High Speed Logging of GPIO states

paras99
Posts: 11
Joined: Tue Nov 17, 2020 11:46 am

High Speed Logging of GPIO states

Postby paras99 » Wed May 12, 2021 7:30 am

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.
Last edited by paras99 on Wed May 12, 2021 10:58 am, edited 1 time in total.

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: Clarity on processing speed

Postby ESP_Minatel » Wed May 12, 2021 8:10 am

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

paras99
Posts: 11
Joined: Tue Nov 17, 2020 11:46 am

Re: Clarity on processing speed

Postby paras99 » Wed May 12, 2021 9:07 am

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

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: Clarity on processing speed

Postby ESP_Minatel » Wed May 12, 2021 9:28 am

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?

paras99
Posts: 11
Joined: Tue Nov 17, 2020 11:46 am

Re: Clarity on processing speed

Postby paras99 » Wed May 12, 2021 10:04 am

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

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: Clarity on processing speed

Postby ESP_Minatel » Wed May 12, 2021 10:51 am

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

paras99
Posts: 11
Joined: Tue Nov 17, 2020 11:46 am

Re: Clarity on processing speed

Postby paras99 » Wed May 12, 2021 10:57 am

Thanks a lot I will definitely try that method

paras99
Posts: 11
Joined: Tue Nov 17, 2020 11:46 am

Re: High Speed Logging of GPIO states

Postby paras99 » Wed May 12, 2021 5:05 pm

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

Who is online

Users browsing this forum: No registered users and 190 guests