Debouncing inductive sensor input

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Philosophix
Posts: 24
Joined: Wed Jan 02, 2019 11:45 am

Debouncing inductive sensor input

Post by Philosophix » Wed Jan 30, 2019 7:12 am

I have an inductive sensor on X20 setup with an interrupt like so:

Code: Select all

import stm

def axle_pulse_detected(line):
    stm.mem32[stm.RTC+stm.RTC_BKP9R] += 1

ExtInt(Pin('X20'), ExtInt.IRQ_RISING, Pin.PULL_UP, axle_pulse_detected)
What would be a good way do debounce the input, as I now get sporadic extra pulses at power down?

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Debouncing inductive sensor input

Post by OutoftheBOTS_ » Wed Jan 30, 2019 7:40 am

not sure if it is a good way but what I usually do is in the first line of the call back function I disable the interrupt to stop it triggering lots of times then I have a small de-bounce delay then I execute the rest of the function then on last line of code before exiting the function I re-enable the interrupt

I don't know how Micro-python handles interrupts on STM32 but when I use low level C code on STM32 when an interrupt fires it can't fire again un-till the pending bit is reset in the pending register. This will stop switch bounce firing the interrupt many times but it is probable that Micro-python automatically resets the pending bit for you as it is a higher level language

Philosophix
Posts: 24
Joined: Wed Jan 02, 2019 11:45 am

Re: Debouncing inductive sensor input

Post by Philosophix » Wed Jan 30, 2019 8:15 am

Thanks, I'll try that. Do you know if the interrupt gets called already when I set

Code: Select all

ExtInt(Pin('X20'), ExtInt.IRQ_RISING, Pin.PULL_UP, axle_pulse_detected)
which will pull up the line causing a rising signal?

Post Reply