Author Topic: Timers  (Read 3469 times)

Offline paulk

  • Newbie
  • *
  • Posts: 45
    • View Profile
Timers
« on: November 06, 2009, 10:53:33 PM »
I'm trying to wrap my head around all this wonderful stuff, so I apologize if my question is dumb or easily answered.  I've been reading the uTasker documents including the timer document as it would relate to my project.

On top of adding web server, file system, etc connectivity, my project requires a highly accurate task to run at exact intervals.  In my previous implementation (without on operating system), I've used high priority interrupts.  Basically, I need a task to happen exacly 8192 times in 1 hour (3600s / 8192 = 439.453125 ms)....with as much accuracy as possible.  This task should fire and preempt anything else happening if possible.

Now, I know the LM6965 has 32-bit hardware timers, so presuming they count at 50Mhz (the LM6965 datasheet doesn't mention anything about pre-scalers for 32-bit timers??!?), it would yield a 0.02us period resolution.  If I'm doing my math right (and my assumptions are correct), this means that using a 32-bit timer, it could count to 85.899 seconds....so my requirement of 439ms would give me great resolution on top of adequate timer size.

Reading through the uTasker header files however appears that it only uses 16-bit timers.

Basically, I'm wondering if someone could kick me in the right direction:
a) Can uTasker use a dedicated 32-bit timer for high priority, high-resolution tasks?
b) Which documents should I digest to move in this direction?
c) Which header files and which defines are required for this to happen?


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3068
    • View Profile
    • uTasker
Re: Timers
« Reply #1 on: November 07, 2009, 04:10:45 AM »
Hi Paul

I think that the uTasker periodic and single-shot timer interrupts always use 32 bit timer mode (in 16 bit mode an 8 bit pre-scaler could be set according to the Luminary docs).

The only time that it configures the timer to run in 16 bit mode is when a square wave output (50/50 duty cycle or other [PWM]) is generated since the Luminary parts can not generate square wave outputs in 32 bit mode: see http://www.luminarymicro.com/component/option,com_joomlaboard/Itemid,/func,view/catid,5/id,6617/#6617
This limits the lowest frequency that can be generated as a square wave output to about 382Hz from a 50MHz clock (without toggling the port output from an interrupt) but a repetitive interrupt should be possible with much longer periods.

The first question is whether you need a task to handle the periodic events. If the handling is fast it is simplest to put it into the interrupt handler itself.
Due to the interrupt prioritorisation it is also possible to do more work within an interrupt routine as long as it doesn't have too high a priority and so block other interrupts which need to be handled quickly.
Typically a task is woken from an interrupt routine by posting an event to it, but the reaction time to the event depends on what other tasks are doing at the time (cooperative operation). If you can't accept task jitter due to this, the interrupt handling direct is probably the best solution. Sometimes it is possible to perform critical things in the interrupt and then let a task handle less critical 'clean-up' work.

There is nothing special to set up to do this - just use a periodic timer interrupt as in the example in ADC_Timers.h, with demo setting TEST_TIMER and TEST_PERIODIC_TIMER (with SUPPORT_TIMER enabled in app_hw_lm3sxxxx.h to include the timer interrupt driver).

Regards

Mark