0

I'm using an MSP430F5529 board and CCS to program it for this problem. My code is as follows:

#include <msp430.h>


int main(void)

{
    WDTCTL = WDTPW | WDTHOLD;       //stop watchdog timer

    P1SEL |= BIT0;                  //configure P1.0 as TA0.1
    P1DIR |= BIT0;                  //P1.0 is output (compare mode)
    P4SEL |= BIT7;                  //configure P4.7 as TA0.2
    P4DIR |= BIT7;                  //P4.7 is output (compare mode)


    TA0CCR0 = 999;                  //CCR0 is used to generate the desired period
    TA0CCR1 = 749;                  //CCR1 is used to generate 0.25 duty cycle
    TA0CCR2 = 249;                  //CCR2 is used to generate 0.75 duty cycle


    TA0CCTL1 = OUTMOD_7;            //PWM 1
    TA0CCTL2 = OUTMOD_7;            //PWM 2

    TA0CTL = MC_1 + TASSEL_2 + TACLR|ID_3;
    _BIS_SR(LPM0_bits+GIE);



    while(TA0CCTL2 == 1)
    {
       P4OUT ^= BIT7;
       if(TA0CCTL1 == 1)
           {
              P1OUT ^= BIT0;
           }
    }
}

This code only results in the LED on pin 1.0 to illuminate, it does not blink and the LED on pin 4.7 doesn't even turn on.

Dan
  • 10,303
  • 5
  • 36
  • 53
  • Is this the MSP430F5529 Launchpad board or a different board? My 5529 Launchpad has the LEDs on P1.2 (TA0.1) and P1.3 (TA0.2), not P1.0 and P4.7. Also what is the input clock frequency to TA0? I haven't checked your settings for TA0CTL but if you've done it right, main() doesn't have to do anything except a while(1){} or go into a low power mode. The PWM is handled by CCR1 and CCR2 and the period is set by CCR0. – Dan Nov 07 '20 at 01:36
  • Yes this is the dev board from the launchpad kit. According to the question it requests the frequency to be 1KHz – giadidonato Nov 07 '20 at 16:39
  • So this sounds like a school assignment. Do you agree that the LEDs are on P1.2 and P1.3? Set up CCR1 and CCR2 to be the correct duty cycle, set CCR0 so that it will reset 1000 times / sec (depends on input clock frequency), and you're done. Reset/Set mode is the right mode, UP mode is the right mode for the timer. – Dan Nov 08 '20 at 00:48
  • Looks like the debug MCU LEDs are connected to P1.2 and P1.3, but the main MCU LEDs are P1.0 and P4.7. Do not configure P1SEL and P4SEL, those pins (1.0 and 4.7) aren't TA0 outputs. Just configure the pins as GPIO output. Also no need to program OUTMOD field in TA0CCTL1 and TA0CCTL2. In main(), after you've configured the pins, do a while(1) a) turn LEDs on (P1OUT, P4OUT) and wait for TA0CCTL1[IFG] and TA0CCTL2 to be set; when so, turn off LED; wait for TA0CTL[IFG] to be set (CCR0), turn LEDS on again – Dan Nov 08 '20 at 01:03
  • The assignment asks us to use the onboard LEDs 1.0 and 4.7 though so I can't agree that the LEDs are 1.2 and 1.3 for this application. I do have a PCB with LEDs at those pins but they are not to be used for this – giadidonato Nov 08 '20 at 16:28

0 Answers0