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.

MSP430FR5972: CLOCK_TIMER

Part Number: MSP430FR5972

Hi Experts,

I am using a MSP430FR5972 controller for my project ,I need to invoke  built-in timers so that it could be used to automatically drive each LED connected to  pin as follows

LED

Timer pin

Stimulation Green

TA0.1

Stimulation Yellow

TA0.2

Battery Green

TA1.1

Battery Yellow

TA1.2

 I want  GPIO pins can be set to be driven by the timer peripherals. LED can be set to ON or OFF (active low) in the timer registers, or the timers can be configured to switch the pins periodically without the need for interrupts or delay cycles.

Adding further more I using the clock settings as under in my code:

// Clock System Setup
CSCTL0_H = CSKEY >> 8; 
CSCTL1 = DCOFSEL_4 | DCORSEL; // Set DCO to 16MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO,
// ACLK = VLOCLK
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
CSCTL0_H = 0; // Lock CS registersM

 

Can you please help how to user timer in this mode or provide any example code to solve my above query.

  • Hello Himanshu,

    One option would be to change the function of the pin from TAx.x to GPIO when you want to set the output to low or high, and vice versa when you would like to toggle the pins periodically.

    For example, this code would set the pin high:

    P1SEL0 &= ~BIT6       \\Set both selection pins to zero for GPIO out
    P1SEL1 &= ~BIT6
    P1OUT |= BIT6          \\Set pin high

    And this code would set the pin to the timer function:

    P1SEL0 |= BIT6       \\Set selection pins to 11 for TA0.1
    P1SEL1 |= BIT6

    In order to set the timer so that the pins toggle high or low without an ISR or delay cycles you need to tie the LED directly to the capture compare register (CCRx). This is done by selecting the TAx.x function using the function select pins and then choose the output mode for the pin that best suits your needs.

    This example code shows how to set up the timer to output a PWM of different periods and duty cycles without any interrupts. In this example code, the CCR0 determines the period of the PWM signal, and the relation between CCR1/CCR2 and CCR0 determines the duty cycle.

     Alternatively, you could only use CCR0 and use TA0CCTL0 = OUTMOD_4 to have the pin toggle every time the timer counts up to the CCR0 value.

    For example, the following code will toggle the output on pin 1.5 every 100 clock cycles:

    TA0CCR0 = 100-1; \\timer will roll over every 100 clock cycles
    TA0CCTL0 = OUTMOD_4; \\Toggle
    TA0CTL = TASSEL_ACLK | MC__up | TACLR; \\ ACLK, up mode, clear TAR

    Please let me know if this does not answer your question or you have more questions.

    Regards,

    Matthew

  • Thank You Matthew for your reply. My requirement is set the pin to the timer function.I am able to understand with example how to workout this but still I am failed to toggle LED.

    LED is connected to PIN P1.2/TA1.1/TA0CLK/COUT/A2/C2 and setting which I am using in my code is :



    // Clock System Setup
    CSCTL0_H = CSKEY >> 8; // Unlock CS registers
    CSCTL1 = DCOFSEL_4 | DCORSEL; // Set DCO to 16MHz
    CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO,
    // ACLK = VLOCLK
    CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers
    CSCTL0_H = 0; // Lock CS registersM

    P1SEL0 |= BIT2; //Set selection pins to 11 for TA0.1
    P1SEL1 |= BIT2;
    TA1CCR0 = 1000-1; //timer will roll over every 100 clock cycles
    TA1CCTL1 = OUTMOD_4; //Toggle
    TA1CCR1 = 750; // CCR1 PWM duty cycle
    TA1CTL = TASSEL_1 | MC_1 | TACLR; // ACLK, up mode, clear TAR

    Please tell whether these above settings are right or wrong.
    Thanks in advance.
  • Hello Himanshu,

    One issue you have in your code is the selection bits for P1.2:

    You have the selection bits set to "11", which is correct for pin P1.6 as the TA0.1 function is the tertiary function for pin P1.6; however, for pin 1.2, TA1.1 is actually the primary function, not the tertiary, so you want to set the function bits to "01"

    Eg:

    P1SEL0 |= BIT2;
    P1SEL1 &= ~BIT2;

    You can get information about the pin functions in the MSP430fr5972 datasheet. The function selection bits for pin P1.2 are found on page 80.

    Additionally, you will want to set your P1.2 pin to an output via the P1DIR register.

    Finally, if you are looking for a duty cycle of 75%, you will want to set your output mode to reset/set as the example code shows. If you use toggle, it will not output the desired duty cycle. 

    Regards,

    Matthew

  • Hi Matthew,

    I totally agree with you Answer.Here is the code I am using Now.Still I am failed to toggle the LED.

    P1SEL0  |= BIT2;

    P1SEL1 &= ~BIT2;

    P1DIR |=BIT2;

    TA1CCR0 = 100-1; //timer will roll over every 100 clock cycles


    TA1CCTL1 = OUTMOD_4; //Toggle
    TA1CTL = TASSEL_1 | MC_1 | TACLR; // ACLK, up mode, clear TAR

  • Hello Himanshu,

    Are you disabling the GPIO high-impedance mode?

    Regards,
    Matthew
  • Hello Himanshu,

    Do you have any updates on this issue?

    Regards,
    Matthew

**Attention** This is a public forum