Debouncing The Old-Fashioned Way

If you were given the task of designing a computer at a time when computers weren’t really even a thing, how would you start? How would you take a collection of vacuum tubes, passive components, and a precious few germanium diodes and engineer something to sell to customers looking for an “electronic brain”?

Where there’s a paycheck, there’s a way, and computer archeologist [Ken Shirriff] laid his hands on some old IBM hardware that tells us a lot about how engineers thought in the earliest days of the computer industry. The gear is a pluggable module from IBM, one of hundreds that once went into their Model 705 computer from the mid-1950s. The particular module [Ken] has is a 5-channel contact debouncer, or in Big Blue’s mid-century parlance, a “Contact-Operated Trigger.” It was used to debounce five of the many, many mechanical contacts in the machine, both buttons and relays, and used eight dual triode tubes to do it. Other modules with the exact same footprint formed the flip-flops, inverters, buffers and clocks needed to build a computer.

[Ken]’s analysis of the debouncer is a fascinating look at what was possible with the technology of the day, and the fact that it led to a standardized framework for generic modules that were actually hot-swappable with what essentially was a zero insertion force plug was quite a feat of engineering. And as a bonus, [Ken] and friends actually got the module up in running in the video after the break.

Jonesing for more retro-computer pluggable goodness? Check out this reproduction IBM flip-flop module from the 1940s.

Continue reading “Debouncing The Old-Fashioned Way”

An Introduction To Solid State Relays

When we think of relays, we tend to think of those big mechanical things that make a satisfying ‘click’ when activated. As nice as they are for relay-based computers, there are times when you don’t want to deal with noise or the unreliability of moving parts. This is where solid-state relays (SSRs) are worth considering. They switch faster, silently, without bouncing or arcing, last longer, and don’t contain a big inductor.

Source Fotek SSR Specifications Sheet

An SSR consists of two or three standard components packed into a module (you can even build one yourself). The first component is an optocoupler which isolates your control circuit from the mains power that you are controlling. Second, a triac, silicon controlled rectifier, or MOSFET that switches the mains power using the output from the optocoupler. Finally, there is usually (but not always) a ‘zero-crossing detection circuit’. This causes the relay to wait until the current it is controlling reaches zero before shutting off. Most SSRs will similarly wait until the mains voltage crosses zero volts before switching on.

If a mechanical relay turns on or off near the peak voltage when supplying AC, there is a sudden drop or rise in current. If you have an inductive load such as an electric motor, this can cause a large transient voltage spike when you turn off the relay, as the magnetic field surrounding the inductive load collapses. Switching a relay during a peak in the mains voltage also causes an electric arc between the relay terminals, wearing them down and contributing to the mechanical failure of the relay.

Continue reading “An Introduction To Solid State Relays”

Mouse Mis-Clicking? We Got You.

A mouse with malfunctioning buttons can be a frustrating to deal with — and usually a short leap to percussive maintenance. Standard fixes may not always last due to inferior build quality of the components, or when the microswitch won’t close at all. But, for mice that double/triple-click, will release when dragging, or mis-click on release, this Arduino-based hack may be the good medicine you’re after.

Instructables user [themoreyouknow]’s method cancels click malfunctions by latching the mouse’s controller switch trace to ‘on’ when pressed, keeping it there until the button normally closed contact closes again completely. Due to the confined spaces, you’ll want to use the smallest Arduino you can find, some insulating tape to prevent any shorts, and care to prevent damaging the wires this process adds to the mouse when you cram it all back together.

Before you take [themoreyouknow]’s guide as dogma, the are a few caveats to this hack; they are quick to point out that this won’t work on mice that share two pins between three buttons — without doing it the extra hard way, and that this might be trickier on gaming or other high-end mice, so attempt at your own peril.

Speaking of gaming mice, we recently featured a way to add some extra functionality to your mouse — cheating optional — as well as how to stash a PC inside an old Logitech model.

Conflict Escalates Between Brilliant Rat And 555 Timer

After [Casey Connor] captured and relocated a number of unwanted rodents in his home using commercially available live traps, he was presented with a problem: a rat had learned to avoid them.

In an epic, and adorable, conflict caught on video (and embedded below),  he documents the  designs used and how the rat escaped them by either recognizing the trap, or sheer agility. We can only tip our hat to the determination of both parties.

