Debouncing (and air capacitance?) problem!
D34DF007
Posts: 4
So for part of a project I am working on, I am trying to get the basic stamp to output a 750 Hz tone whenever a pushbutton is pressed.
The button (RS# 275-1556) is hooked up to pin 14, there is an indicator lamp wired to pin 15, and a speaker hooked up to pin 13.
What happens is that when the circuit is turned on (I have a SPDT switch that turns on the basic stamp), then tone instantly is emitted. If I hit the push button, it will stop. After that the button will work the way it is supposed to for a few seconds, then the circuit starts randomly beeping on its own spuriously. Doing things like waving my hand over the switch wire, or touching the plastic on the breadboard is enough to make it stop, or make it start at this point, and eventually it gets to where no matter what I do, it just constantly emits tone until I shut off the stamp. I've tried putting a .01uF capacitor in line with the switch to smooth out the noise, and have adjusted the sensitivity of the debounce, cut the length of the switch leads, etc. and nothing is fixing the problem.
Again, Im using a RadioShack SPST, Normally-Open push button. Here is the code that I am using with it. If anyone can tell me what the problem is, I would be so very thankful!:
' MORSEBUTTON.BS2
DO
HIGH 15
FREQOUT 13, 50, 450
Btn PIN 14
btnWrk VAR Byte
Main:
PAUSE 5
BUTTON Btn, 0, 0, 10, btnWrk, 0, No_Press
DEBUG "*"
LOOP
No_Press:
GOTO Main
The button (RS# 275-1556) is hooked up to pin 14, there is an indicator lamp wired to pin 15, and a speaker hooked up to pin 13.
What happens is that when the circuit is turned on (I have a SPDT switch that turns on the basic stamp), then tone instantly is emitted. If I hit the push button, it will stop. After that the button will work the way it is supposed to for a few seconds, then the circuit starts randomly beeping on its own spuriously. Doing things like waving my hand over the switch wire, or touching the plastic on the breadboard is enough to make it stop, or make it start at this point, and eventually it gets to where no matter what I do, it just constantly emits tone until I shut off the stamp. I've tried putting a .01uF capacitor in line with the switch to smooth out the noise, and have adjusted the sensitivity of the debounce, cut the length of the switch leads, etc. and nothing is fixing the problem.
Again, Im using a RadioShack SPST, Normally-Open push button. Here is the code that I am using with it. If anyone can tell me what the problem is, I would be so very thankful!:
' MORSEBUTTON.BS2
DO
HIGH 15
FREQOUT 13, 50, 450
Btn PIN 14
btnWrk VAR Byte
Main:
PAUSE 5
BUTTON Btn, 0, 0, 10, btnWrk, 0, No_Press
DEBUG "*"
LOOP
No_Press:
GOTO Main
Comments
There's a 5 ms pause and the BUTTON statement is executed. Assuming that the button isn't pressed, you should see a "*" on the debug window, then the whole process will start over again (DO / LOOP).
You didn't say how the pushbutton is hooked up. From the behavior you mentioned with the hand waving, etc., you probably don't have a pullup or pulldown resistor for the switch. You need to follow the examples in the "What's a Microcontroller?" tutorial or those shown in the Stamp Manual section on the BUTTON statement.