PDA

View Full Version : Matrix keyboard and sleep



Ioannis
- 10th December 2022, 21:35
I am trying to get rid of double keypress of the same key in the matrix keyboard that is scanned by the PIC 16F886 after it wakes up from sleep.

Not always but random times some of the key presses are detected two times. I think either a debounce or waiting for key release could help but cannot find a way to make it work.

After any key press a beep is generated to give feedback.

The 886 is in sleep and IOC is enabled to detect keypress of the matrix.

Then flag pressed is set and main routine takes over.

Attached is the program. Just delete the .txt extension.

Ioannis

9295

mpgmike
- 14th December 2022, 21:07
I didn't download your program, as I surf with my Mac and PBP on my PC. I would have to thumb-drive it over to look. However, the debounce procedure that works well for me it to detect a button press, then pause about 50 ms to see if it's still pressed. Then wait until it is no longer pressed, and wait another 50 ms. Something like this:


IOC_ISR:
IF PORTB.4 = 1 THEN 'Button is pressed
PAUSE 50 'Give it a chance to stabilize
IF PORTB.4 = 1 THEN 'Recheck to verify button press
WHILE PORTB.4 = 1 'Wait until button is released
END WHILE
PAUSE 50 'To give any rogue static bounces a chance to fizzle
'Take Action Based on Button Press
ENDIF
ENDIF

I've been coding in XC8 for the past couple years. My PBP is getting a bit rusty. Forgive me if my syntax isn't correct, but hopefully you get the gist of what I'm trying to accomplish.

Ioannis
- 15th December 2022, 08:16
Thanks Mike.

The problem is that the keyboard is a matrix one that is scanned to see which key was pressed. This complicates the case...

Ioannis

mpgmike
- 15th December 2022, 12:54
Maybe you could use a Timer to mask recently pressed buttons. When PORTB.4 IOC triggers, disable the IOC Interrupt for that pin, start your 50 ms Timer, then in the Timer ISR restore all IOC Interrupts, regardless of which one you disabled for the mask.

Ioannis
- 15th December 2022, 13:59
I am not sure why you mention the portb.4 bit but regardless, the idea to use timer is good. Thanks.

Matrix keyboard is more complicated in that aspect, also if sleep is also involved.

Ioannis