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.

CCS/MSP430FR5857: Timer

Part Number: MSP430FR5857

Tool/software: Code Composer Studio

My design needs a pin to be low for 5 minutes and then on for 5 secs and want to repeat endlessly. I thought of using the timer for this. 

#include <msp430.h>
unsigned int i=1;
int main(void)
    WDTCTL = WDTPW | WDTHOLD;               // Stop WDT

    // Configure GPIO
    P1DIR |= BIT2;

    // Disable the GPIO power-on default high-impedance mode to activate
    // previously configured port settings
    PM5CTL0 &= ~LOCKLPM5;

    TA0CCTL0 = CCIE;                        // TACCR0 interrupt enabled
    TA0CCR0 = 50000;
    TA0CTL = TASSEL__SMCLK | MC__CONTINOUS; // SMCLK, continuous mode

    __bis_SR_register(GIE);     // Enter LPM0 w/ interrupt
    __no_operation();                       // For debugger

void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer0_A0_ISR (void)
        P1OUT |= BIT2;
        TA0CCR0 += 50;
        P1OUT &=0xFFFB;
        TA0CCR0 +=65535;

This code works but I need a higher off time as I explained above. How can I do that?

Can I use something else other than timer to do the above operation?

Thank you in advance.


  • You can use DIVS to make SMCLK up to 32 times slower than the clock source. (The default already divides the 8 MHz source by 8.)
    You can use ID and IDEX to make the timer's input clock 64 times slower.

    With the default DCOFSEL of about 8 MHz, this would result in a timer tick of 4096 Hz, i.e., the maximum delay would be about 16 s.
    If you reduce DCOFSEL, you get a timer tick of 512 Hz, i.e., the maximum delay would be about 128 s.
    If you have a 32768 Hz crystal, you can use ACLK instead; the timer tick would be 16 Hz, and the maximum delay, about 4096 s (68 minutes).

    Alternatively, don't think of it as a delay of 5 minutes; split it into 20 pieces of 15 s each, and switch the output only after the last one.
  • Thank you Clemens. I am using 16 MHz because I need high speed operation in some parts of the circuit. About the last idea can you just guide me on how to do that.? I mean in terms of code. I am a beginner to ccs and its a little confusing to do it.
  • At the moment, your interrupt handler has two states.

    The name "i" is meaningless; rename it to "state". Instead of looking at its lowest bit, reset it when it has reached the last state.

    Then do whatever is necessary in each state:

    switch (state) {
    case 0:
        TA0CCR0 += 15000;
        P1OUT |= BIT2;
    case 1:
        TA0CCR0 += 50000;
        P1OUT &= ~BIT2;
    case 2:
    case 3:
    case 20:
        TA0CCR0 += 50000;
    if (state == 21)
        state = 0;
  • Thank you Clemens. I found out another solution for this problem. I used the VLOCLK as my timers clock and then applied the prescalars. Using this we can get a maximum time count of almost 270 minutes.

**Attention** This is a public forum