All the trap mechanisms are based on a 555 monostable solenoid triggering circuit that ensures that a pulse of sufficient duration is sent to the solenoid to trigger the trap correctly. This way even intermittent contacts will trigger the trap rather than just causing the solenoid to twitch without fully actuating. This is the same technique used to debounce a switch using a 555 timer.

A Raspberry Pi Zero detects motion using an IR camera to film the interesting parts. This is also a good indicator for when you’ve trapped your quarry – if you’re trying be humane then leaving it in a trap for days is counterproductive.

With the time and effort we spend building better and more complex rodent traps, we sometimes wonder who has cleverly trapped whom.

Continue reading “Conflict Escalates Between Brilliant Rat And 555 Timer”

About Schmitt (Triggers)

There is an old saying: “In theory, theory and practice are the same. In practice, they are not.” We spend our time drawing on paper or a computer screen, perfect wires, ideal resistors, and flawless waveforms. Alas, the real world is not so kind. Components have all kinds of nasty parasitic effects and no signal looks like it does in the pages of a text book.

Consider the following problem. You have a sine wave input coming in that varies between 0 V and 5 V. You want to convert it to a square wave that is high when the sine wave is over 2.5 V. Simple, right? You could use a CMOS logic gate or a comparator. In theory…

The problem is, the sine wave isn’t perfect. And the other components will have little issues. If you’ve ever tried this in real life, you’ll find that when the sine wave is right at the 2.5 V mark the output will probably swing back and forth before it settles down. This is exacerbated by any noise or stretching in the sine wave. You will wind up with something like this:

scope1

Notice how the edges of the square wave are a bit fat? That’s the output switching rapidly back and forth right at the comparator’s threshold.

Hysteresis

The answer is to not set the threshold at 2.5 V, or any other single value. Instead, impose a range outside of which it will switch, switching low when it leaves the low end of the range, and high when it exceeds the high end.  That is, you want to introduce hysteresis. For example, if the 0 to 1 shift occurs at, say, 1.9 V and the 1 to 0 switch is at 0.5 V, you’ll get a clean signal because once a 0 to 1 transition happens at 1.9 V, it’ll take a lot of noise to flip it all the way back below 0.5 V.

You see the same effect in temperature controllers, for example. If you have a heater and a thermal probe, you can’t easily set a 100 degree set point by turning the heater off right away when you reach 100 and then back on again at 99.9999. You will usually use hysteresis in this case, too (if not something more sophisticated like a PID). You might turn the heater off at 99 degrees and back on again at 95 degrees, for example. Indeed, your thermostat at home is a prime example of a system with hysteresis — it has a dead-band of a few degrees so that it’s not constantly turning itself on and off.

Schmitt Triggers and How to Get One

A Schmitt Trigger is basically a comparator with hysteresis. Instead of comparing the incoming voltage with VCC / 2, as a simple comparator would, it incorporates a dead band to ensure that logic-level transitions occur only once even in the presence of a noisy input signal.

Schmitt Trigger Symbol by Selket CC-BY 2.5

Assuming you want a Schmitt trigger in a circuit, you have plenty of options. There are ICs like the 74HC14 that include six (inverting) Schmitt triggers. On a schematic, each gate is represented by one of the symbols to the right; the little mark in the box is the hysteresis curve, and the little bubble on the output indicates logical negation when it’s an inverter.

You can also make them yourself out of transistors or even a 555 chip. But the easiest way by far is to introduce some feedback into a plain op amp comparator circuit.

Below are two op amps, one with some positive feedback to make it act like a Schmitt trigger. The other is just a plain comparator. You can simulate the design online.

 

schem21-wide

If you haven’t analyzed many op amp circuits, this is a good one to try. First, imagine an op amp has the following characteristics:

  • The inputs are totally open.
  • The output will do whatever it takes to make the inputs voltages the same, up to the power supply rails.

Neither of these are totally true (theory vs. practice, again), but they are close enough.

The comparator on the right doesn’t load the inputs at all, because the input pins are open circuit, and the output swings to either 0 V or 5 V to try, unsuccessfully, to make the inputs match. It can’t change the inputs because there is no feedback, but it does make a fine comparator. The voltage divider on the + pin provides a reference voltage. Anything under that voltage will swing the output one way. Over the voltage will swing it the other way. If the voltages are exactly the same? That’s one reason you need hysteresis.

The comparator’s voltage divider sets the + pin to 1/2 the supply voltage (2.5 V). Look at the Schmitt trigger (on top). If the output goes between 0 V and 5 V, then the voltage divider winds up with either the top or bottom resistor in parallel with the 10K feedback resistor. That is, the feedback resistor will either be connected to 5 V or ground.

