2013-03-10 03:38 PM
Hi,
In our system, we are trying to debounce switches on GPIO lines. Every msec the switch is sampled using TIM3. After 16 ticks, if the input has settled, the idea is to set the interrupt pending register and trigger the interrupt. E.g.simple code to illustrate if (db_count = 16) EXTI->PR = 0x00000200; else EXTI_ClearITPendingBit(EXTI_Line9); Is this code valid. ie Can I manually set the interrupt pending register like this. When I use this method, I never see the pending reg being set at all. Is there anything else I need to do in order to set this reg? Many Thanks Bob2013-03-11 12:41 AM
''After 16 ticks, if the input has settled, the idea is to set the interrupt pending register and trigger the interrupt''
Taking a step back, why do you want to trigger another interrupt? At this point, you have a debounced event - why not just use it?!
2013-03-11 03:17 AM
> if (db_count = 16)
Shouldn't that be if (db_count == 16)2013-03-11 07:22 AM
the way I do switches (and it works)
global (for module?) switch state global (for module?) action flag TIMER_ISR (frequency set to ''bounce time'' - typically 10ms) new switches = read switches() if switch state == new switches return if old switches == new switches set switch state and set action flag old switches = new switches2013-03-12 01:12 AM
Sorry Trevor...yes I meant that...typo
2013-03-12 01:15 AM
Thanks for that Eric...I don't quite follow the logic.
What is happening at each of these lines. Bob2013-03-12 01:31 AM
There are of course several tested approaches that works well.
But IMHO, a sampling period of 1ms for manually operated keys is too high. It is really difficult to produce a keypress of less than 50ms, at least for a normal human. We have commercial products were 10ms or 20ms cycles work well. And at that frequency, you could even think about polling your keys, perhaps from a SysTick interrupt.2013-03-12 06:48 AM
Hi Eric,
I meant to post the lines that I didn't understand... if switch state == new switches return if old switches == new switches set switch state and set action flag What exactly are you checking for in each of these lines? Regards Bob2013-03-12 07:49 AM
global (for module?) word switch state what the main() see
global (for module?) bool action flag tell the main()that switches have changed TIMER_ISR (frequency set to ''bounce time'' - typically 10ms) word new switches the result of reading the switches at6 the beginning of the ISR word old switches what was read last time in the ISR new switches = read switches() if switch state == new switches return if old switches == new switches set switch state and set action flag old switches = new switches better? Eriki2013-03-12 12:29 PM
I like the www.Ganssle.com method.
global volatile uint16_t buttonState = 0;in timer callback or ISRbuttonState = (buttonState << 1) | button; //where button is 1 or 0, read from pinin main loop, switch is bounced when buttonState bits are either all 1 or all 0