Very accurate timer implementation

holopaul
Posts: 7
Joined: Sat Jun 23, 2018 2:49 am

Very accurate timer implementation

Postby holopaul » Sat Jun 23, 2018 3:15 am

Hi,

I'm trying to detect some fast events.
I have two signals from two sensors. The signal looks like this :HIGH 60-130 microseconds (us), LOW 0-2700 microseconds (us), HIGH 0-20 microseconds (us). I need to measure the length of each event as accurate as possible.

What is the best approach?

Thank you!
Attachments
signal.png
signal.png (24.51 KiB) Viewed 428 times

User avatar
kolban
Posts: 1572
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Very accurate timer implementation

Postby kolban » Sat Jun 23, 2018 11:50 am

My gut is saying I would look at the RMT peripheral functions. This appears to be able to record pulse transitions down to 12.5 nanoseconds (1/80Mhz). See:

http://esp-idf.readthedocs.io/en/latest ... s/rmt.html
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Available for ESP32 consulting.

holopaul
Posts: 7
Joined: Sat Jun 23, 2018 2:49 am

Re: Very accurate timer implementation

Postby holopaul » Mon Jun 25, 2018 1:45 am

Hi kolban,
Thanks you for answering my question.
I will go with your call and get back with the results. I had some trouble with timer intrerupts given minimum prescaler value of 2 (80/2).
Do you think using the I2s infrastructure DMA capable to read this signal would be another viable alternative?
Thanks

ESP_Angus
Posts: 1002
Joined: Sun May 08, 2016 4:11 am

Re: Very accurate timer implementation

Postby ESP_Angus » Mon Jun 25, 2018 6:26 am

holopaul wrote:Do you think using the I2s infrastructure DMA capable to read this signal would be another viable alternative?


You could probably hack something up by injecting a dummy reference clock for I2S to sample against.

The RMT peripheral is significantly better suited to this, though - I can't think of any way that I2S could be made to outperform it.

RMT is designed to solve almost the exact problem you have, and it's also based on DMA-like functionality so measurement accuracy is not limited by interrupt latency - the pulse timings are written to a memory block, and then an interrupt fires so you can retrieve them.

holopaul
Posts: 7
Joined: Sat Jun 23, 2018 2:49 am

Re: Very accurate timer implementation

Postby holopaul » Mon Jun 25, 2018 3:31 pm

Gentlemen thank you for your time. This approach looks very promising and seems like i have some reading and testing to do.

holopaul
Posts: 7
Joined: Sat Jun 23, 2018 2:49 am

Re: Very accurate timer implementation

Postby holopaul » Mon Jul 02, 2018 7:08 pm

Hello,
I did some reading about RMT and it looked too good to be true. And if i'm not mistaking, it is exactly that way.
The main problem is the 16 (or 15) bit resolution. My signal train is exactly 8.3 ms(120 Hz) long. I really need the 12.5 ns (80MHz) granularity because the timebase of my signal is 20.9 ns / tick (48MHz). But at this speed i can't measure the whole train. I need to measure as accurate as possible only t0 and t1. Is there another option to measure this? Thank you
Attachments
ir-signals-timing.jpg
ir-signals-timing.jpg (9.46 KiB) Viewed 184 times

WiFive
Posts: 1820
Joined: Tue Dec 01, 2015 7:35 am

Re: Very accurate timer implementation

Postby WiFive » Mon Jul 02, 2018 10:37 pm

If you have 12.5ns and 32767 samples per entry so max 409us per entry so your total signal should use max 20 entries

holopaul
Posts: 7
Joined: Sat Jun 23, 2018 2:49 am

Re: Very accurate timer implementation

Postby holopaul » Mon Jul 02, 2018 11:41 pm

@WiFive, I'm afraid I don't quite follow you. Please explain. Also RMT is in RX mode. I cannot modify the signal. thanks

WiFive
Posts: 1820
Joined: Tue Dec 01, 2015 7:35 am

Re: Very accurate timer implementation

Postby WiFive » Tue Jul 03, 2018 12:08 am

Oh I see you are saying the idle threshold can't be more than 819us.

What about mcpwm capture?

holopaul
Posts: 7
Joined: Sat Jun 23, 2018 2:49 am

Re: Very accurate timer implementation

Postby holopaul » Tue Jul 03, 2018 2:05 am

Okay, i didn't know about this one, thanks. I'll give it a try. But isn't this based on regular intrerupts? The good thing is that the timer is 80Mhz. Have you tried it for capturing signals?

Who is online

Users browsing this forum: Bing [Bot], loboris, WiFive and 5 guests