User avatar
Grumpy Mike
Posts: 1001
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District
Contact: Website

[solved] Pico GPIO interrupts

Tue Apr 20, 2021 9:46 am

I am trying to implement a rotary encoder interface using GPIO interrupts.

As there is only one vector for all GPIO interrupts and I want some single buttons as well, then in the interrupt handling function I look at what pin has caused the interrupt and pass the call to the appropriate function. All well and good, but I am finding that the events variable which contains bits to show what caused the interrupt is sometimes indicating that the interrupt was called both by a rising edge and a falling edge which is clearly a nonsense.
I have tried some software debounce but it makes no difference. Both pins have 1K pull up resistors and the signals on the scope look almost like RF, that is many times higher frequency than the pin excursions.
Any idea why the interrupt cause is showing both levels?
Last edited by Grumpy Mike on Wed Apr 21, 2021 9:02 am, edited 1 time in total.

User avatar
joan
Posts: 15649
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Pico GPIO interrupts

Tue Apr 20, 2021 9:58 am

Are they mechanical? If so switch bounce. You might easily get a couple of edges within less than a microsecond. Your interrupt handling might be taking too long.

User avatar
Grumpy Mike
Posts: 1001
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District
Contact: Website

Re: Pico GPIO interrupts

Tue Apr 20, 2021 11:46 am

Yes it is mechanical, I slugged it with a 0.1uF ceramic, signals look as clean as a whistle but still I get some readings showing both up and down states.

User avatar
Grumpy Mike
Posts: 1001
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District
Contact: Website

Re: Pico GPIO interrupts

Wed Apr 21, 2021 9:02 am

You might easily get a couple of edges within less than a microsecond. Your interrupt handling might be taking too long.
I don't see how that should be a problem. An interrupt gets triggered and at the same time an interrupt enable bit somewhere in the processor is cleared. Then for the length of the ISR that pin can do the sailors horn pipe for all we care nothing should affect it until that ISR is finished. So that suggests to me an error in the interrupt mechanism in the processor or a lack of correct interrupt handling in the low level routines.

Anyway I have come to the conclusion that the events returned with the callback function are not to be trusted. Therefore, I took to actually looking at the two pins in question and using those values to drive a state machine. This approach worked well and so I consider the matter closed.

Thanks.

divyam5129
Posts: 14
Joined: Sun Jan 31, 2021 6:46 pm

Re: [solved] Pico GPIO interrupts

Sun Jun 13, 2021 1:28 pm

Hi, I am trying to use Water flow sensor with raspberry pi pico and I am trying to write the code from C++(Arduino) to Micropython and there is an interrupt fuction that I can't get hold of. Someone please help me!

User avatar
Grumpy Mike
Posts: 1001
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District
Contact: Website

Re: [solved] Pico GPIO interrupts

Sun Jun 13, 2021 9:00 pm

This is the link to interrupts in MicroPython. They are called "call backs"
https://docs.micropython.org/en/latest/ ... witch.html

Return to “SDK”