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.

How to Implement a software timer on msp430 ?

Other Parts Discussed in Thread: MSP430F5529

Hello,

I would like to know how to implement and use a Software timer on msp430.

I've been using msp430f5529. 

Thank You

  • Maisie,

    The MSP430F5529 has quite a few HW timers you can use. For code examples of this please see MSPWare. MSPWare can be accessed via stand alone download, through the TI Resource Explorer in CCS, or the cloud TI Resource Explorer located at https://dev.ti.com
  • Hi Maisie!

    You may want to look at the code examples for the MSP430F5529. They include various examples for using the internal timer(s) of the microcontroller:

    • MSP430F55xx_ta0_02.c              Timer0_A5, Toggle P1.0, CCR0 Up Mode ISR, DCO SMCLK
    • MSP430F55xx_ta0_04.c              Timer0_A5, Toggle P1.0, Overflow ISR, 32kHz ACLK
    • MSP430F55xx_ta0_16.c              Timer0_A5, PWM TA1.1-2, Up Mode, DCO SMCLK
    • MSP430F55xx_ta0_17.c              Timer0_A5, PWM TA1.1-2, Up Mode, 32kHz ACLK
    • MSP430F55xx_ta1_01.c              Timer1_A3, Toggle P1.0, CCR0 Cont. Mode ISR, DCO SMCLK
    • MSP430F55xx_ta1_02.c              Timer1_A3, Toggle P1.0, CCR0 Up Mode ISR, DCO SMCLK
    • MSP430F55xx_ta1_03.c              Timer1_A3, Toggle P1.0, Overflow ISR, DCO SMCLK
    • MSP430F55xx_ta1_04.c              Timer1_A3, Toggle P1.0, Overflow ISR, 32kHz ACLK
    • MSP430F55xx_ta1_05.c              Timer1_A3, Toggle P1.0, CCR0 Up Mode ISR, 32kHz ACLK
    • MSP430F55xx_ta1_11.c              Timer1_A3, Toggle P1.7/TA1.0, Up Mode, 32kHz ACLK
    • MSP430F55xx_ta1_13.c              Timer1_A3, Toggle P1.7/TA1.0, Up/Down Mode, DCO SMCLK
    • MSP430F55xx_ta1_14.c              Timer1_A3, Toggle P1.7/TA1.0, Up/Down Mode, 32kHz ACLK
    • MSP430F55xx_ta1_16.c              Timer1_A3, PWM TA1.1-2, Up Mode, DCO SMCLK
    • MSP430F55xx_ta1_17.c              Timer1_A3, PWM TA1.1-2, Up Mode, 32kHz ACLK
    • MSP430F55xx_ta1_19.c              Timer1_A3, PWM TA1.1-2, Up/Down Mode, DCO SMCLK
    • MSP430F55xx_ta1_20.c              Timer1_A3, PWM TA1.1-2, Up/Down Mode, 32kHz ACLK
    • MSP430F55xx_ta2_01.c              Timer2_A3, Toggle P1.0, CCR0 Cont. Mode ISR, DCO SMCLK
    • MSP430F55xx_ta2_03.c              Timer2_A3, Toggle P1.0, Overflow ISR, DCO SMCLK
    • MSP430F55xx_ta2_08.c              Timer2_A3, Toggle P1.0;P2.3-5, Cont. Mode ISR, 32kHz ACLK
    • MSP430F55xx_ta2_14.c              Timer2_A3, Toggle P2.3/TA2.0, Up/Down Mode, 32kHz ACLK
    • MSP430F55xx_ta2_19.c              Timer2_A3, PWM TA1.1-2, Up/Down Mode, DCO SMCLK
    • MSP430F55xx_tb_01.c               Timer_B, Toggle P1.0, CCR0 Cont. Mode ISR, DCO SMCLK
    • MSP430F55xx_tb_02.c               Timer_B, Toggle P1.0, CCR0 Up Mode ISR, DCO SMCLK
    • MSP430F55xx_tb_03.c               Timer_B, Toggle P1.0, Overflow ISR, DCO SMCLK
    • MSP430F55xx_tb_04.c               Timer_B, Toggle P1.0, Overflow ISR, 32kHz ACLK
    • MSP430F55xx_tb_05.c               Timer_B, Toggle P1.0, CCR0 Up Mode ISR, 32kHz ACLK
    • MSP430F55xx_tb_10.c               Timer_B, PWM TB1-6, Up Mode, DCO SMCLK

    The configuration and best mode of operation depends on your specific application. So what do you plan to do?

    Dennis

  • You cannot implement software timer without help from hardware timer. So you shall get familiar with hardware timer first, build code that calls timer interrupt service routine (ISR) 100 or 1000 times per second. Then next step would be implementing software timer(s) code in the hardware timer ISR. Example of supersimple implementation of two software period timers:

    volatile counter1 = 0;
    volatile counter2 = 0;
    
    hw_timer_isr() { // running 100 times/sec
    
      if (++counter1 >= 10) {
        do_something_each_100msec();
        counter1 = 0;
      }
    
      if (++counter2 >= 100) {
        do_something_each_1sec();
        counter2 = 0;
      }
    }
    

  • Hello Ilmars ,

    Thanks a lot ! that was exactly what I wanted to know.

    Maisie

**Attention** This is a public forum