FreeRTos on ESP32 to speed up sending ADC Data.

Status
Not open for further replies.

Joe123456

Newbie
Joined
Sep 13, 2021
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
19
Hello everyone,
Thank you in advance for your time!

I am using MCP3008 (10 bit ADC)+MPU6050 connected to an ESP32 to send some sensors data over Bluetooth. I used FreeRtos (to which I am really new) to speed up the process and collect more data over time.
I attached parts of my code. (Task1 and Task 2 have the same content so I didn't put it.)
  • For some reason the amount of data sent by each task is not always the same over a defined time. Some times the difference is huge. For example for Task1 I get 200 data points/sec for each ADC channel and in task2 700 for each channel.
  • I tried different task priorities / changed the stack size but it got worse
  • Sometimes two tasks output overlap
My goal is to get the maximum amount and same number of data points over time.
Any help or Info would be appreciated.

Thanks a lot!






 

Without seeing the full code, my guess is that your tasks are interrupting each other at random times - I can't see the way you have set up the pre-emption but I think you will find that your task3 is being interrupted at various times as the freeRTOS tried to give some CPU time to task1 and task2.
I suggest that you read up on semaphores and set them up so that your task that reads from the ADC is allowed to read whatever your required number of samples is, it then triggers the semaphore that lets your display task access the data and send that number of samples over bluetooth. It can then go back to wait for the next semaphore.
You probably also want to investigate a double-buffer scheme so that one task can fill one buffer while the other tasks send the data - when the first buffer has been filled it triggers the semaphore and witches to the other buffer. Of course this assumes that you can send data faster than the ADC can fill a buffer.
Susan
 

You need to be aware that there are blocking functions involved. The println() for example, since there are a different number of calls in each task, depending on the baud rate, the smaller it is and the larger the number of characters, the smaller the amount of data sent by the Serial port from each task with the same priority level. Another strongly blocking function is the ADC, which even without knowing the library you are using, looks like a callback for a sample-hold/conversion in a single instance. In short, consider a timed call, or the use of semaphores as Aussie Susan mentioned.
 

Hi,

I have no experience with RTOS on ESP32. I guess it´s a valid way to go.

But with ESP32 I successfully used interrupts via Arduino IDE. It worked great.
It helped to avoid blocking functions, thus it speeded up overall timing.

Klaus
 

IIRC FreeRTOS is the basis for both the 'Arduino' and 'ESP_IDF' frameworks anyway for ESP32s.
Susan
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…