Jump to content

I have a SPST switch that I need to send a pulse when it 's turned on and off


G+_Wolf 68k
 Share

Recommended Posts

I have a SPST switch that I need to send a pulse when it's turned on and off. The pulse needs to mimic a keyboard press.

The only methods I've found so far either use a DPDT switch or an Arduino, both are not possible in this case. After that was a method that used an IC chip but only sent the pulse when the switch is closed, and it was a pretty big set up, plus it wasn't explained all too well.

Link to comment
Share on other sites

I barely know how to solder, which is part of what I'll be learning as I do this project, so I have no idea.

I think I know part of it, put a resistor and capacitor in line between the positive lead to the switch? Yes? In which order I'm not sure of and which way to face the capacitor I have no idea. But that would solve the closed part of the switch.

I guess I just don't see how you can send another pulse again going from a close state to an open state.

Link to comment
Share on other sites

Ok so the capacitor goes on the open side of the switch? Like this maybe? imgur.com - Imgur: The magic of the Internet It's only thing I can think of. I might have gotten the open side of the resistor and capacitor order wrong. I used a website to do the circuit, I left the components the default just to get the basic idea. I figure I'll have to come up with what a good combination of resisters and capacitors I'll need.

This is going to end up being connected to a zero delay usb encoder, the kind used for MAME cabinets, but used for something else.

Another question is do I use one of those round capacitors, which if I'm not mistaken are polarized, or the disc capacitor which aren't polarized? Because of I use the round one, how do I know which way it should go?

Link to comment
Share on other sites

The issue with this circuit is the requirement of generating a pulse on - both - switch opening and closing. To generate a pulse on one switch operation or the other is straight forward; both edges is a little harder.

 

Consider the circuit shown: it works like this:

 

R2 and C1 form a time delay circuit. R1 is a pull-up resistor and is much smaller than R2. When SW1 is open, C1 charges through R1 and R2. When the switch is closed, C1 discharges through R2. The time constant of R2-C1 needs to be significantly longer than the bounce time of SW1.

 

U1 is a cmos quad XOR gate (4070B, for example). U1a buffers the output of the switch debounce network.

 

R3 and C2 form a second delay network. The values determine the width of the output pulse.

 

Assume the switch has been open for a long time. C1 and C2 are both charged to near Vcc (+5 vdc, in this case). Now the switch is closed. This causes the output of U1a, and thus the upper input of U1b, to go low. C2 is being discharged by R3, but for a short time, the lower input of U1b is still high. Because U1 is an XOR gate and its inputs are not equal, the output of U1b goes high. C2 eventually discharges enough and the lower input of U1b goes low. The U1b inputs now match, and U1b output goes back low. When Sw1 opens again, the process repeats, but inverted.

 

Thus, the output of U1a indicates whether SW1 is open (high) or closed (low). Each transition of SW1 generates a pulse at U1b's output.

 

For a start, I'd set R1 = 1 kohm, and R2 = R3 = 10 kohms. Then select C1 and C2 to set the debounce time and pulse width, respectively. A 'scope would be very handy for doing this empirically.

 

Of course, doing this on an Arduino or a Tiny would eliminate all resistors and capacitors, as their functions would be emulated in software [this would be a perfect app for a Tiny].

2204%20-%20Switch.jpg

Link to comment
Share on other sites

Glad to see that Telford Dorr read the question correctly. When I read it I knew I didn't have the spare time to give an answer. This is not some simple debounce situation, the OP specifically asks that a single pulse be generated on both an open and close of an SPST switch. AFAIK there is no way to do this with only passive components.

Link to comment
Share on other sites

I breadboarded the circuit below and tested it. Do the same.

 

R1 = 1 kohm

R2 = R3 = 10 kohm

C1 = 4.7 uf

C2 = 1 uf

U1 = 4030, 4070, or 74C86 (quad cmos XOR gates).

 

Notes:

1] For reference, an XOR gate produces a high output when the two inputs don't match (e.g., high and low, or low and high) and a low output when they do match (low and low or high and high).

 

2] The 74C86 is good to maybe 6 volts. The 4030 and 4070 will work past 12 volts.

 

3] 4000 series cmos is not pin compatible with 74C series cmos. Google the part numbers for pinout info.

 

4] Cmos gates have a very high input impedance, thus they do not load down any driving RC networks

 

5] Bypass the power pin on U1 with both a 22 uf and a 100 nf capacitor to the ground pin, to eliminate any output oscillations caused by power fluctuations (generally good practice anyhow...) The 100 nf capacitor picks up where the internal inductance of the 22 uf capacitor forces it to quit acting like a capacitor as the applied frequency increases.

 

6] With the parts values specified, you should get roughly a 7 msec pulse at U1b output every time the switch changes. U1a output will indicate the switch position.

 

Experiment from there.

 

2207%20-%20Switch.jpg

Link to comment
Share on other sites

Wolf 68k will this switch and pulses be connected to a computer? If so, how? If via a USB port then you most likely will require a microcontroller, like Arduino, because USB keyboards send a series of data pulses to identify which key was pressed. To note they also send a series of data pulses when the key is released.

 

Why is it you can't use an Arduino?

Link to comment
Share on other sites

I'm using what is known as a Zero Delay USB Encoder, the type of controller board used for MAME cabinets. They come with a USB cable and usually some wires to connect the buttons. And it's a simple plug&play. So I can't just program it to do this. However after seeing how much of a pain in the rump this is getting to be I'm starting to wonder if it would be easier to use an Arduino Nano instead even though I have no idea how to do any of the programming for it but I'm sure there are some sketches out there already that I could use.

Link to comment
Share on other sites

 Share

×
×
  • Create New...