This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR6989: Blinking LED At Defined Duty Cycle Using Timer

Part Number: MSP430FR6989

Hello, I am very new to micro-controllers. I have a question regarding blinking LED's in accordance with a pre-defined duty cycle using a timer. I am able to get the LED to turn on and off at equal intervals, but I'm trying to get the LED to stay on for 25% of the time, and off for the rest. My code is below.

#include "msp430.h"
#include "intrinsics.h"

/* Configuring Clocks
 Sourcing LFXTCLK to ACLK and dividing by 32. Result clock "should" be oscillating at
 1 kHz. */

void configureClocks(void){
  CSCTL0 = CSKEY;               // Clock Control Register Password
  CSCTL2 = SELA__LFXTCLK;         // Source LFXT to ACLK
  CSCTL3 = DIVA__32;             // Dividing by 32
}


int main(void)
{
  configureClocks();
  
  WDTCTL = WDTPW | WDTHOLD;		        // Stop watchdog timer
  PMMCTL0 = PMMPW;			         	// Open PMM Module
  PM5CTL0 &= ~LOCKLPM5;			        // Clear locked IO Pins
  P1DIR |= BIT0;                        // Set P1.0 to output direction 
  //P1OUT &= 0x00;                        // Initialize P1.0
  
  TA0CCTL0 = CCIE;                 // Enabling interrupts from timer A
  TA0CCTL1 = OUTMOD_7;
  TA0CCR0 = 1024-1;
  TA0CCR1 = 256-1;                   // Duty cycle 25%
 
  TA0CTL = TASSEL_1 + ID_1 + MC_1; // Sourcing Timer A with ALCK, dividing by 1
  
  _BIS_SR(LPM0_bits + GIE);    
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
  P1OUT ^= BIT0;
}

  • The remaining step is to "attach" the pin to the timer using P1SELx.

    Reading from SLAS789B, Table 6-17: you should set BIT0 of PSEL0. (You theoretically should also clear BIT0 of PSEL1, though it is probably =0 already.)

    After doing this, your software PWM (in Timer_A()) becomes inoperative (which is OK).

**Attention** This is a public forum