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.

Generating delay using timer

Other Parts Discussed in Thread: ENERGIA

Hi,


I'm trying a simple thing to blink LED at 1 second. Instead of using SysCtlDelay(), i'm trying to use the timer interrupt. There is a way to blink LED using PWM also.

I'm running Tiva dev kit at 120MHz. Problem is that, with what value should I load the timer with so that I can call interrupt at every second. Since 16 bit timer would give me only 65536, I cant generate interrupt every second. Is there a way to achieve this without using 32 bit timer?  or I have to use 32 bit timer?


Thanks

  • Hi Spandan,

    You could use the timer without splitting it, hence you would have a 32 bit timer.
    Now if you use the split timers you have one thing extra you didn't have with them put together - a 8 bit prescaler. The effect changes between timer modes but in periodic mode you will basically have a 24 timer. The prescaler will hold the 8 more significant bits.

    But I think there is something else that would maybe be more useful to you. Later check other method (it's different than what you want to do, but it allows to configure delays like Energia/Arduino).
    sites.google.com/.../timer-delay
  • Hi,

    I understand that 120MHz is a big number and even with 24 bit timer (16Mega only) its hard to achieve 1 second delay. So i think either i have to reduce the operating frequency or use the 32 bit timer. I understand that 1 second of delay is pretty big when it comes to microcontroller.
    But yeah, i got the idea.
    Thanks
  • You have so many timers on the device so it should not be a problem.

    If you really, really need to use a 16bit timer you can use a variable for counting. You set the timer for 0,5ms. The handler interrupts and counts++. When the counter reaches 1s/0.5ms = 2000 you toggle the LED and reset the counter.

    There are many ways, just get creative and implement what suits you best