Correct way to debounce switches?

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
sjalloq
Active Member
Posts: 55
Joined: Tue Jan 12, 2010 1:49 pm

Correct way to debounce switches?

Postby sjalloq » Tue Feb 02, 2010 8:30 pm

Hey there,

just starting out with my dev board, USB Audio, and have been playing with the limited hardware that I have available to interact with. That's two switches and two LEDs.

My first hack was to get up and running with a saturating counter using the buttons to inc/dec a count value. I didn't bother with debouncing first and as expected I got multiple samples for each button press.

Then, instead of using a timer to wait the specified debounce period, I thought I'd try just waiting to sample a '1' again. This seems to work for this example which is what I don't understand. Perhaps these switches have a short bounce period but I was expecting to still get multiple samples?

What's your thinking?

Code: Select all

	/* Test for button pushes */
	while(1) {
		select {
			case p_buttonA when pinseq(0) :> void:
				p_buttonA when pinseq(1) :> void;
				if(count < 3)
					count++;
				break;
			case p_buttonB when pinseq(0) :> void:
				p_buttonB when pinseq(1) :> void;
				if(count > 0)
					count--;
				break;
		}
Thanks.
User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am

Postby paul » Wed Feb 03, 2010 1:24 pm

Long shot here, but it may be to do with the time it takes to setup the pinseq statement. Its a few instructions, so that my be enough time for it to settle.

For button debounce I would usually want to insert delay between the two pinseq statements of a reasonable time to let the switch settle down.
Paul

On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

Who is online

Users browsing this forum: No registered users and 0 guests