TeensyDigital
Well-known member
I've got a significant code base and program that runs on an ESP32 that I am porting to Teensy 4.1. On the ESP32, I am taking advantage of the two cores, running a bunch of sensor logging on one core and logging to the SD on the other core in the same program. The sensors are two accelerometers and a barometer all on I2C running at 500hz (samples per second). One the other core, I am logging to the SD card at varying speeds from 20hz (safely with open/close) to 150hz (keeping files open).
I have been really impressed with the T4.1. In a comparison of instructions-per-second the T4.1 is 5000x faster, so it seems like I've got infinite CPU cycles, but when it comes to splitting these two process into two threads, I'm running into "single-threading" conflicts. I've created a thread for the I2C sampling that runs at 500hz without issue. I've also created a thread (or keep it in the main loop) that writes to the SD card at 100hz just fine. But, when I run them together, my sample rate on the sensors drops down to 40hz and my SD logging drops way down. I have stacked both loops with a lot of thread.yield() statements, but I suspect the SD card open/close functions are locking the CPU and starving the sampling thread.The two threads do share global variables, but the SD thread only reads, while the sensor side updates the variables.
Any suggestions on how to get these two I/O intense process to behave more like the dual-cores on the ESP32 would be appreciated.
Thanks,
Mike
I have been really impressed with the T4.1. In a comparison of instructions-per-second the T4.1 is 5000x faster, so it seems like I've got infinite CPU cycles, but when it comes to splitting these two process into two threads, I'm running into "single-threading" conflicts. I've created a thread for the I2C sampling that runs at 500hz without issue. I've also created a thread (or keep it in the main loop) that writes to the SD card at 100hz just fine. But, when I run them together, my sample rate on the sensors drops down to 40hz and my SD logging drops way down. I have stacked both loops with a lot of thread.yield() statements, but I suspect the SD card open/close functions are locking the CPU and starving the sampling thread.The two threads do share global variables, but the SD thread only reads, while the sensor side updates the variables.
Any suggestions on how to get these two I/O intense process to behave more like the dual-cores on the ESP32 would be appreciated.
Thanks,
Mike