ESP32 high resolution pulse capture
Budget: $30 – $250 USD
I have a sensor that outputs a pulse that begins with a 375ns low period, followed by a variable high period. The total period from low-going pulse to low-going pulse is the sensor's data that it is trying to convey.
The minimum total period is 2000ns (2.0us) and the maximum can be up to 50.0us. The attached example.jpg shows when the sensor outputs a total duration of 5000ns (5.000us).
I need to capture the total period at 40MHz (25ns resolution) and store those times in PSRAM. The data could be stored in local RAM first and then copied to PSRAM. 300,000 pulses will typically be captured and stored (hence the need for PSRAM).
I am currently using the ESP32S2, but I would switch to the S3 if needed. I will not switch CPU families... I am stuck using the ESP32.
I am told by several experts that there are 3 ways to accomplish this.
1 - Using the RMT periperhal. Setting the clock divider to 2 (40MHz, which is 25ns resolution). The issue here seems to be that only the ESP32S3 has a ping-pong buffer possibility. It may be that at 2.0us minimum pulse duration there is not enough time for the interrupt handler to respond (unless in assembly code, which I am fine with using).
2 - Using the timer interrupt and GPIO pin change interrupt to time the FALLING to FALLING period. This is probably the least likely to work due to jitter and overhead with the older ESP32 chips that did not have the new GPIO direct access option. So, maybe this is an option with the ESP32S2?
3 - Use the I2S to receive a data stream on a GPIO pin at 40MHz and store the bit stream. This sound like a good solution. I2S has a ping-pong buffer built in. I can decode the bit stream and turn that into the proper time periods.
I also need to be able to take this same data that is stored and "play" it back (output it) just like the original signal.
So, basically this is a single channel logic analyzer that captures at 40MHz.
This code must use the Arduino core files. I use both the Arduino IDE and PlatformIO. I prefer PlatformIO.
You will need to know the ESP32 peripherals, C++, and probably assembly language.
Its a very simple project, but I have no time to do the research on these 3 methods to determine which is best and to write a sample that works... that's why I am here!
If you have any questions, please contact me!
The minimum total period is 2000ns (2.0us) and the maximum can be up to 50.0us. The attached example.jpg shows when the sensor outputs a total duration of 5000ns (5.000us).
I need to capture the total period at 40MHz (25ns resolution) and store those times in PSRAM. The data could be stored in local RAM first and then copied to PSRAM. 300,000 pulses will typically be captured and stored (hence the need for PSRAM).
I am currently using the ESP32S2, but I would switch to the S3 if needed. I will not switch CPU families... I am stuck using the ESP32.
I am told by several experts that there are 3 ways to accomplish this.
1 - Using the RMT periperhal. Setting the clock divider to 2 (40MHz, which is 25ns resolution). The issue here seems to be that only the ESP32S3 has a ping-pong buffer possibility. It may be that at 2.0us minimum pulse duration there is not enough time for the interrupt handler to respond (unless in assembly code, which I am fine with using).
2 - Using the timer interrupt and GPIO pin change interrupt to time the FALLING to FALLING period. This is probably the least likely to work due to jitter and overhead with the older ESP32 chips that did not have the new GPIO direct access option. So, maybe this is an option with the ESP32S2?
3 - Use the I2S to receive a data stream on a GPIO pin at 40MHz and store the bit stream. This sound like a good solution. I2S has a ping-pong buffer built in. I can decode the bit stream and turn that into the proper time periods.
I also need to be able to take this same data that is stored and "play" it back (output it) just like the original signal.
So, basically this is a single channel logic analyzer that captures at 40MHz.
This code must use the Arduino core files. I use both the Arduino IDE and PlatformIO. I prefer PlatformIO.
You will need to know the ESP32 peripherals, C++, and probably assembly language.
Its a very simple project, but I have no time to do the research on these 3 methods to determine which is best and to write a sample that works... that's why I am here!
If you have any questions, please contact me!