Understanding Electricity, Electronics, and Digital Circuits -- In Ten Minutes
By Steve Rose
Want to learn how to filet a watermelon? Interested in Digital Video or Video on Demand? Need to know how to troubleshoot a dead motherboard? Click http://steverose.com for more articles...
Wednesday, October 23, 2002Understanding Electricity
If you can picture the way water flows, you can understand electricity, and even electronics. Electrons flow following just about identical rules.
First, voltage is the same as pressure. Another term for voltage is Electro Motive Force, or EMF – the push behind the electrons. The word volt was applied to EMF to honor Volta, an early Italian experimenter. However, volts are identical in concept to water pressure, for example, in pounds per square inch.
Second, amperage is the same as the rate of flow. One ampere is a specific number (10^19) of electrons flowing past a point in one second. Ampere was a French guy whose name was applied to the rate of flow of electricity to honor him. However, amps are identical in concept to the measure of the rate of flow of water, for example, in gallons per hour. Another term applied to amperage is current – sort of tells the whole story.
The amount of energy you can derive from electricity or water is directly proportional to both the pressure and the rate of flow. A small child moving fast can knock you down just as easily as a big guy moving slowly. A small stream of water (low rate of flow) under high pressure can turn a water wheel just as well as a lot of water from a river moving slowly (low pressure, high rate of flow). Energy =Rate of Flow * Pressure. If the pressure is 1 and the rate of flow is 10, the result is the same as when the pressure is 10 and the rate of flow is 1. In electricity, the energy is measured in Watts (named to honor an Englishman), and is equal to Volts * Amps. There is no implication that an Italian times a Frenchman equals an Englishman.
Whenever water flows through a pipe, there is resistance to its flow (friction with the walls of the pipe, for one thing). Think about drinking a milkshake through a straw. Whenever electricity flows through a wire, there is resistance to its flow (disregarding “superconductors” for the moment). Some of the energy pushing the electricity through the wire must be spent to overcome the resistance. With water, the amount flowing into one end of the pipe is equal to the amount flowing out the other end. The same is true of electricity – the same number of electrons flow into one end of a wire as flow out at the other. Amps in = amps out. So the energy used to overcome the resistance results in a lowering of the pressure at the output. The voltage at the input is higher than the voltage at the output, and there is a voltage drop from one end of the wire to the other. What is resistance? Fundamentally, it is friction, and the energy spent to overcome the resistance is expressed as heat, just like the effect of rubbing your palms together (the ones on your hands – do not try this with your electronic organizers). Resistance is measured in Ohms, named after a German guy.
Picture it this way: You are drinking your milkshake through a straw. A friend gives you a second straw. If you put it beside the first straw and use them together, it is twice as easy to drink the shake (you have reduced the resistance to half of what it was). If you are a little strange, and put the straws end to end, it gets twice as hard to drink the shake because you have doubled the resistance. You have to apply twice the negative pressure (words carefully chosen) to overcome twice the pressure loss as the shake flows through the straws.
What's The Formula? What's A Formula?
You know by common sense and life experience, if a door is sticky, you have to push harder to close it. If a wheel has a bad bearing, you have to push it harder to make it turn. In general, when resistance goes up, you have to push harder to get the same result. For a given resistance, the harder you push, the bigger the result. For a given amount of resistance, the less you push, the smaller the result. You could make a formula out of this:
push = result
resistance
This formula expresses in shorthand what we just said: For a given resistance, the greater the push, the greater the result. (When push increases, the result increases in a proportionate way, and is therefore said to be directly proportional.) For a given push, the greater the resistance, the smaller the result. (When resistance increases, the result decreases in a proportionate way, and is therefore said to be inversely proportional.) A formula is just a concise way to represent a concept -- don't let it put you off.
With electricity, for a given voltage difference (push), the greater the resistance, the less the amperage (rate of flow). They are inversely proportional. For a given resistance, the greater the voltage, the greater the amperage. They are directly proportional. The formula that expresses this relationship is called Ohm’s law: A one volt difference in voltage across a one ohm resistor causes a current of one ampere to flow through the resistor. How the heck could this coincidence happen? Easy -- the units were chosen to make it happen. No point in making life more difficult! So here it is:
(E/R) = I (E is pressure or voltage, I is rate of flow or amperage, R is resistance)
Why do we use letters or other symbols in an equation? Easy: We know the relationships, but we don't know the values until we get to a specific case. A formula expresses the relationships, and gives us a general purpose tool so that we will know what to do when a specific case comes up. What does "R" mean? It stands for any resistance. By the same token, E stands for any voltage, and I for any amperage. However, when we have a specific case, we have to come up with the actual numbers for two of those values to be able to use the formula to calculate the third. By the way, don't let Algebra ever get in your face -- it is the same concept. Use letters for values you don't know right now, and that might have any value in an actual case (called variables). They are just placeholders so that you can get to what really matters, and is most general: The relationship between the variables. When you write a computer program, you will use lots of variables, so the program will work in any circumstance. For example, if you are writing a program which makes a receipt, you don't know in advance what is going to be purchased, so you might use the variable X as a placeholder to represent the cost of an item. When a purchase is made, X is replaced by the actual value for that purchase. When the next purchase is made, X is replaced with a new value for the current purchase. The program describes the general case, and in its operation specific values are substituted.
Let's play with this a little. Notice that if R remains the same, that if E gets larger I gets larger (they are directly proportional). If E is constant, then if R gets larger I gets smaller (they are inversely proportional). The formula may be rewritten by simple manipulation into forms that suit the problem you are trying to solve. For example, if you know the current and the resistance, and want to calculate the change in voltage between the input and output, you might want to multiply both sides of the equation by R and reverse the terms. What does "multiply both sides by R" mean? Well, remember that anything divided by itself is 1, 1 times anything is itself, multiplying or dividing both sides of an equation by the same value doesn't change the result of the equation, and the equals sign works both ways. So,
(E/R)=I ;Starting equation, "Ohm's Law"
R/R=1 ;Anything divided by itself equals 1
R=R ;Anything equals itself
R*(E/R)=I*R ;Multiplying both sides of an equation by the same value doesn't change the result
R*(E/R) = (R/R)*E = 1*E = E ;Looking at the left side of the equation, the R's "cancel", or
R * E = R * E = 1 * E = E
R R
E=I*R ; The change in voltage equals the current times the resistance.
By the same token,
E/R=I ;Divide both sides by E:
1/R=I/E ;Invert both sides:
R=E/I
So now we have the three forms of Ohms Law, which will allow us to solve any case where we know two of the variables:
I=E/R R=E/I E=I*R
Notice that, no matter how we manipulate the equation, the inverse and direct relationships remain the same. The equations are equivalent.
What About Electronics?
Now we get to the fun part. Think of a perfect water turbine with a flywheel attached to it. No water can pass unless the turbine is turning. For those so inclined, think of a car’s water pump (a new, improved version) with a wheel and tire attached to its shaft. The wheel is not turning, and we apply water pressure to the left inlet of the turbine. At first, the flow of water is blocked by the inertia of the wheel, but slowly the wheel begins to turn (extracting most of the energy from the water as it gets underway). Eventually, the wheel is turning at a rate that lets all of the water through, and it takes no further energy. Now we remove the pressure from the inlet. The energy which we have stored in the spinning wheel now turns our turbine into a pump, and tries to keep the water flowing through it in the same direction until all of its energy is spent. Got it?
Think of a pipe with a swelling containing an elastic diaphragm. When we apply pressure to the left inlet, water immediately comes out of the other side because in that first instant, the diaphragm offers no resistance to the flow. After a moment, though, it begins to stretch, and starts to push back against the pressure we have applied. Eventually, the diaphragm stretches to the point that it is pushing back with exactly the same force that we are applying, and the flow of water stops. We have stored energy in the stretched diaphragm. When we release the pressure, water is pushed back out (moving in the opposite direction) by the stored energy in the diaphragm until the diaphragm is once again flat and at rest. OK?
Let’s now hook them together in a closed loop, and give the wheel a spin (supplying the initial energy to the system). As the wheel turns, it pushes water through the turbine and the diaphragm stretches. The energy is being transferred from the wheel to the diaphragm. When all of the energy has been transferred, the wheel stops, but the diaphragm is stretched. The diaphragm pushes the water back the other way, and the wheel slowly begins to turn in the opposite direction. Eventually, the diaphragm gives up all of its energy, and it is flat – but the wheel is turning, having had the energy passed back to it. So now, the wheel uses its stored energy to keep the water moving in this new direction – causing the diaphragm to begin to stretch in the opposite direction. And so it goes, back and forth, until the resistance in the system (friction of the bearings, pipe walls, etc.) converts the stored energy to heat. If we supply just enough energy to balance the resistance (by giving the wheel a little spin on each cycle, for example), the system will keep oscillating at a rate (frequency) determined by the weight of the wheel and the size of the diaphragm. The heavier the wheel, the slower the rate, and the larger the diaphragm, the slower the rate.
Here is the key: The turbine is conceptually the same as a coil of wire (an inductor), and the diaphragm is conceptually the same as a capacitor. The combination of the two in a closed loop is a “tuned circuit” whose frequency is determined by the physical characteristics of the components, and it works in exactly the same way as the circuitry used to control the frequency of a radio station, or used inside your radio to select one station from another.
An inductor stores energy in a magnetic field surrounding it. Whenever a magnetic field moves past a wire, it induces an electrical current in the wire. When electricity begins to flow in a coil, the magnetic field that starts to grow moves past the wires of the coil in such a way as to induce a voltage that opposes the flow of the electricity in the coil that is creating the magnetic field! This “back EMF” has the same effect as the inertia of the flywheel. As the flow of electricity in the coil reaches a steady state, the magnetic field stops growing, so there is no further back EMF to oppose the flow of electricity. However, when the flow stops, the magnetic field collapses, moves the opposite way past the wires of the coil, and induces a voltage that tries to keep current flowing through the coil in the same direction – just like the momentum of the wheel tries to keep water flowing through the turbine in the same direction.
A capacitor stores energy as a charge between two conductive “:plates” (typically aluminum foil) separated by an insulator. The insulator may vary from a vacuum to waxed paper to a pasty electrolyte, giving capacitors of different characteristics. But they all store a charge in a way that is conceptually the same as the diaphragm. We generally think of water as flowing steadily in one direction, much like direct current electricity. But if you think of the water in the pipes of our tuned circuit, it is moving back and forth, just like alternating current electricity (AC). A capacitor in series with an electrical circuit allows alternating current to pass through, because the “diaphragm” is just stretching back and forth (the charge is flowing on and off the plates). The slower the oscillation, the larger the diaphragm (value of the capacitor) has to be to keep it from stretching to its limit during each cycle. A capacitor will not allow a direct current to pass. After enough current has passed to “stretch the diaphragm” to the point that it is pushing back with equal pressure, the flow of electricity stops as surely as someone turning off a switch. One common use of a capacitor is to block the flow of direct current, while allowing an alternating current signal to pass. A small value capacitor will block the flow of low frequency AC, such as from the power line, while allowing high frequencies (such as cable signals) to pass.
Interestingly, if a high value capacitor is placed in parallel with a direct current circuit, it acts as a storage device to even out variations in voltage in that circuit. During voltage spikes, the diaphragm stretches, and during dips in the voltage in the circuit, the diaphragm releases its stored energy, smoothing out the variations. Large electrolytic capacitors are used for this purpose in power supplies.
In the opposite fashion, an inductor allows a direct current to flow, but blocks an alternating current. After a DC flow begins, and the steady magnetic field has been created, there is no further opposition to the flow of electricity. However, an alternating current is trying to spin the wheel in one direction, then the other, and the inertia of the wheel stops the flow. A larger coil is needed to block lower frequencies, just as a larger capacitor is needed to let them pass.
Resistors are devices which have more resistance than wire (from a resistance resembling wire, a fraction of an ohm, to almost being an open circuit – millions of ohms). Resistors are used when a voltage drop is required, or to limit the maximum amperage from a circuit, or to isolate one part of a circuit from another, or to translate a changing rate of flow to a corresponding changing voltage drop (for example, in an amplifier). And for other stuff.
Now you know about capacitors, coils, and resistors. What about transistors? They are valves! In fact, inEngland, vacuum tubes are called valves. By using just a little force to turn the handle of a valve, you can control a stream of water that is so powerful you cannot stop it with your hand. It took just a slight fingertip effort to control the valve. In the same way, a transistor has a gozinta, a comzouta, and a control element. Power from the power supply is connected to the gozinta, and what comes out of the comzouta is proportional to the signal applied to the control element. It means that you can take the very tiny signal that comes out of a microphone, apply it to the control element, and control such a large flow of electricity with just a few stages of transistor amplification that you can run speakers at earsplitting volume. It doesn’t matter what type of transistor you are talking about – bipolar, FET, MOSFET, or even a vacuum tube – they all work in a remarkably similar way, with differing labels for the gozinta, comzouta, and control element.
Digital Circuits
Digital circuits are all built from a very small kit of parts, which are logic gates. As a matter of fact, in designing digital circuits, the more gates you have to work with, the better. This is the opposite of software, where one Gates is too many. The fundamental hardware gates are inverters, AND gates, OR gates, and exclusive or gates, or XOR gates. An inverter has an output that is always opposite of its input. If the input is on, the output is off. If the input is off, the output is on. You can think of off as 0, and on as 1.
An AND gate works like two (or more) light switches that are wired in series. The light will only come on if both switches are on. If either or both switches are off, the light is off. An OR gate works like two (or more) light switches wired in parallel. If either switch is on, the light is on. You have to turn off both switches for the light to go out.
An XOR gate is like a two way switch, where you have a switch at each end of a long hallway. If both switches are down, the light is off. If we flip the switch at one end to the up position, the light comes on (regardless of from which end of the hallway we start). When we get to the other end of the hall, we flip the switch on that end to the up position (both switches are now up), and the light goes out. So, if either switch is up (we’ll say “on”), the light is on. If both switches are down (off), the light is off. But if both switches are up (on), the light is off.
In other words:
INVERTER: If the Input is On, the Output is Off, and visa versa.
Input
Output
0
1
1
0
OR Gate: If any input is On, the output is On. Only if all inputs are Off is the output Off:
Input 1
Input 2
Output
0
0
0
0
1
1
1
0
1
1
1
1
AND Gate: If all inputs are On, the output is On, otherwise the output is Off:
Input 1
Input 2
Output
0
0
0
0
1
0
1
0
0
1
1
1
XOR Gate: If one input is On, and the other Off, the output is On. If both inputs are On or both are Off, the output is Off:
Input 1
Input 2
Output
0
0
0
0
1
1
1
0
1
1
1
0
There are all kinds of combinations that yield new gates that are commonly used. For example, if you put an inverter on the output of an AND gate, you end up with an inverted AND gate, or a NOT AND gate, abbreviated NAND. Interestingly, just like we played with the algebraic formula for Ohm’s law and found it could be expressed in several ways that were really identical, so it is with gates. A NAND gate is identical to an OR gate with an inverter on each input. A NOT OR gate (inverter on the output), or NOR gate, is equivalent to an AND gate with an inverter on each input. There are others. However, if you can just picture the INVERTER (or NOT), AND, OR, and NOR gates, you can understand digital circuits (or NOT).
For example, what if we want to remember that something has happened in a circuit? There is no memory in any of the gates we have discussed. Well, take two two input NOR gates, and connect the output of each to one of the inputs of its companion. By momentarily changing one of the unconnected inputs from a 0 to a 1, it forces the output of its OR gate to be 1, and the output of its inverter to be 0. This causes both inputs of the other gate to be 0, causing its output to be 0, causing the inverter output to be 1, which forces the other gate to remain in its new state even when we change the other input back to 0. There is a feedback loop between the two gates that forces the pair to be able to remember the last input forever (until the next rolling blackout). We have taken a pair of gates, and added memory to our bag of tricks. This circuit, of which there are many variations, is called a flip-flop, named in honor of the rubber slipper.
Correcting Errors Digitally
Just one more example. Sometimes you have to transmit or store data in an unreliable environment, where information may be lost due to interference or equipment failure. How do you protect yourself? Enter the XOR gate, and simple forward error correction. Lets take the case where we have to transmit pairs of bits. By adding a third bit, and some XOR magic, we can reconstruct missing information. The first two columns are the information we need to transmit, and the third is the exclusive or result we’ll transmit along with the data:
0
0
0
1
0
1
0
1
1
0
0
0
1
1
0
Now lets say we lose some bits:
00
0
1
0
10
11
0
00
11
0
Now, lets apply the XOR function to the remaining bits:
0
0
0
1
0
1
0
1
1
0
0
0
1
0
1
The bits are shown separately here for illustration. In reality, the recalculated bits would resume their old position in the data. And guess what? By using the XOR function on the flawed data, but which had the “forward error correction” overhead in it, we have restored the original data without having to ask for a retransmission! This example is very oversimplified (for example, we would be stymied by two errors in the same row), but the concept is there, and actual implementations are just extensions of this concept.