Page 1 of 1

How to handle a fast signal

Posted: Sun Apr 18, 2021 1:14 pm
by proteus
Hello,

I need to detect and measure the duration of the transitions of a signal, how many us pass between two rising edges of a Signal, we are talking about times starting from 0.1ms up to a few ms.
It is an application that I had developed a few years ago using a Microchip uController and managing interrupts and an array I was able to get what I needed.

I did some tests using the interrupt on Pin.16 with an ESP8266 and with an ESP32, I can't get a precision on the timing detection, or sometimes I get different times, sometimes the interrupt is not executed and other times it seems that run several times ...??

I ask for advice, in your opinion which is the mothod/ technique to follow in order to be able to measure the duration (us), of the signal described above. (links, resources, examples, etc.)

I currently define the input pin
pin_13.irq (handler = int_pin13, trigger = machine.Pin.IRQ_RISING)

so in the routine that is called I go to calculate the elapsed time and then manage it.
def int_pin13(p):
new_time = utime.ticks_us ()
i_delta_time = utime.ticks_diff (i_new_time, i_old_time)
i_old_time = i_new_time

...

The Interrupt program is long but, shortening it, I have not noticed significant improvements.

thank you

Re: How to handle a fast signal

Posted: Sun Apr 18, 2021 4:00 pm
by Roberthh
The best results that you can achieve is using machine.time_pulse_us(). See https://docs.micropython.org/en/latest/ ... e_pulse_us.

Re: How to handle a fast signal

Posted: Sun Apr 18, 2021 4:43 pm
by proteus
I did not know "machine.time_pulse_us ()" I try immediately.

thanks