Hi
I would like to sample two IMUs with 6 axes each at 200Hz and send them to the PC APP via USB.
But I don't know yet which processor is best to use.
With the PIC32MZ2048 and STM32F469, I can use interrupt from the timer to sample data.
With the ESP32 no possibility to sample something in the timer loop just errors.
Can the timer interrupt in the ESP32 be improved?
What would work best of these 3 processors?
Or a completely different type?
Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
-
- Valued Contributor
- Posts: 1065
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 201 times
- Been thanked: 225 times
-
- Valued Contributor
- Posts: 1628
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
Hi Stefan,
On the esp32 - could create a new task (or 2) and just sample in that (them) with a loop and delay?
Martin
On the esp32 - could create a new task (or 2) and just sample in that (them) with a loop and delay?
Martin
-
- Valued Contributor
- Posts: 1065
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 201 times
- Been thanked: 225 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
Hi Martin
Would you make a second task for sampling or sending?
In the PIC32 I have sampling in the interrupt and sending in the main.
send if the buffer is full(send ready=1) fill the buffer and make a copy and set (send ready=1)
Would you make a second task for sampling or sending?
In the PIC32 I have sampling in the interrupt and sending in the main.
send if the buffer is full(send ready=1) fill the buffer and make a copy and set (send ready=1)
-
- Valued Contributor
- Posts: 1628
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
You could both sample and send in the task - but there is a proviso to that. If you have multiple tasks sending the data can get 'mixed'- so you'll need some sort of semaphore (or lock). Alternatively the tasks could feed the data into a queue and main (or another 'send' task) output the data.
Again - needs a little bit of care if multiple tasks are accessing the same data to avoid corruption.
Martin
Again - needs a little bit of care if multiple tasks are accessing the same data to avoid corruption.
Martin
-
- Valued Contributor
- Posts: 1065
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 201 times
- Been thanked: 225 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
Hi Martin
With the PIC
I copied the buffer to avoid accessing the same memory at the same time.
This is very fast with the PIC and probably also with the ESP So at the moment:
With ESP i only set recsample to 1 in the interrupt. Nothing additional. and in the main i sample the IMU and send just the array with the 12 axis. This works nice with 20 Hz If I have understood you correctly then I can also collect about 120 values and then in a second task
I send the copie from the buffer.
I simply have to send faster than saving data in the buffer.
This i think i can controll with my osciloscope
With the PIC
I copied the buffer to avoid accessing the same memory at the same time.
This is very fast with the PIC and probably also with the ESP So at the moment:
With ESP i only set recsample to 1 in the interrupt. Nothing additional. and in the main i sample the IMU and send just the array with the 12 axis. This works nice with 20 Hz If I have understood you correctly then I can also collect about 120 values and then in a second task
I send the copie from the buffer.
I simply have to send faster than saving data in the buffer.
This i think i can controll with my osciloscope
-
- Valued Contributor
- Posts: 1628
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
A small example program:
It's rather contrived - and sends strings of data rather than 'real' data - and outputs the values received to UART - rather than processing them in any way.
I use two queues - and two tasks (Sensor1 and Sensor2) that push data into the queues (in this case the 'data' is just 8 characters "A..H" and for sensor2 "a..h" - that is rotated on each 'send'. The queue - here is defined using xQueueCreate to take 8 bytes of data per item.
There is a macro RcvQueue that outputs all the data from a queue to UART before returning - and here Sensor1 sends 1 'reading' per second and sensor2 one every 100ms.
I am just outputting the data from main here (by calling RcvQueue) - then waiting 5s and repeating.
Note - the queues are created in main and passed to the Sensors as parameters. This could be a separate task if required - but I don't need main to do anything else.
Every 5s - queue1 holds 5 data items and queue2 up to 20 - as set here, Sensor2 sends 10 items per second - but the queue is full at 20 items. Here I drop the additional items, but Sensor2 could wait either for a set period or until there is room in the queue as required.
Note that the data is copied to the queue - the sensor tasks can modify the data without affecting the sent data. Also all the tasks (including main) must 'yield' to allow the multi-tasking of RTOS to occur (there are always several tasks running - so every program must do this - otherwise WDT issues will occur)
Although I use two queues - using one also works - queues are thread safe. Using one queue - means the queue holds a 'mix' of the data from Sensor1 and Sensor2 (maybe the first byte could indicate which?)
In the real world - a check should be made that both the queues and the tasks can be created - and failure handled gracefully.
Martin
It's rather contrived - and sends strings of data rather than 'real' data - and outputs the values received to UART - rather than processing them in any way.
I use two queues - and two tasks (Sensor1 and Sensor2) that push data into the queues (in this case the 'data' is just 8 characters "A..H" and for sensor2 "a..h" - that is rotated on each 'send'. The queue - here is defined using xQueueCreate to take 8 bytes of data per item.
There is a macro RcvQueue that outputs all the data from a queue to UART before returning - and here Sensor1 sends 1 'reading' per second and sensor2 one every 100ms.
I am just outputting the data from main here (by calling RcvQueue) - then waiting 5s and repeating.
Note - the queues are created in main and passed to the Sensors as parameters. This could be a separate task if required - but I don't need main to do anything else.
Every 5s - queue1 holds 5 data items and queue2 up to 20 - as set here, Sensor2 sends 10 items per second - but the queue is full at 20 items. Here I drop the additional items, but Sensor2 could wait either for a set period or until there is room in the queue as required.
Note that the data is copied to the queue - the sensor tasks can modify the data without affecting the sent data. Also all the tasks (including main) must 'yield' to allow the multi-tasking of RTOS to occur (there are always several tasks running - so every program must do this - otherwise WDT issues will occur)
Although I use two queues - using one also works - queues are thread safe. Using one queue - means the queue holds a 'mix' of the data from Sensor1 and Sensor2 (maybe the first byte could indicate which?)
In the real world - a check should be made that both the queues and the tasks can be created - and failure handled gracefully.
Martin
- Attachments
-
- Queue.fcfx
- (20.32 KiB) Downloaded 147 times
-
- Valued Contributor
- Posts: 1628
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 142 times
- Been thanked: 761 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
Forgot to mention - if you want to read at 200Hz - set the delay in the sensor macro(s) to 5ms - and it will run okay - though you'll need to do something other with the data rather than outputting to UART every 5s...
-
- Valued Contributor
- Posts: 1065
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 201 times
- Been thanked: 225 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
Hi Martin
Thank you very much. The Queve works well.
Soon I connect the real sensor und trie it again.
Later I then try to read both sensors in one macro
and store them in one integer array and Send this array with one Queve.
Thank you very much. The Queve works well.
Soon I connect the real sensor und trie it again.
Later I then try to read both sensors in one macro
and store them in one integer array and Send this array with one Queve.
-
- Valued Contributor
- Posts: 1065
- Joined: Wed Dec 02, 2020 10:53 am
- Has thanked: 201 times
- Been thanked: 225 times
Re: Sampling 2pcs IMU 6axis @ 200Hz with PIC32,STM32,or ESP32?
Hi Martin, Hi Ben
At the moment it works with the ESP32, I can read and save both sensors. However, there is a problem with the SD card when saving the data. I use a string in excel format which also works very well for saving. It only needs 128uSec for the big string write to disk. But at regular intervals the saving takes 1.4mSec. Then I can't sample. Can I move the appendStringToFile into a separate task? or in the second core?
yellow=I2C read the IMU; green= write to disk result .csv file
At the moment it works with the ESP32, I can read and save both sensors. However, there is a problem with the SD card when saving the data. I use a string in excel format which also works very well for saving. It only needs 128uSec for the big string write to disk. But at regular intervals the saving takes 1.4mSec. Then I can't sample. Can I move the appendStringToFile into a separate task? or in the second core?
yellow=I2C read the IMU; green= write to disk result .csv file