How to debounce in xmega?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void row1_col1()
{
		
		PORTC.OUTSET = 0x20;
		PORTC.OUTCLR = 0x0F;
		PORTC_OUTCLR = 0xD0;
		
	if(((PORTC.IN & 0x01)==0b00000001)&&((PORTC.IN & 0x2F)==0b00100000)) //1
	{
		
		blinkduration =1;
		blink(); //LED toggle

	}
	
}

This is a part of the matrix keypad code for xmega a3bu, I'm not understanding how to write a debounce logic for the same.

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just read at a regular interval, in the range of a few milliseconds. When you get some number in a row with the same value, then it is not bouncing.

 

There are other ways, of course. But I always have some kind of "clock" ticking so that works just fine for me.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Jim says the technique for debounce is pretty much the same whatever the micro (which is why Jack Ganssle was able to write the renowned papers that show the common solutions). The essence of it is that you need "temporal sampling". That is something that is going to read the input states at fixed time intervals and compare the "history" of the input over a few samples to see if it's been seen in a stable state for a while. To do that implies the use of a timer. So folks typically setup a timer interrupt that occurs every few milliseconds and each time it checks the input pins and records their history. If several recent samples are all the same state the pin can be considered to have settled into that state.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

nitinjs wrote:

This is a part of the matrix keypad code for xmega a3bu, I'm not understanding how to write a debounce logic for the same.

 

How I do it is to split the problem into two parts...

 

1) Read the matrix keypad

2) Debounce the result

 

What I do, for a 4x4 keypad, is read the keypad and put the result into a 16-bit variable where each bit corresponds to a specific key. I then debounce that value using 'vertical counters'.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss