r/esp32•
dls2016

Input Capture

I'm looking to obtain a precise time of arrival of a GPS PPS signal... but I can't find a clean example. I've seen suggestions elsewhere that it may be possible to perform input capture using either the RMT or MCPWM peripherals. Eventually I'd like to capture a "sample ready" pulse from an ADC, as well. I don't care about pulse duration.

Can anyone suggest one method over the other (or a third alternative)? It looks like both provide 80MHz resolution, though with different timer bit depths.

Posted Sep 2, 2020, 4:40 PM UTC

33
g6ejd•

Doesn’t the GPS receiver do all that? It receives signals from at least satellites to get a position. The time of arrival would have to be compared to a very accurate real time clock but using NTP has only a 1-sec resolution so I don’t see a solution. What are you trying to do?

1
dls2016OP•

GPS receivers produce an extremely precise pulse-per-second output as a side effect of calculating position. Additionally, I have an ADC being driven by a stable oscillator with variable frequency (often this is a voltage controlled, oven-controlled crystal oscillator). By comparing the time-of-arrival of the GPS PPS and the oscillator, one can steer the ADC so that the samples occur at precise intervals, even across a sensor network (<100ns precision according to some papers). This is called GPS-disciplined sampling.

I need to be able to compare the time of arrival of the GPS PPS and the ADC sample-ready pulses with very fine precision, then use a control loop to minimize the difference between the PPS and the N-th ADC pulse (where N is the desired sample rate).

I think I'm leaning towards learning more about the MCPWM module, as it has the ability to detect edges on three inputs with 80MHz resolution/32 bit timer. This would give me 12.5ns nominal resolution (subject to environmental factors).

1
dls2016OP•

Ok I lied, Espressif's MCPWM example is clear. I commented out a bunch of stuff not related to input capture on a single pin, changed the gpio pin definition and removed the conversion to microseconds to give me tick output. Fired up immediately. The clock seems fairly stable at +-1 tick per PPS under constant room temperature.

1