detect interrupt type in ISR?

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
dwculp
Posts: 12
Joined: Wed Jul 13, 2016 6:43 pm

detect interrupt type in ISR?

Post by dwculp » Wed Jul 13, 2016 6:48 pm

I just got my Pyboard and have been putting it through some tests. I need to know the following:

1. Is it possible to tell the interrupt type (rising or falling) inside of an ISR that is set to trigger on both a rising and falling signal?

2. Or, is it possible to set up multiple callbacks for the same pin, one for a rising edge and another for a falling?

I need to do something different based upon if the interrupt occurs on a rising to falling signal.

Thanks!

David

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: detect interrupt type in ISR?

Post by dhylands » Wed Jul 13, 2016 10:37 pm

dwculp wrote:I just got my Pyboard and have been putting it through some tests. I need to know the following:

1. Is it possible to tell the interrupt type (rising or falling) inside of an ISR that is set to trigger on both a rising and falling signal?
I'm not aware of anyway of detecting this. What I do is query the gpio value to figure that out (not perfect, but the best I've been able to figure out for now). See: https://github.com/dhylands/upy-example ... ic_test.py
dwculp wrote:2. Or, is it possible to set up multiple callbacks for the same pin, one for a rising edge and another for a falling?
That's not possible (at least not on the pyboard).
dwculp wrote:I need to do something different based upon if the interrupt occurs on a rising to falling signal.
If it's a clean signal, then reading the GPIO is probably the best way. If it's a push button, then you'll need to add debouncing as well.

dwculp
Posts: 12
Joined: Wed Jul 13, 2016 6:43 pm

Re: detect interrupt type in ISR?

Post by dwculp » Thu Jul 14, 2016 1:02 am

Thanks for the reply! I was actually looking at the value of the pin inside the ISR but it was not working as expected. Essentially I wanted to set up a simple ISR that turned an LED on if the switch was down, and turn it off upon releasing the switch. It was not working as expected.

I finally figured it out....................I was looking at the wrong pin inside the ISR due to a typo :lol:

It works as expected now after a few hours of frustration and then changing one character :twisted:

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: detect interrupt type in ISR?

Post by dhylands » Thu Jul 14, 2016 3:41 pm

Also beware that a switch can have a very noisy signal, so pressing or releasing a switch can cause multiple edges.
http://www.ganssle.com/debouncing.htm
http://www.ganssle.com/debouncing-pt2.htm

The switch on the pyboard isn't too bad, and most of the time I'll just get 2 edges, but occasionally, I'll get several.

dwculp
Posts: 12
Joined: Wed Jul 13, 2016 6:43 pm

Re: detect interrupt type in ISR?

Post by dwculp » Thu Jul 14, 2016 5:08 pm

Yep, I properly debounced it.

I have to say, this is one of the cooler little devices I have played with. I plan to turn it into a general purpose robotics controller for small mobile robots and let my students experiment with them.

Post Reply