How to handle a fast signal

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
proteus
Posts: 5
Joined: Sat Jan 02, 2021 11:16 pm

How to handle a fast signal

Post by proteus » Sun Apr 18, 2021 1:14 pm

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

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to handle a fast signal

Post by Roberthh » Sun Apr 18, 2021 4:00 pm

The best results that you can achieve is using machine.time_pulse_us(). See https://docs.micropython.org/en/latest/ ... e_pulse_us.

proteus
Posts: 5
Joined: Sat Jan 02, 2021 11:16 pm

Re: How to handle a fast signal

Post by proteus » Sun Apr 18, 2021 4:43 pm

I did not know "machine.time_pulse_us ()" I try immediately.

thanks

Post Reply