Running a OS new Task at specific frequency

Discussion to talk about software related topics only.
Post Reply
nicobari
Posts: 110
Joined: Mon Jan 30, 2012 12:15 pm

Running a OS new Task at specific frequency

Post by nicobari »

Hi,
I created a new task using OSTaskCreate and everything works fine. I would however like to limit the frequency at which the new task runs. I want to limit it to 50 Hz, I was using PIT1 as free running timer configured for 50 Hz and I was checking the interrupt flag to see when the timer count is complete. Is there any other way I can do it more efficiently?

Thank you,
TM
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Running a OS new Task at specific frequency

Post by rnixon »

A Real Time OS is different than a time slice OS. The highest priority task ready to run will always run. One possibility would be that you could make it a very high priority, add a blocking function like a semaphore, than post the semaphore at your frequency. However, this seems like an architecture issue that should be addressed in a different way.
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Running a OS new Task at specific frequency

Post by Ridgeglider »

If the task really needs to run at 50Hz, use a timer (PIT, DMA, or on some platforms, the GPT timer) to generate an interrupt that calls an ISR every 20mSec that, in turn (as rnixon suggests) posts a semaphore to a hi priority task (low task prio number). Depending on what you want to do, an IRQ may not be required. For example if all you want to do is to set, clear, or toggle one of the timer-related pin levels, just init the timer once in output compare mode and let the hardware do its job. Of course, your task may be more complicated, or you may not want the action (eg your task) to occur at 50Hz rate....
nicobari
Posts: 110
Joined: Mon Jan 30, 2012 12:15 pm

Re: Running a OS new Task at specific frequency

Post by nicobari »

I had it setup as a separate ISR but I have several interrupts running and they are interfering with each other leading to noisy data. This made me run the most important task as a separate OS task. When I checked with oscilloscope the new task frequency was approximately 1.4 KHz. Everything works fine but I want to reduce the frequency to do some test. Anyways thanks for the suggestions and I don't see any harm in trying it out.

Thanks,
TM
ecasey
Posts: 164
Joined: Sat Mar 26, 2011 9:34 pm

Re: Running a OS new Task at specific frequency

Post by ecasey »

You could just put an OSTimeDly(x) in the task loop to slow it down for testing. It would not be deterministic, but for 50Hz from 1.4 Khz, it would be pretty good. You could also use the HiResTimer functionality to get very close to 50 Hz.
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: Running a OS new Task at specific frequency

Post by pbreed »

I set up a PIT timer and in that ISR post to a semaphore....
I have some code that does this cleanly... what platform are you running on?

Paul
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: Running a OS new Task at specific frequency

Post by dciliske »

Looking at his previous posts, it appears he's using a MOD54415.
Dan Ciliske
Project Engineer
Netburner, Inc
Post Reply