Octal DIP Switch Digital ‘0’

digital-logicdipswitches

I've been playing around with logic gates and RAM chips and stuff the past week or so, but I can't figure out how to get a DIP switch to represent a digital '0' while still being able to represent '1' when turned on. Having no current running through doesn't work, and the switch only has one input for each bit. How would I do this?

Best Answer

You are right, you need something more than a simple single pole single throw switch to make a digital logic signal. Usually that something is a pullup resistor. The resistor goes between the power supply and the logic line, and the switch between ground and the logic line. When the switch is closed, it hard-shorts the line to ground. When the switch is open, the pullup resistor provides a weaker drive to power.

The tradeoff is that you want the pullup stiff enough (low enough resistance) so that it can overcome any current that other parts on the digital line might be leaking to ground. It has to be weak enough (high enough value), so that the current is limited to a reasonable value when the switch is closed.

Most CMOS logic gate inputs leak little enough that a few 100 kΩ to power is enough to guarantee the voltage will be interpreted as a logic high level. However, you don't want the line to pick up stray noise and of course you want some margin. If in doubt, use a 10 kΩ pullup.

This same concept works flipped around too. You can use a pulldown resistor and put the switch between power and the logic line. For various reasons, switches, whether mechanical or transistors, are usually connected to ground, and therefore pullups are more common than pulldowns.