Page 1 of 2

Very accurate timer implementation

Posted: Sat Jun 23, 2018 3:15 am
by holopaul
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!

Re: Very accurate timer implementation

Posted: Sat Jun 23, 2018 11:50 am
by kolban
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

Re: Very accurate timer implementation

Posted: Mon Jun 25, 2018 1:45 am
by holopaul
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

Re: Very accurate timer implementation

Posted: Mon Jun 25, 2018 6:26 am
by ESP_Angus
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.

Re: Very accurate timer implementation

Posted: Mon Jun 25, 2018 3:31 pm
by holopaul
Gentlemen thank you for your time. This approach looks very promising and seems like i have some reading and testing to do.

Re: Very accurate timer implementation

Posted: Mon Jul 02, 2018 7:08 pm
by holopaul
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

Re: Very accurate timer implementation

Posted: Mon Jul 02, 2018 10:37 pm
by WiFive
If you have 12.5ns and 32767 samples per entry so max 409us per entry so your total signal should use max 20 entries

Re: Very accurate timer implementation

Posted: Mon Jul 02, 2018 11:41 pm
by holopaul
@WiFive, I'm afraid I don't quite follow you. Please explain. Also RMT is in RX mode. I cannot modify the signal. thanks

Re: Very accurate timer implementation

Posted: Tue Jul 03, 2018 12:08 am
by WiFive
Oh I see you are saying the idle threshold can't be more than 819us.

What about mcpwm capture?

Re: Very accurate timer implementation

Posted: Tue Jul 03, 2018 2:05 am
by holopaul
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?