While idly mulling over how one might create a control panel for an eight-bit microcomputer – something I plan to do for my (very) slowly progressing Zolatron 64 project – it occurred to me that there might be occasions when it would be useful to send a brief pulse.
I didn’t have a specific use case in mind. In fact, it’s not generally needed. Let’s say, for example, that you want to send a single clock pulse because you’re single-stepping through a program. Generally, a momentary switch is fine for this because the system will be configured to act just on the rising edge. Providing the switch is fully debounced, then all is well.
With a momentary switch, though, the signal will stay high for as long as you hold it. This might be a good thing (maybe you also need the falling edge to do stuff and want a reasonably long period when the signal is high). Maybe it’s a bad thing (can’t think of an example). And most likely it simply doesn’t matter.
But I couldn’t get out of my head the idea that a very brief pulse might come in handy one day. The signal goes high when you press the switch, but then drops back again very quickly even if you’re holding down the button.
Then I just happened to re-watch a video by Ben Eater. If you haven’t seen Ben’s videos on things like latches, flip-flops and building a breadboard computer you should rush over to his channel on YouTube the moment you finish reading this post. He is very skilful in explaining key electronics concepts.
In the following video on the D flip-flop, he talks about how you might create an ‘edge detector’ that produces a short pulse only on the rising edge of a clock signal.
The way Ben explains it, it’s easy to understand. The first method he mentions is by using an inverter and an AND gate, and it works like this:
- You take the clock signal and connect it to an inverter and one input for the AND gate.
- You connect the output of the inverter to the other input of the AND gate.
- When the clock is low (0) the inputs to the AND gate will be 0 (direct from the clock signal) and 1 (via the inverter). So the output of the AND gate is 0.
- When the clock signal goes high, the direct input to the AND switches from 0 to 1. The input that goes via the inverter switches from 1 to 0. So the output of the AND will be 0.
- However, the change in the output of the inverter takes a finite amount of time to go from 1 to 0. So, just for a fleeting moment, the output of the inverter is still 1 at the same time that the direct input is also 1. This means the output from the AND gate will be 1 for as long as it takes the inverter to get its act together. This is your pulse.
- The output of the AND is now 0. So when the clock drops to 0, the direct input is 0, the output of the inverter is fleetingly 0 before switching to 1. All of these states mean that the AND will continue to output a 0, so nothing happens on a falling edge.
In the video, Ben doesn’t actually build this circuit – he leaves it as an exercise for the viewer. So, with half-and-hour to kill last night I thought, hell yes, I’ll do that.
My inverter of choice was a 74HC14N Schmitt trigger inverter – in retrospect not the best choice, as we’ll see, but it was what came most immediately to hand. (Okay, I confess, it was already plugged into the breadboard.)
The AND gate was a CD4081BE – functionally equivalent to the 74xx08 quad AND gate chip. It was the only AND gate chip I had.
I hooked up an ordinary tactile switch to the 5V supply on the breadboard. The output of the switch was pulled low with a 10KΩ resistor. This output also went to the input of one of the six inverters on the 74HC14N and also to one input of an AND gate on the CD4081BE. The output of the inverter went to the other input on the AND gate. Finally, I connected an oscilloscope probe to the output of the AND gate.
I powered on, set the scope to single shot and pressed the button.
To be fair, Ben Eater did mention that one might have to pass the input signal through several inverters in order to get enough of a delay. So I wired up the 74HC14N chip so that the signal passed through three inverters (using an odd number to ensure the signal was still inverted).
I pressed the button multiple times until, finally, I got a pulse. And what a brief pulse it was.
The time between the pulse starting and it reaching 3V was 27ns. (The 3V level is the somewhat arbitrary figure I decided on for ‘high’; I chose 0.8V for ‘low’. The actual figures that would be significant in a circuit would depend on the components you’re using.)
The time between it reaching the 3V level and dropping back down to 0.8V was 91ns.
However, to get a pulse at all took around 20 presses of the button, and in all my messing about I only managed to produce two pulses.
One reason for this may have been my poor choice of inverter. I used an ‘HC’ version of the chip – high-speed CMOS. And this is a chip we’re trying to use to slow down the signal. Oops. Alas, I didn’t have any slower inverters on hand, so I leave trying this with more modest inverters as an exercise for the reader…
In any case, there’s a better way of doing this, as Ben mentions in the video. And it’s the good old RC (resistor-capacitor) circuit.
When the switch is open, there’s no current flowing to the capacitor, which has discharged through the resistor to GND. The probe point is also pulled low to GND via the resistor. Therefore the signal at the scope probe is 0. When you push the button, the capacitor starts charging. As we know, capacitors block DC current, but only when charged. At the moment of pushing the button, current flows through the capacitor to the probe. As the capacitor charges, this voltage declines. When the capacitor is fully charged, no more DC current flows through it and the probe point is once again pulled low via the resistor. When you release the button, the capacitor discharges through the resistor.
I used whatever I had lying around on the breadboard, which happened to be a 10KΩ resistor and a 0.1µF capacitor. They produced the pulse above. As you can see, the rise time is effectively instant, so the time to get from 0V to, say, 3V isn’t all that relevant. The important thing is the time taken to decay back down to the low setting (here we’re using 0.8V). In this case it was 1.76ms.
In theory, you can calculate the pulse time in seconds by simply multiplying the resistor value by the capacitor value, after having converted to standard units – ie, Ohms and Farads. In this case, that would give us 0.0000001F x 10,000Ω = 1ms.
Why is this different to what we got above? Because this calculation gives us the time constant for the RC circuit, and this relates to the time taken for a capacitor to go from a zero charge to around 62% of its full charge.
I replaced the 10KΩ resistor with a 1KΩ one and got this.
As you would expect, the result here is 176µs when measuring from initial pulse to the 0.8V level – exactly a tenth of the previous result. (The horizontal scale on the scope has changed.)
And just for fun, I tried it with a 330pF cap, and this gave a pulse of 5.8µs (compared to a theoretical time constant of 33µs).
One thing to note is that these pulses are entirely independent of how long you hold down the button. And there was no problem with switch bounce. The time periods are so short anyway, and this process occurs on the first contact made. Any subsequent bounce isn’t going to have much, if any, effect.
So, I now know how to generate a pulse. Now I just have to think of something to do with it.
Following Richard’s comment below about using a Schmitt inverter, I thought ‘that sounds like a good idea’. So here’s the pulse, using a 0.1µF capacitor and 10KΩ resistor fed via a 74HC14 Schmitt inverter.
Two things are immediately obvious – first, it’s inverted (duh); and second, the end of the pulse is now as sharply defined as the start thanks to the hysteresis of the Schmitt trigger. So let’s measure our pulse duration.
That’s 940µs – let’s call it a millisecond. If we replace the 10KΩ resistor with a 1K one, we’ll get a pulse one tenth as long – 94µs. And if you want a positive-going pulse, then you can feed the signal through a second inverter on the 74HC14 (it has six).
Now, as I had my container of inverters on the bench, I thought I’d drop in a 74HC04. This is just a regular old inverter with no Schmittiness. And this is what I got.