I’m trying to achieve a sample rate of 100Hz on a sensor task. The BLE stack appears to be delaying that timer, even though they are pinned to different cores.
If I disable BLE advertising, that timer fires pretty close to 10ms (nanosecond variations)
With BLE advertising on, the timer fires +/-1.5ms, which is a significant variation.
- I set the BLE stack to core0
- Pinned the SD logging task to core0
- Pinned the sensor task to core1
- The sensor task uses a periodic timer set to 10ms
- I’ve implemented appropriate scheduling:
- The 100Hz timer ISR gives a semaphore to the sensor task loop.
- To simplify things, I disabled the actual sensor code, so all the task does is read esp_timer_get_time() and check the difference from the last time.
- The sensor task pushes to the back of the queue
- The logger task drains the queue to a SD card.
- That’s how I generated the plots, but for sanity, I also did a simple “last timestamp” test and disabled the SD logging task (writing to the SD card is not the source of this delay).
- The example BLE project puts the BLE 2 under the max.
- If my timer/sensor task is above that (either by lowering the BLE priority, or raising my task priority), I don’t get advertisements on the other end.
- I've tried changing the FreeRTOS tick rate. See this post: viewtopic.php?f=13&t=1341&p=64625#p64594
- I've tried adjusting adv_int_min and adv_int_max, which partially fixes the timing on the other core, but then I lose advertisements on the other end.
The Y axis is the time difference in nanoseconds from the previous timer trigger (as read from esp_timer_get_time()). The X axis is each sample.
Here's the timing with BLE advertisements on. The timer gets delayed, and then fires early next time. That appears to explain the symmetric pattern (I just cant explain that delay beyond "something in the BLE stack"): And if I simply turn off BLE advertisements, I get this (which is what I want): My question is: can I achieve a 10ms timer/sample rate on core1 with BLE on core0 (or BLE on in general)?