Function similar to Pulse In in C
-
@devang-sharma pycom.pulses_get() uses the RMT unit of the ESP32, and AFAIK this has 15 bit registers for a pulse width. Therefore the maximum pulse length it can detect is about 32 ms, which I expect to be the largest timeout.
-
@livius It really depends on the period window of the particular sensor. Generally it is in milliseconds, while the timeout parameter in pycom.pulses_get() is in microseconds. So it should be set higher. But it may not be able to detect larger pulse widths(in ms).( I don't know the exact amount though)
-
@soren
this can have too small resolution
why not using already mentioned by @robert-hhpycom.pulses_get()
?
-
Hi, I just noticed this thread and was wondering if a pulseIn function could be done like this. Here "sout" is my input pin where I get pulses:
def pulseIn(self, val): lap = 0 while True: # wait until we receive provided val (0 / 1) if sout() == val: chrono.start() # start timer break while True: # wait until value changes if sout() != val: lap = chrono.read() # read time it took chrono.stop() return lap
-
@devang-sharma That's tricky. It depends if you can narrow down the time window when you expect the pulse. Normally you would set up an interrupt service routine for the rising slope and then time the pulse. That is not a recommended method with LoPy (xxPy). The interrupt latency is large an varying between 50 and 900 µs (!).
If you trigger the sensor and know the time windows when to expect the response pulse, like within the next 2 ms, the you can use pulses_get with a sufficiently large timeout, like 3 ms. The result would be entries in the list, a low period for the initial wait time, the high pulse period.
-
@robert-hh Okay. I just have one question. I need to get values of a sensor as soon as the pin is made HIGH. Is it possible?
Thanks.
-
@devang-sharma The pycom port das a different function, called pycom.pulses_get() https://docs.pycom.io/chapter/firmwareapi/pycom/pycom.html
This function is more generic and times a sequence of high/low pulses.