Hi FreeRTOS community. I am new to FreeRTOS and I am using Toradex Colibri iMX7.In my SOM, I am using FreeRTOS for Cortex-M4 micro-controller. I need to send data acquired from ADC through SPI for the remote A7 processor. For this I need to acquire a data and send that data every 50 micro-second. If the process is over before 50micro-sec, then the function should wait for the remaining time until 50micro-sec. Is it possible to increase the configTICK_RATE_HZ to 1MHz so that I can get one tick at each micro-second. Is it possible or is there anyother way of doing this?.
Note: I am going to use only this task and no other tasks are created.So is it ok to increase the configTICK_RATE_HZ to 1MHz.
Thanks for your time in advance. Suggestions are welcome.
1 MHz, or even 20 kHz (50 usec) is in my opinion too fast to want to run the system tick. What I would do for this problem is first see if I could set up a timer to automatically trigger the ADC conversion, and if not have a timer generate a very high priority interrupt and have the ISR trigger the ADC. Then have the conversion complete interrupt handler get the data and start the SPI operation.
Note that ADC conversion and SPI sending should be fixed time operations, so there should be no question of ‘if’ the process finishes before the 50 usec period, either it will complete, so you can work off the timer, or it won’t (at which point you will need to slow down the sample rate).
If this really is all that the processor will be doing. then it is also possible to write the program without interrupts but polling loops, at which point the program is simpler, but the processor is really dedicated to that function.
Hi @richard-damon,
Thanks for your reply.
I checked with the ADC conversion and sending data to the remote processor takes time from 63 to 67 microseconds per iteration. I want the overall time to be 100 micro-seconds.So in this case I want to make the system to wait for 33 to 37 micro-seconds which is possible through vTaskDelay() if the configTICK_RATE_HZ is set to 1000000. I searched a lot regarding the increasing of configTICK_RATE_HZ over 1000, all of them suggested not to do so becauseit may cause undefined behaviour with system task scheduling. But in my case, I am going to use only one task. So in my case is it ok to increase the configTICK_RATE_HZ to 1000000. Or can you suggest me any methods to make the task wait for 33 to 37 microseconds?
I have a GPT in my SOM which also has ms precision. Any links on how to use a hardware timer will be helpful as completely new to freeRTOS.
The issue with high tick rates isn’t that FreeRTOS itself has problems, but that running the tick at a high frequency means the tick interrupt and the scheduler get run often, and use up significant CPU resources, and at some point, they will use up all the CPU time so nothing is left to run your program. What does have a problem are some of the ‘convenience’ macros that convert time periods to ticks, those don’t work right if your tick period isn’t an integral number of milliseconds.
Another point, you DON’T need a wait for 33 micro-seconds, but a wait to the next 100 micro-second period, so you just need a 10 kHz rate timer. In FreeRTOS, delays are always relative to the timer, so a delay of 1 tick means delay until the next tick interrupt, which might be almost no time.
10 kHz is a bit fast in my opinion for the FreeRTOS tick but maybe doable if the processor is running reasonably fast. My thought of using a simple hardware timer to trigger the ADC converter is that this would make the sampling period very accurate, and in most systems using a high-frequency sampling, keeping the period accurate is important for accurate data. Working off the tick interrupt and such is apt to introduce a bit of variation into the timing.