cancel
Showing results for 
Search instead for 
Did you mean: 

Debouncing interrupts

stenasc
Senior
Posted on March 10, 2013 at 23:38

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

Bob
14 REPLIES 14
stenasc
Senior
Posted on March 12, 2013 at 22:35

I understand all the types etc..it is the two lines below that are confusing...

if switch state == new switches return

My take on this is,,,

So if current switch state is the same as new switches...do nothing as the new switches hasn't changed...is this correct?

if old switches == new switches set switch state and set action flag

This to me means if the last switch value is the sames as the new switch values, which implies that no switch change has been made.

Would it not be ...if (old switches ^ new switches) set switch state and set action flag....This would detect a change in the switches.

mrupprath
Associate II
Posted on March 13, 2013 at 12:51

Hello;

another approch for key debouncing

1. You can buy special ''factory'' debnounced switches

2. use an RC circuit to provide the input signal to the µC Port

3. Use the ''one shot'' function of the build in µC Timers

 

  

emalund
Associate III
Posted on March 13, 2013 at 15:57

if switch state == new switches return

My take on this is,,,

So if current switch state is the same as new switches...do nothing as the new switches hasn't changed...is this correct?

YES

if old switches == new switches set switch state and set action flag

This to me means if the last switch value is the sames as the new switch values, which implies that no switch change has been made.

NO, ''same as the new switch values'' is taken care of in the previous statement, THIS means that the switches read the same twice i.e. are debounced

Erik
Posted on March 14, 2013 at 07:37

another approch for key debouncing

 

 

1. You can buy special ''factory'' debnounced switches

 

2. use an RC circuit to provide the input signal to the µC Port

 

3. Use the ''one shot'' function of the build in µC Timers

 

4. You can buy ''switch debounce'' chips; eg,

http://www.maximintegrated.com/datasheet/index.mvp/id/1896

See also:

http://www.maximintegrated.com/app-notes/index.mvp/id/1858

stenasc
Senior
Posted on March 14, 2013 at 09:27

Hi Erik,

Thanks for that...got you now.