Page 1 of 1
Debouncing inductive sensor input
Posted: Wed Jan 30, 2019 7:12 am
by Philosophix
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?
Re: Debouncing inductive sensor input
Posted: Wed Jan 30, 2019 7:40 am
by OutoftheBOTS_
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
Re: Debouncing inductive sensor input
Posted: Wed Jan 30, 2019 8:15 am
by Philosophix
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?