Shop OBEX P1 Docs P2 Docs Learn Events
Debouncing (and air capacitance?) problem! — Parallax Forums

Debouncing (and air capacitance?) problem!

D34DF007D34DF007 Posts: 4
edited 2011-01-05 22:16 in BASIC Stamp
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

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-01-05 14:51
    Do you have a pullup resistor from the switch p14 to +5 Volts, as in the Stamp manual, page 139 figure 5.1?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-05 14:57
    The program is doing what it's written to do. Initially, pin 15 is made high hopefully making indicator light and the speaker will emit a tone (FREQOUT).

    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.
  • D34DF007D34DF007 Posts: 4
    edited 2011-01-05 22:16
    I figured out a solution. By having the switch control a transistor, I was able to eliminate alot of the noise. I think the problem was in the construction of the switch. However the hardware in the switch is configured, even the slightest bump, nudge, or change in temperature causes it to output alot of noise. I'm guessing this is because it wasn't meant to be used in logic applications such as with a basic stamp. The transistor ignores 95% of that noise though, and outputs a clean tone only when I high the button fully.
Sign In or Register to comment.