Libgpiod missing events

Dear Toradex Community,

i am using the libgpiod to detect some buttons (in this example a PTT Button on an microphone) as inputs.
In my application i use the libgpiod-python API and noticed some weird behavior while detecting libgpiod-events. This leads to my software debouncing not detecting any button press if the last event is missing (at least this is my guess).
To exclude errors in my application, i try to show the problem with the default command line tools from libgpiod.

root@colibri-imx7:~# gpiomon --version
gpiomon (libgpiod) v1.4.3
Copyright (C) 2017-2018 Bartosz Golaszewski
License: LGPLv2.1
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
root@colibri-imx7:~# gpiomon 3 23
event: FALLING EDGE offset: 23 timestamp: [1581090954.384962000]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385014750]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385021875]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385075375]
event:  RISING EDGE offset: 23 timestamp: [1581090954.385326750]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385362625]
event:  RISING EDGE offset: 23 timestamp: [1581090954.385382750]
event:  RISING EDGE offset: 23 timestamp: [1581090954.385556500]
event:  RISING EDGE offset: 23 timestamp: [1581090954.385575000]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385586375]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385600750]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385613875]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385624750]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385645750]
event: FALLING EDGE offset: 23 timestamp: [1581090954.385658250]
event:  RISING EDGE offset: 23 timestamp: [1581090960.342767000]

This is the event log of gpiomon detecting a single button press and release with some bouncing action. As you can see there are multiple sections multiple falling edge events follow after each other (which should not be possible in my understanding). Because of this i think there are missing events in between, or there is some problem with the libgpiod itself.

This is a screenshot from the oscilloscope at the button press:

I will try some additional hardware debouncing but i would like to prevent this libgpiod behavior in the first place.
Have you some tips or ideas why there are multiple falling edges after each other?

Thanks for reading :slight_smile:

Thanks for your answer,

i hoped i could prevent this behavior in the software before adding the additional hardware RC, but i guess that’s my only hope.

The RC filter solution works fine with the PTT button:

event: FALLING EDGE offset: 23 timestamp: [1581090774.301520000]
event:  RISING EDGE offset: 23 timestamp: [1581090774.756483125]
event: FALLING EDGE offset: 23 timestamp: [1581090775.627235375]
event:  RISING EDGE offset: 23 timestamp: [1581090776.000433375]
event: FALLING EDGE offset: 23 timestamp: [1581090776.378505500]
event:  RISING EDGE offset: 23 timestamp: [1581090776.701697250]
event: FALLING EDGE offset: 23 timestamp: [1581090777.050067625]
event:  RISING EDGE offset: 23 timestamp: [1581090777.350181250]
event: FALLING EDGE offset: 23 timestamp: [1581090777.774775125]
event:  RISING EDGE offset: 23 timestamp: [1581090778.142102750]
event: FALLING EDGE offset: 23 timestamp: [1581090778.620138750]
event:  RISING EDGE offset: 23 timestamp: [1581090778.886432125]
event: FALLING EDGE offset: 23 timestamp: [1581090779.107011750]
event:  RISING EDGE offset: 23 timestamp: [1581090779.261633875]
event: FALLING EDGE offset: 23 timestamp: [1581090779.637234625]
event:  RISING EDGE offset: 23 timestamp: [1581090779.868029000]
event: FALLING EDGE offset: 23 timestamp: [1581090780.168051250]
event:  RISING EDGE offset: 23 timestamp: [1581090780.331965000]
event: FALLING EDGE offset: 23 timestamp: [1581090780.547924000]
event:  RISING EDGE offset: 23 timestamp: [1581090780.676186125]
event: FALLING EDGE offset: 23 timestamp: [1581090780.818459375]
event:  RISING EDGE offset: 23 timestamp: [1581090780.954200250]
event: FALLING EDGE offset: 23 timestamp: [1581090781.037623000]
event:  RISING EDGE offset: 23 timestamp: [1581090781.165274125]
event: FALLING EDGE offset: 23 timestamp: [1581090781.288592500]
event:  RISING EDGE offset: 23 timestamp: [1581090781.404736750]

I have some more pushbuttons of a different type which i don’t want to RC-filter each. Those buttons seem to bounce way less, so i hope my application register all the pushes of them in the future. For the PTT button i am going to add the filter into the final design.

Also thanks for the great support from Toradex :slight_smile:

iMX7D GPIO can sense either falling or rising edge, but not both simultaneously. Changing sensitivity direction takes time and SW may loose events in that time. But application or perhaps libgpiod could check pin level after changing rising/falling mode and this way not lose last event.

I didn’t use gpiomon before. Why does it require unexported gpio in /sys/class/gpio ? It exits with error if pin is exported, even though direction is “in”.

Linux is not a real time OS, so if you have too many interrupts in a short time some of them can be missed. Could you try to connect an RC filter in parallel with your button?

Where did you find the info with “iMX7D GPIO can sense either falling or rising edge, but not both simultaneously”?

i.MX 7Dual Applications Processor Reference Manual

Chapter 8. Chip IO and Pinmux

Each GPIO input has a dedicated edge-detect circuit which can be configured through software to detect rising edges, falling edges, logic low-levels or logic high-levels on the input signals.

As well look around in registers. You will find settings for rising, for falling, but not for both simultaneously.

Thank you, i gonna dig deeper into that chapter.

But application or perhaps libgpiod
could check pin level after changing
rising/falling mode and this way not
lose last event.

I gonna implement an polling like pin level check in addition to the edge detection and the hardware RC-filter to be on the save side.

Perfect. Thanks for your Input.