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.

newbie question on timers

Hi

I have setup timerA using DSO/8 to 125khz and enabled interrupts...

I want to toggle 3 different LEDs at different time intervals...

Do I use one ISR with a CASE selection for each led or is there a way to use 3 different ISRs one for each led?

what is the proper programming method?

actually what I am interested in is how to use one timer for various timing functions..

all tutorials that I can find in literature and web only cover one led

thnx

Gjango

  • Hi, 

    I'm a noob in MSP430 too ;)

    I would choose to do 3 leds with a single timer interruption and various cases (periods). The reason I think is to save resources (number of interrupt sources, max. code reusing and minimizing code size...) but this is only my opinion.

    Good luck!

  • I agree with Kazola and would like to add the possibility of not using a state machine and still run as many timers as you want with a single interrupt. You could make for instance a 1ms interrupt and run 3 registers that decrement from an initial value. When a timer reaches zero, the micro toggles the LED and reload the timer. Even the periods for a given LED could vary according with what you load the timer (timer on could be different than timer off for example).

  • Thank you for the replies :)

    @Lenio Cacula: when you say register or timer you mean a variable "i" etc  like the one we use to make a for loop?

  • You can also take a look at the capture and compare capability of the msp430 timers. Even small devices as the value line ones have three of them you could use for your applicaton. But only TACCR0 has a seperate interrupt vector - TACCR1 and TACCR2 share TIMER A interrupt and the interrupt source must be tested in the ISR. 

    For blinking just add your desired delay value to the TACCRx register and wait for the next interrupt (but: use variables as unsigned integers!).

    Why bother with capture and compare? You get more accurate timings (smaller ISR, comparison is done by hardware) and you could even use timer outputs to drive the led directly from hardware which gives most accurate timings. 

  • Yes, I mean regular registers that you decrement from a given value.

**Attention** This is a public forum