Page 1 of 1

High Speed Logging of GPIO states

Posted: Wed May 12, 2021 7:30 am
by paras99
So in my program I have

Code: Select all

for(;;)
	printf("%lld\n",esp_timer_get_time());
only this much code
I am pretty much amazed by the results
2817315
2818096
2818878
these are almost 780 microsec apart...How is this possible considering esp32 runs at 240Mhz
Forgive me If I asked a NOOB level question...I get it has to perform numerous cycles to execute even a single line of code but the values are much far from 240Mhz its nearly 1.2Khz(780microsec)

Please someone give some clarity.

Re: Clarity on processing speed

Posted: Wed May 12, 2021 8:10 am
by ESP_Minatel
Hi,

Using printf function to measure performance isn't the best thing to do (except if you're testing the function itself).

I recommend you to try some other approach for your test, using this example:

https://github.com/espressif/esp-idf/tr ... em/perfmon

or running CoreMark to test it:

https://www.esp32.com/viewtopic.php?t=14932

Re: Clarity on processing speed

Posted: Wed May 12, 2021 9:07 am
by paras99
OK That's perfect
I really need time value on terminal so can i reduce the gap of 780 microsec ?

I need to log a GPIO behavior with time, Can You suggest any better way where the gap can be minimized

Re: Clarity on processing speed

Posted: Wed May 12, 2021 9:28 am
by ESP_Minatel
Do you need the log to be real time? Why don't you store some results and print it after the test?

The main problem here is the serial log. If you are using 115200 bps on the serial log, this will be your bottleneck (assuming your current approach).

If you need to measure the GPIO speed, you can use an oscilloscope, for example, to measure the frequency.

I'm still not sure what you need to test. Can you give more details?

Re: Clarity on processing speed

Posted: Wed May 12, 2021 10:04 am
by paras99
I need to log the behavior of a GPIO ... I am not doing any type of speed test , I need this for system Identification , Basically I want to do GPIO get Input of that particular pin and store a timestamp ....for this what I did was
printf("%d\t%lld\n",gpio_get_level(INPUT_SIG_IO),esp_timer_get_time());
The states printed were around 1millisecond apart . I would run this program for 1-2 minutes my job is done .But the issue here is resolution.
I get it now the baudrate,printf statements were causing this delay

i want something from which I could get the states at a much higher resolution.
I dont want realtime...I can store and get the values later if it something like that is possible

Re: Clarity on processing speed

Posted: Wed May 12, 2021 10:51 am
by ESP_Minatel
Ok, I think you should take a look at the RMT peripheral and the Pulse Counter.

For your application, I think you can have a try with the RMT in receiver mode: https://docs.espressif.com/projects/esp ... s/rmt.html

Pulse Counter (for reference): https://docs.espressif.com/projects/esp ... /pcnt.html

Using RMT you can get the timing of each pulse from the ring buffer and print it periodically.

We don't have any example on how to use for this purpose, but you can have a look at this example: https://github.com/espressif/esp-idf/bl ... _protocols

Re: Clarity on processing speed

Posted: Wed May 12, 2021 10:57 am
by paras99
Thanks a lot I will definitely try that method

Re: High Speed Logging of GPIO states

Posted: Wed May 12, 2021 5:05 pm
by paras99
Just letting you all know I omitted printfs and stored all the states in a bit array . I reduced delay from 780microsecs to 200nanoseconds thats a super success