Input, In General

In order to be useful, a controller, such as a BASIC Stamp, must control things. In computer jargon, it is said that the computer has outputs.

In some cases, the controller is just telling the world what to do, and does not care what may be going on in the world. But most of the time, the controller wants to check on a condition - peeking at the condition of the outside world - before doing something. In computer jargon, it is said that the computer has inputs.

This page discusses various aspects of input interfacing - transforming the real world data into a clean digital signal.

Before you read this section, please:

skip list of on-page links

True, False, And Uncertain

When you take an analog input voltage and try to turn it into a logical true or false, you must decide what voltage corresponds to what logical value.

If your CPU runs on 5 Volts, it is easy to declare that 5 Volts is a logical true and 0 Volts is a logical false. But what about voltages in between?

This is usually handled by defining a range of voltages that correspond to logical true and a range that correspond to logical false. Anything in between those ranges could be interpreted either way. I like the term "uncertain", but the chip specifications usually call it "undefined".

Inside the digital part of the computer, you can't have anything other than true and false, so the voltage turns into logic somewhere. But, in practice, every chip will have its own threshold where it defines what is a true and false. This is partly due to manufacturing tolerance. In fact, a chip may have a different threshold when a voltage is rising than when it is falling.

The uncertainty zone allows for communication between chips with different levels. Because even if they can't agree precisely where to switch, there are pre-agreed levels that are certain. So, to make sure that all of the chips agree with each other, signals between chips should rapidly make the transition from low to high, spending as little time as possible in uncertainty.

Hysteresis And Schmitt Trigger

When you take an analog input voltage and try to turn it into a logical true or false, you must decide what voltage corresponds to what logical value. Let's sauppose that the uncertain zone is very small, to the point where your CPU pretty much defines half of its supply voltage as the cutoff point between false and true.

We will be safe if the input makes a rapid and smooth transition between states. But what if it is close to the threshold for a while, wobbling up and down with small fluctuations.

A Schmitt Trigger solves this problem by applying hysteresis: once a transition has been made from one level to another, a small transition in the reverse direction does not change the output. In order to change, you must go a certain distance back in order to change.

Pull Up, Pull Down

It is a bad idea to leave a controller input disconnected - just hanging in the air. At all times, it should be connected to either a logical 1 (+5 Volts) or a logical 0 (ground = 0 Volts). If you leave an input pin not connected ("floating"), it may read in as a 0, a 1, or just flap up and down in the breeze.

Simple electrical switches just open and close. If you hook a switch up to an input, and the switch is open, the input will float and can not be trusted. You have to find a way to make sure that you always present a solid 1 or 0.

A common way to impose a default input is with pull-up or pull-down resistors. These resistors can be used to shove a 0 ("pull-down" to ground) or a 1 ("pull up" to +5 volts) into input pins. The 0 or 1 provided by the resistor can be safely overpowered by the switch when it is activated.
When the switch is open, the pull-down resistor encounters no opposition and is able to pull the input down to ground.

When the switch is closed, the switch pulls strongly up, and the resistor pulls weakly down. The switch wins, and the controller sees a logical true on its input.

You should use the resistor that does the opposite of what your switch will do when activated:

Normally Open Switch

A "normally open" switch takes two wires and leaves them dangling in space ("open") most of the time. When you activate the switch, it connects the wires together, which completes the electrical circuit.

For positive logic, hook one end of the switch to the input, the other end of the switch to +5 Volts, and use a pull-down resistor.
A normally open switch, wired for positive logic.



Normally Closed Switch

A "normally closed" switch takes two wires and connects them together ("closed") most of the time, which completes the electrical circuit. When you activate the switch, it disconnects the wires, leaving them dangling in space ("open").

For positive logic, hook one end of the switch to the input, the other end of the switch to ground, and use a pull-up resistor.
A normally closed switch, wired for positive logic.



Related Pages

Skip this list.
You may be interested in these related pages:
privacy policy | write to us | tip us
©Copyright 2005-2006 by The Wolfstone Group. All rights reserved.
You must read and abide by our terms of service.