This is an old revision of the document!


Pages 537-547

Digital Logic

At the end of this course, we'll delve a little into the realm of digital logic.  In practice, it is very unusual to work with individual chips to do digital calculations anymore.  That being said, there are two critical reasons you may need to know about digital circuits for physics experimentation:

  1. Computers don't work with analog signals, so to record data or control analog devices you'll need to convert signals from digital to analog or vice versa. - Field Programmable Gate Arrays (FPGAs) are currently key for processing data from particle physics experiments.  They're affordable, reprogrammable, and much, much faster than microcontroller devices (e.g. Arduino).  From a user side they act like a bunch of customizable logic gates, so knowing at least the basics will help you get started in working with them.

Digital Logic Signals:

When working with digital circuits, voltages are essentially mapped to either High (1) or Low (0).  There are quite a few different standards out there for what voltages are mapped to which, but we'll work with a 5V standard:

  • 5V standard (Used by Transistor Transistor Logic (TTL) and some Complementary Metal Oxide Semiconductor (CMOS))
    • Above 2V is HIGH
    • Below 0.8V is LOW
    • Between 0.8V and 2V is UNDEFINED (Don't do this!)
What about other logic families?

3.3V is the other dominant logic family used by modern devices, but there are other standards for even lower power consumption.  The trade off is that they are much less tolerant of any noise

Image courtesy of a Texas Implements application report

Logic Operations

Now that we've defined what voltages correspond to what logic states, let's talk about the actual operations. Our inputs are denoted as letters A and B (and C, D, etc for more exotic gates), and the output is denoted Q.  The behavior of Q for given inputs is summarized in the table below:

Operation Q High Q Low Circuit Symbol Mathematical Expression Chip
AND All inputs are high Any inputs are low { $Q = A \land B$ SN74LS08N
OR Any inputs are high All inputs are low $Q = A \lor B$ SN74LS32N
Not And (NAND) Not all inputs are high All inputs are high $Q = \lnot(A \land B)$ SN74LS00N
Not Or (NOR) All inputs are low Any inputs are high $Q = \lnot(A \lor B)$ SN74LS02N
eXclucive Or (XOR) Exactly one input is high Both inputs are high or low { $Q = A\underline{\lor}B$ SN74LS86N
Buffer Input is High Input is Low $Q = A$ None in our kit (Build a follower)
Inversion (NOT) Input is Low Input is High $Q = \lnot A$ SN74LS04N
Symbols courtesy of https://commons.wikimedia.org/wiki/Category:ANSI_logic_gates

Most of the chips we'll use for this share the same pinout, which makes our lives quite a bit simpler.  The inversion gate is the exception, because it can fit 6 gates rather than 4.

Pinout for all chips but the NOT gate.  Note that the ordering shifts pattern on the right-hand side. Pinout for the NOT gate.  This one differs because there's only one input per output.

Lab Template

Using a Button for Logic Input

It will be useful to be able to produce logic level signals with a button in this lab. However, you can't just connect 5V to one side of a button and ground to the other; that would short the power supply and generally be bad for your health.  

How to place your button in the breadboard Button circuit A, with pull-down resistor Button circuit B, with pull-up resistor
Predict what $V_{out}$ will be for circuits A and B both with and without the button pressed (i.e. 4 predictions)>
Test your predictions, and comment on any disparities

Leave button circuit B built, you'll be using it later.

Making an LED as Readout

To visualize the logical state (HIGH or LOW) for a circuit's output, it can be handy to use an LED.  However, our logic chips aren't designed to put out more than a couple of mA of current at most.  What do we do when we need more current than something can supply?  You guessed it, time for a transistor circuit.  We've modified things by adding a base resistor, which helps keep the circuit behaving as expected.  Without it, we'd be trying to set the base to 5V and the emitter to ground, which does not make for a happy transistor.

A transistor LED circuit for visualizing logic states. (2N3094L transistor)  Exact resistor values aren't critical, replace the 1k with a smaller resistor for a brighter light.
Using your button circuit, test the LED indicator.  Does the LED properly turn on when the button output is high?

How does the voltage change when the indicator is attached versus having no indicator?

Is the logic level still the same (i.e. above 2V or below 0.8V)?

Prep Work: Grounding Unused Inputs

Now that you've got some inputs and outputs, its time to set up your logic chip. We'll be using the SN74LS00N (NAND) chip to start, so locate yours and place it on the board.

After powering the chip, there is one more step before you start using it.  You should connect all of the inputs you aren't using (pins 4 & 5, 9 & 10, and 12 & 13) to ground so that their outputs won't be trying to change due to stray noise. 

Remember that pins start at 1 in the top-left corner and continue counter-clockwise.  If in doubt, check the diagram.

NAND Truth Table

Now that you've got everything started, its time to map out the behavior of the NAND gate for all permutations of inputs.  To do this, you'll want to connect the inputs to voltages you can toggle (via the button, movable wires, or the function generator) and observe the output for all four combinations that the inputs could be.  Remember, inputs should always either be 5V (High) or 0V (Low)

The schematic symbol for a NAND gate.
A B Q
H H
H L
L H
L L
Fill in the truth table in your report

Floating Input Issues

Remember how we told you to ground your unused inputs?  Disconnect the inputs from one of your NAND gates, and observe the output state.

Is the circuit behaving as you'd like in this instance?  Why or why not?

A Puzzle: Making an AND gate with NANDS

According to computer scientists, NAND gates are universal: combinations of NANDs and fixed inputs can re-create any other logic gate, or even any possible logic function.  The implementation may not be pretty, but it is always possible.  As an easy example, if we keep one input of the NAND fixed at HIGH, it can act as an inverter, as shown below.

As an exercise, you'll be using your NAND gates to simulate an AND gate.  Your circuit can connect any number of NAND gates and use any number of fixed inputs, but it should take exactly two variable inputs (A and B) and have exactly one output Q.
Sketch/diagram the combination of NAND gates you'll use to simulate an AND gate

Test all four possible inputs for your simulated AND and verify that it behaves as expected.

This section is new this year, so apologies if there are unknown issues.

Analog to Digital Conversion

Until this lab, we've focused on creating and manipulating continuous (analog) voltages.  When it comes time to do experimental science, you'll probably want to be able to interface a physical circuit to a computer at some point.  Since computers will only recognize digital information, we will use a special-purpose chip to convert an analog voltage to a digital one, an Analog to Digital Converter (ADC)

The chip we'll use for this is the ADS7816P (or ADS7822P; they're interchangeable), its pinout is shown below:

Pinout for the ADS7816 ACD.  Taken from the TI datasheet.

We'll set up our circuit with this chip such that:

  • {$+\mathrm{In}$ is the analog voltage we're converting
  • $-\mathrm{In}$ is connected to ground
  • $V_{CC}$ and $V_{REF}$ are 5V
  • $\overline{\mathrm{CS}}$ is connected to our button (which is normally high)
  • $\mathrm{DCLOCK}$ will be a 0-5V square wave we set up on the function generator.

Our digital signal $\mathrm{D}_{\mathrm{OUT}}$ will be in the form of twelve high or low outputs on pin 6, corresponding to the 12 binary digits of our measured voltage.  These will be synchronized with the $\mathrm{DCLOCK}$ signal, as the sending and receiving devices typically need to agree on when data is supposed to be transferred.

A schematic for how we'll hook up our analog to digital converter chip, adapted from the datasheet.  Note that there are some capacitors across $V_{REF}$ and $V_{CC}$ , these are fairly important to ensure stability and reliability.

We can think of the digital output in terms of repeated subtraction: The first bit tells us if our analog voltage is greater than half the reference number or not.  If so, the bit is a 1 (5V output) and we subtract half our reference value from the voltage we're converting, if not we pass the number on.  The second bit tells us if the number we're left with is greater than a quarter of the reference value, and so on. 

Input Expected output
5V 1111 1111 1111
2.5 V = $\dfrac{5 V}{2^{1}}$ 1000 0000 0000
1.25 V = $\dfrac{5 V}{2^{2}}$ 0100 0000 0000
0.625 V = $\dfrac{5 V}{2^{3}}$ 0010 0000 0000
$\cdots$ $\cdots$
.0049 V = $\dfrac{5 V}{2^{10}}$ 0000 0000 0100
.0025 V = $\dfrac{5 V}{2^{11}}$ 0000 0000 0010
.0012 V = $\dfrac{5 V}{2^{12}}$ 0000 0000 0001
0V 0000 0000 0000
I want to see an example in gory detail!

Let's consider how we get the binary conversion of 4 (on a 5V scale)

4 is greater than 2.5, so the first bit is 1

4 - 2.5 = 1.5, which is greater than 1.25, so the second bit is 1.

0.25 is less than 0.625, so the third bit is 0

0.25 is less than $5*2^{-5} = 0.3125$ , so the forth bit is 0. 0.25 is greater than $5*2^{-6} =0.15625$ , so the fifth bit is 1. 0.09375 is greater than $5*2^{-7} =0.078125$ , so the sixth bit is 1 0.015625 is less than $5*2^{-8} =0.0390625$ , so the seventh bit is 0 0.015625 is less than $5*2^{-9} =0.01953125$ , so the eighth bit is 0 0.015625 is greater than $5*2^{-10} =0.009765625$ , so the ninth bit is 1 0.005859375 is greater than $5*2^{-11} =0.0048828125$ , so the tenth bit is 1 0.0009765625 is less than $5*2^{-12} =0.00244140625$ , so the eleventh bit is 0 0.0009765625 is less than $5*2^{-13} =0.001220703125$ , so the twelfth bit is 0

As you might guess, nice looking numbers in base 10 don't always look like anything pretty in base 2:

Input Expected Output
4 V 1100 1100 1100
3 V 1001 1001 1001
2 V 0110 0110 0110
1 V 0011 0011 0011

So, after that nice foray into digital logic, let's build and test our circuit.

For the clock signal, use a 0-5V square wave, with a frequency of 10 kHz.  (The actual frequency isn't really critical here)

To observe the output here, you should change your triggering settings to use the rising edge of whichever channel $D_{OUT}$ is on, and set it to normal mode so that the screen stops updating when no new signal is present. Pushing your button should make the ADC trigger once, giving you a snapshot of the converted input voltage.  However, the $\overline{\mathrm{CS}}$ signal needs to be synced with the clock, so in practice it may take a few presses for the button to work. A scope isn't really the best tool for this, but we'll make do.  If you do a lot with digital signals, you'll want to learn about logic analyzers, which are specially built for observing the timing of many digital signals at once.

*FIXME* Add note about using the trigger holdoff here: trace should be stable if holdoff time is > burst width.

An example of $D_{OUT}$ for a high voltage.  Ch 1 shows the clock signal, and Ch 2 shows the digital conversion.  Note that the triggering point has been moved left to facilitate seeing the entire signal.
Observe the output of your circuit for 0V and 5V inputs.  How close are they to what you would expect?

0V might be hard to observe, since the expected output is basically also 0V.

You could try looking at $D_{OUT}$ on one channel and triggering off of your button on the other channel

Potentiometer Input

Let's turn once again to our friend the potentiometer to make ourselves a variable voltage divider, as shown below:

Can you observe bits change as you adjust your potentiometer?

How many times does the output change with one full rotation of the adjustment screw? (You don't have to be exact.)

Light sensor reprised

Going all the way back to lab 4, let's rebuild our light sensor by making a voltage divider using our photoresistor and a 100k resistor. 

Feed this circuit's output to the ADC, and see how the output signal changes as you cover and uncover the light.

The next step here would be to send the ADC's output to a microcontroller and then log it on a computer, but the parts to do so aren't included in our kits.

Use this link to submit your report

Portions of this lab are based on material from Learning the Art of Electronics by Hayes and Horowitz