Tics Realtime -----


 
Home Services Products Tutorials Contact Us
- - - - -

Debouncing Techniques

Mechanical switches and moving mechanical parts in general do not simply stop when they reach their destination - they vibrate or "bounce" before coming to rest. Consider a mechanical on/off motor switch that is polled by software. If the software blindly turns the motor on when the switch is down, and off when the switch is up, the motor may be turned on and off multiple times before the switch finally comes to rest. Software must do more than check the position of the switch - it must determine when the switch has settled into position.

Maximum Delay Technique

A simple technique is to pause for "n" milliseconds once "switch down" is sensed, the value of "n" being such that it guarantees that the switch has settled after "n" milliseconds.
		if (switchDown()) {
			pause(1000L);
			motorOn();
		}

Transition Delay Technique

There are some applications where the above technique is unacceptable. Consider a semi-conductor IC machine that uses a chute to move parts from one station to another; that is, parts slide down the chute due to gravity, and can be made to stop at certain positions on the chute by a solenoid controlled post. When the post is up the part (an IC package) will hit the post, bounce back and forth a few times, and finally come to rest at the post. Once at the post the part is stamped with a part number, the post is brought down, and the part slides to the next station, where for example the ink is cured by heating, and so forth. This type of environment requires as much throughput as possible, and so, the maximum delay technique is unacceptable. Furthermore, different runs of parts can be constructed of different materials (plastic, ceramic, etc.) and their bounce characteristics will differ. Therefore, we not only need a faster technique, but an adaptive one as well.

The transition delay technique waits for the bounces to stop. In our example, this is done by installing a sensor that looks across the chute and can therefore sense when the part is at the post and when it is not.

void stampPartTask(void)
{
	while (TRUE) {
		if (partIsAtPost()) {
			while (TRUE) {
				pause(50L);
				if (partIsAtPost()) {
					stampAndReleasePart();
					break;
				}
				else break;
			}
		}
		yield();
	}
}
The code polls the sensor for the presence of a part at the post. When a part is found at the post, a delay of 50 ms or so is required for the part to bounce back out of the sensor's view. Once the 50 ms has expired, the presence of the part is tested for again. If the part is out of the sensor's view, it has not come to rest, and the inner while loop is exited and the outer while loop takes over again, looking for the reentry of the part. This process continues until the part hits the post and is still at the post after 50 ms, at which time it is considered at rest, the part, is stamped, and the code waits for the entry of a new part.

Comments

The number of milliseconds to pause is determined empirically. A debugger is handy for the iterative process of trying different values.

Note also that it is assumed that when the task yields, that it will resume quickly, otherwise, the algorithm may not work properly. (Please email us if you would like a detailed explanation).


We welcome comments. Let us know what subjects you would like written up. Send comments to Mike@TicsRealtime.com

Copyright © 2000, Tics Realtime