Introduction: HackerBoxes 0012: Digital Logic
DIGITAL LOGIC: This month, HackerBox Hackers are exploring the basics of digital and programmable logic devices. This Instructable contains information for working with HackerBoxes #0012. If you would like to receive a box like this right to your mailbox each month, now is the time to subscribe at HackerBoxes.com and join the revolution!
Topics and Learning Objectives for this HackerBox:
- Understand Boolean Logic and the Basic Digital Gates
- Wire and Test Digital Gate Circuits
- Understand Latches and Flip-Flops
- Wire and Test a Digital Flip-Flop Circuit
- Measure Digital Circuits using a Logic Analyzer Instrument
- Understand Programmable Logic Devices
- Implement Digital Circuit Examples in Schematic Capture
- Implement Digital Circuit Examples in VHDL/Veriog
- Program Implemented Digital Circuits into a CPLD
HackerBoxes is the monthly subscription box service for DIY electronics and computer technology. We are hobbyists, makers, and experimenters. Hack the Planet!
Step 1: HackerBoxes #0012: Box Contents
- HackerBoxes #0012 Collectable Reference Card
- Intel Altera MAX II EPM240 CPLD Development Board
- JTAG USB Blaster with Ribbon Cable
- 8 Channel 24 MHz USB Logic Analyzer
- DuPont Jumpers for Logic Analyzer
- Grabber Clip Leads for Logic Analyzer
- Chip Box with ESD-Safe Foam
- 74HC08, 74HC32, and 74HC74 Digital ICs
- 7805 5V Regulator (TO-220)
- 9V Battery Clip with Leads
- 100 ohm and 10K Resistors
- Red LEDs
- Tactile Pushbutton
- Solderless Breadboard (400 points)
- Jumper Wire Bundle for Breadboard
- MiniUSB Cable
- Exclusive HackerBoxes Digital YinYang Decal
Some other things that will be helpful:
- One 9V battery
Most importantly, you will need a sense of adventure, DIY spirit, and hacker curiosity. Hardcore hobbyist electronics isn't always easy, but when you persist and enjoy the adventure, a great deal of satisfaction may be derived from persevering and getting your projects working. Just take each step slowly, mind the details, and don't hesitate to ask for help.
Step 2: What Is Digital Logic?
You are probably already at least somewhat familiar with the basic concepts of digital electronics where a binary world is defined such that every signal is either a ONE (high, on, true, 5V) or a ZERO (low, off, false, 0V). These notions are the basis of our modern digital computers and communications devices. We can use the ONEs and ZEROs to represent any other values, data, or signals such as music and video.
With these signals (ZEROS and ONES) in mind, we will explore the basic logic gates. Logic gates allow us to compute outputs given digital inputs according to the rules of Boolean Algebra. While we will test out AND gates and OR gates to start out, other basic gates also include NOT, NAND, NOR, and XOR. Combining these types of gates together allow us to implement combinational logic.
Adding memory (in the form of a Flip-Flop or Latch) allows our digital circuits to maintain state of operate in a time-dependent fashion. Such circuits implement sequential logic.
If you are interested, here are some nice online video and instructional resources:
Step 3: Wiring Up an AND Gate
- Solderless Breadboard
- 7805 5V Regulator
- 9V Battery Clip
- 9V Battery
- 74HV08 (Quad AND Gate)
- 3 Red LEDs
- 3 100 ohm Resistors (brown, black, brown)
- Jumper Wires
First let's set up a power supply for our circuit. The 7805 5V Regulator (datasheet) is used to turn the supply of the 9V battery into a nicely, regulated 5V power rail. Note the ordering of the pins for the 7805. With the heatsink down, the left pin is the input (9V here), the center is common (GND here), and the right pin is the output (5V). The output (5V) and the GND are wired to the rails along the bottom of the breadboard.
Next pins 7 and 14 of the 74HC08 (datasheet) chip are connected to 5V and Ground to supply power to the logic chip. Note the orientation of the chip according to the semicircular notch on the left end as illustrated here.
Pins 1, 2, and 3 of the 74HC08 chip are the inputs and outputs for one of the four AND gates in the chip. Each of these inputs and outputs is wired to a 100 ohm resistor, which is in turn wired to a red LED. The resistors can go into the breadboard either way but the LEDs must be oriented such that the shorts of the two pins goes into the ground rail.
Lastly, the two wires illustrated in yellow are the inputs to the AND gate. They are illustrated wires into the ground rail. This represents inputs A=0 and B=0, moving one of the yellow wires from the GND rail to the 5V rail will represent inputs A=1 and B=0 (or A=0 and B=1). What wiring represents the inputs A=1 and B=1? Try all four of the possible input combinations and verify the truth table.
If you would like to watch a video of this circuit being assembled, the folks at PyroEDU have done just that.
Step 4: Wiring Up an OR Gate
This circuit is exactly like the one for the AND gate. Notice that the pinout for the 74HC32 OR gate chip (datasheet) is identical as that for the 74HC08, only the gate inside is different.
Swap out the AND gate chip with the OR gate chip.
Try the four different combinations of inputs and verify the truth table of the 74HC32 OR gate.
Step 5: Sequential Logic - Latches and Flip-Flops
The logic gates that we have worked with so far will always have outputs that are only a function of the current inputs (according to their truth tables). This type of logic (combinational logic) cannot generate outputs that depend upon previous inputs. For example, a vending machine circuit implemented in this way could never get to the "state" of having 50 cents because when the second quarter is inserted it has no way to store the memory of the first quarter being inserted. Being able to remember and apply previous inputs is called having memory, maintaining state, or being time-dependent. This is referred to as sequential logic.
According to the Wikipedia Entry, an electronic flip-flop or latch is a circuit that has two stable states and can be used to store state information. A flip-flop is a bistable multivibrator. The circuit can be made to change state by signals applied to one or more control inputs and will have one or two outputs. It is the basic storage element in sequential logic. Flip-flops and latches are fundamental building blocks of digital electronics systems used in computers, communications, and many other types of digital systems.
Here is a nice video explaining the construction and operation for different types of latches and flip-flops.
Step 6: Wiring Up a D Flip-Flop Circuit
- Solderless Breadboard
- 7805 5V Regulator
- 9V Battery Clip
- 9V Battery
- 74HC74 D Flip-Flop
- 2 10K Resistors (brown, black, orange)
- 4 Red LEDs
- 4 100 ohm Resistors (brown, black, brown)
- Push Button
- Jumper Wires
This D Flip-Flop circuit is wired up in a very similar fashion to the circuit for the AND/OR gates, but now there is a push button to provide the clock signal. The D input (green wire in the breadboard diagram) can be moved between the 5V rail and the GND rail to change the D input from ONE to ZERO.
This video, again from the folks at PyroEDU, is worth watching in its entirety. More specifically, it has a nice description of the D Flip-Flip at about 3:40 and a demonstration of this circuit being assembled at a about 7:40.
Step 7: Digital Logic Analyzer
A logic analyzer (Wikipedia) is an electronic instrument that captures and displays multiple signals from a digital system or digital circuit. A logic analyzer may convert the captured data into timing diagrams, protocol decodes, state machine traces, assembly language, or may correlate assembly with source-level software. Logic Analyzers have advanced triggering capabilities, and are useful when a user needs to see the timing relationships between many signals in a digital system.
This 8-Channel USB Logic Analyzer is based on a Cypress CY7C68013A-56PVXC (FX2LP) Microcontroller (datasheet). It used an NXP 74HC245 input buffer, an Atmel AT24C02 256-byte I2C EEPROM, and includes a 24MHz crystal oscillator.
The sigrok software is a great choice for use with this logic analyzer. The sigrok project is a portable, cross-platform, Free/Libre/Open-Source signal analysis software suite that supports various device types, such as logic analyzers, oscilloscopes, and many others. The sigrok project is licensed under the terms of the GNU GPL.
Step 8: Programable Logic Devcies
According to Wikipedia, a programmable logic device (PLD) is an electronic component used to build reconfigurable digital circuits. Unlike a logic gate, which has a fixed function, a PLD has an undefined function at the time of manufacture. Before the PLD can be used in a circuit it must be programmed, that is, reconfigured.
PLDs can be designed using schematic capture where gates and flip-flops are laid out and connected as a visual schematic representation of the circuit to be implemented. PLDs can also be designed using hardware description languages that are similar to programming languages for implementing software, but are actually descriptions for implementing hardware within the PLD. VHDL and Verilog are popular hardware description languages for CPLD and FPGA design. VHDL borrows many features from the Ada programming language, while Verilog borrows from the C programming language.
It is important to conceptualize that the hardware description language is not a program running on the PLD, it is a mechanism for reconfiguring the logic resources (think gates and flip-flops) within the PLD into a new machine.
You might want to check out this EEVblog Video with a basic introduction to FPGAs, how they work, and why to use them.
Step 9: Altera MAX II EPM240 CLPD Board
Intel's Altera MAX II family of CPLD family is based on a groundbreaking architecture that delivers low power and the low cost per I/O pin. This instant-on, non-volatile CPLD family targets general-purpose, low-density logic and portable applications, such as cellular handset design. In addition to delivering the lowest cost for traditional CPLD designs, the MAX II CPLD drives power and cost improvements to higher densities, enabling you to use a MAX II CPLD in place of a higher power or higher cost ASSP or and standard-logic CPLD.
The CPLD is programmed using the USB Blaster JTAG module.
This site has all of the documentation on the MAX II CPLD family. Along with the Quartus Software.
This series of videos includes some examples using the older Quartus II software for both schematic capture design as well as VHDL design.
Note that Quartus has native Windows and Linux versions. If you are using Mac OS X and do not have either of those operating systems running under dual-boot or virtualization, you will need to set that up. For example, use Boot Camp or VirtualBox to install Ubuntu. You can also just run Ubuntu from a USB device.
Step 10: Hack the Planet
Hopefully, you are enjoying this foray into digital electronics. If you have enjoyed this Instrucable and would like to have a box of electronics projects like this delivered right to your mailbox each month, please join us by SUBSCRIBING HERE.
Please share your success in the comments below and/or on the HackerBoxes Facebook page. Certainly let us know if you have any questions or need some help with anything. Thank you for being part of the HackerBoxes adventure. Please keep your suggestions and feedback coming. HackerBoxes are YOUR boxes. Let's make something great!
4 People Made This Project!
We have a be nice policy.
Please be positive and constructive.