Of course, two 10K resistors in parallel will effectively be 5K. So the voltage divider will be either 5000/15000 (1/3) or 10000/15000 (2/3) depending on the state of the output. Given the 5 V input to the divider, the threshold will be 5/3 V (1.67 V) or 10/3 V (3.33 V). You can, of course, alter the thresholds by changing the resistor values appropriately.

Practical Applications

Schmitt triggers are used in many applications where a noisy signal requires squaring up. Noisy sensors, like an IR sensor for example, can benefit from a Schmitt trigger. In addition, the defined output for all voltage ranges makes it handy when you are trying to “read” a capacitor being charged and discharged. You can use that principle to make a Schmitt trigger into an oscillator or use it to debounce switches.

If you want to see a practical project that uses a 555-based Schmitt, check out this light sensor. The Schmitt trigger is just one tool used to fight the imprecision of the real world and real components. Indeed, they’re nearly essential any time you want to directly convert an analog signal into a one-bit, on-off digital representation.

An Intel 8085 Microprocessor Trainer

The Intel 8085 microprocessor was introduced 40 years back, and along with its contemporaries — the Z80 and the 6502 — is pretty much a dinosaur in terms of microprocessor history. But that doesn’t stop it from still being included in the syllabus for computer engineering students in many parts of the world. The reason why a 40 year old microprocessor is still covered in computer architecture text books instead of computer history is a bit convoluted. But there’s a whole industry that thrives on the requirements of college laboratories and students requiring “8085 Microprocessor Training Kits”. [TisteAndii] just finished college in Nigeria, where these kits are not locally built and need to be imported, usually costing well over a 100 dollars.

Which is why his final year project was a low cost Intel 8085 Microprocessor Trainer. It’s a minimalist design with some basic read/write memory, program execution and register inspection, with no provision for single stepping or interrupts yet. The monitor program isn’t loaded in an EEPROM. Instead, a PIC18 is used and connected to the 8085 address, data and control pins. This makes it easier to write a monitor program in C instead of assembly. And allows use of a 1.8″ LCD with SPI interface instead of the more usual 7-segment displays used for these kind of kits. [TisteAndii] built a 6×4 keyboard for input, but couldn’t solve debounce issues and finally settled on a 5×4 membrane keypad.

Being a rookie, he ended up with a major flaw in his board layout — he missed connecting the SRAM and the PPI devices to the data bus. A bunch of jumper links seemed to solve the issue, but it wasn’t perfect. This, and a few other problems gave him a lot of grief, but towards the end, it all worked, almost. Most importantly, his BoM cost of about $35 makes it significantly cheaper compared to the commercial units available in Nigeria.

While some hackers may consider this a trivial project, it solves a local problem and we hope the next iteration of the design improves the kit and makes it more accessible.

Encoders Spin Us Right Round

Rotary encoders are great devices. Monitoring just a few pins you can easily and quickly read in rotation and direction of a user input (as well as many other applications). But as with anything, there are caveats. I recently had the chance to dive into some of the benefits and drawbacks of rotary encoders and how to work with them.

I often work with students on different levels of electronic projects. One student project needed a rotary encoder. These come in mechanical and optical variants. In a way, they are very simple devices. In another way, they have some complex nuances. The target board was an ST Nucleo. This particular board has a small ARM processor and can use mbed environment for development and programming. The board itself can take Arduino daughter boards and have additional pins for ST morpho boards (whatever those are).

The mbed system is the ARM’s answer to Arduino. A web-based IDE lets you write C++ code with tons of support libraries. The board looks like a USB drive, so you download the program to this ersatz drive, and the board is programmed. I posted an intro to mbed awhile back with a similar board, so if you want a refresher on that, you might like to read that first.

Reading the Encoder

The encoder we had was on a little PCB that you get when you buy one of those Chinese Arduino 37 sensor kits. (By the way, if you are looking for documentation on those kinds of boards, look here.; in particular, this was a KY-040 module.) The board has power and ground pins, along with three pins. One of the pins is a switch closure to ground when you depress the shaft of the encoder. The other two encode the direction and speed of the shaft rotation. There are three pull-up resistors, one for each output.

I expected to explain how the device worked, and then assist in writing some code with a good example of having to debounce, use pin change interrupts, and obviously throw in some other arcane lore. Turns out that was wholly unnecessary. Well… sort of.

Continue reading “Encoders Spin Us Right Round”