Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4777

General discussion • reading duration of a signal using PIGPIO

$
0
0
I have a device that continuously sends the signal of different pulse widths. I am trying to read those pulse duration and build my logic to further implement it. It is a synchronous signal.
I am using raspberry pi zero w and using GPIO 4 to read the signal using the monitor.py code.
However when i see the oscilloscope trace it is clear and the minimum duration is 1000micros.

But when i am reading the values, in between it gives me 50, 250, 90 and so on.. the values are inconsistent. And the output seems not to be synchronous.

Since it a synchronous signal the start is detected by a long Low duration of 63ms. But I am not getting the desired output when i run monitor.py

Below is my monitor.py code:

Code:

# monitor.py# 2016-09-17# Public Domain# monitor.py          # monitor all GPIO# monitor.py 4        # monitor GPIO 4import sysimport timeimport pigpiolast = [None]*32cb = []def cbf(GPIO, level, tick):   if last[GPIO] is not None:      diff = pigpio.tickDiff(last[GPIO], tick)      if diff >= 59000:  # Check if difference is greater than or equal to 59000         print("G={} l={} d={}".format(GPIO, level, diff))      else:  # Print other differences         print("G={} l={} d={}".format(GPIO, level, diff))   last[GPIO] = tickpi = pigpio.pi()if not pi.connected:   exit()# Check if GPIO 4 is specified in the command line argumentsif len(sys.argv) == 1 or '4' in sys.argv:   cb.append(pi.callback(4, pigpio.EITHER_EDGE, cbf))   try:   while True:      time.sleep(60)except KeyboardInterrupt:   print("\nTidying up")   for c in cb:      c.cancel()pi.stop()

Below is my output:

G=4 l=1 d=62295
G=4 l=0 d=1321
G=4 l=1 d=5
G=4 l=0 d=444
G=4 l=1 d=5
G=4 l=0 d=2056
G=4 l=1 d=3065
G=4 l=0 d=1019
G=4 l=1 d=870
G=4 l=0 d=6
G=4 l=1 d=2189
G=4 l=0 d=1020
G=4 l=1 d=3066
G=4 l=0 d=304
G=4 l=1 d=5
G=4 l=0 d=770
G=4 l=1 d=3005
G=4 l=0 d=426
G=4 l=1 d=5
G=4 l=0 d=564
G=4 l=1 d=5
G=4 l=0 d=20
G=4 l=1 d=1020


Those 3 digit numbers are undesirable. I am not able to figure out what is going wrong.

Statistics: Posted by Axon_11 — Wed Apr 24, 2024 2:18 am



Viewing all articles
Browse latest Browse all 4777

Trending Articles