HackerBoxes 0012: Digital Logic


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.

Complex programmable logic devices (CPLDs) and field-programmable gate arrays (FPGAs) are two types of larger PLDs that are commonly used in modern digital systems.

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.

Quartus Prime Lite Download Page

Quartus Quick Start Guide

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!


  • Clocks Contest

    Clocks Contest
  • Oil Contest

    Oil Contest
  • Creative Misuse Contest

    Creative Misuse Contest

50 Discussions

Long story follows:

I installed Quartus Prime and got the USB driver working on my Windows 10 machine. I followed the "Entering your first design" walkthrough at http://www.hackshed.co.uk/getting-started-with-cplds-index/ (which was pretty clear I thought, well done). Every time I try to program it causes Windows to blue screen.

Installed Ubuntu on a VM and then downloaded the Quartus Prime software and installed it. After some work I was able to walk through the instruction again. Compile, pick pin, compile and then program. Now all the development board LEDs and buzzer are going. Worried that I busted something I turned it off. Is this normal? Did I just not do something that I should have known to do? Anyone have a working Quartus Prime project I could download and study?

I'm loving learning and messing with this stuff! Any pointers would be appreciated.

6 replies

Did anyone ever get a solution for the blue screens MikeM515 mentioned in Windows 10 above? I've got a brand new install of Windows 10, and when the USB Blaster is connected, it randomly bluescreens.

Also, Thanks for the blog jasper_fracture. looks like that will give lots of people a good foundation to start on.

So, since it was a new windows 10 install, I dumped windows 10.

Installed Ubuntu Desktop 16.0.4 LTS and installed the software.

Initially I had issues installing QuartusLiteSetup- (and 200 with the update) where the window would stall (Gray out) after about 50%. Not installing ModelSim like someone else mentioned didn't seem to help. (I let it run over night installing). So I downloaded QuartusLiteSetup- and it worked like a champ installing. I still haven't tried uploading a program, but I will shortly.

Set your unused pins to something other than the default "drive to ground".

My son and I have been working on our hobby site, and the first few posts we did were some basic tutorials (block schematics, blinking led, binary led counter, etc.) for the Altera board: http://jasperfracture.com.

Mike -

Clarification - yes, it is normal for everything to turn on if you compile with the default setting "as output driving ground" for "Unused Pins". Compiling like this pulls all the unused outputs low and turns all the onboard stuff on.

If you've got a project open, you can change the setting via the main menu: "Assignments->Device", click the "Device and Pin Options..." button, select "Unused Pins" under "Category". Last, make a selection from the "Reserve all unused pins" dropdown. Something like "as input tri-stated" instead of "as output driving ground".

Thank you for the information Jasper! I will give this a try when I get home tonight.

Blaster chain problem.

Using Windows 10.

First circuit compiles ok.

Run programmer but get blank report.

Push auto detect and get error message - "Unable to scan device chain."

Run "test TTAG chain."

Get "Error. JTAG chain problem detected. Error. No device detected."

Device manager has - Altera USB-Blaster

Would you help me. I've spent house on this.

Thanks, Pete Lefferson Lefferson@ieee.org

Has anyone gotten the Quartus Prime "lite" software running on linux yet? I started downloading in on Ubuntu running in an VM, but had to abort the download when I realized that the 12GB(!) file wasn't going to fit in my 8GB vm.

7 replies

I have Quartus working on Fedora 23 sort off. I don't seem to be able to connect to the Blaster. The Blaster is seen on usb, but Quartus does not see it. I tried to build the driver, but it says the kernel is too new. Anybody get the driver to compile and load with ndiswrapper?

Well I was able to program the MAXII using my Fedora 23 distribution. I did a few examples and want to reload the time counter that came loaded on it. But I can't find the program. Anybody smart enough to have downloaded it off the MAXII? Also I program the thing, but the program does not take unless I turn the MAXII off for quite a while. Anybody got any ideas on this?

You can expand the size of your VM's virtual disk. Might be faster to create a new virtual disk and either dd your current virtual disk to it or just reinstall from scratch.

I just started from scratch. Installed just fine once I had enough space for it.

I was able to install this under Mint17.3, but I had to deselect the ModelSim package from installing. The installer would just hang for some reason. I think it's only for simulating other FPGA packages in memory. I don't think it's necessary, otherwise I have it installed. Trying to figure out what to do with it now...

Just a follow up for anyone using Ubuntu or an Ubuntu based distribution, I couldn't get it to actually recognize my board (via the USB Blaster JTAG) until I followed these steps: http://www.fpga-dev.com/altera-usb-blaster-with-ubuntu/

Yes, it seems to run fine under Ubuntu 16.04 so far, although I had a few hiccups getting permissions setup properly for the Altera USB Blaster.

Anyone with Windows 10 able to use their USB Blaster? Every time I try to use it my machine crashes. I'm using the drivers that came with Quartus 16.0.

1 reply

This worked for me:


I see a common but unfortunate mistake. Do not arbitrarily equate a low or high voltage with true (1) or false (0)! There are two different logic conventions: positive and negative. For example the 74x00 family data sheet states that this is a Quad Two Input Positive Logic NAND gate. This also means that it can be described as a Quad Two Input Negative Logic NOR gate. In positive logic a high is true (1) and a low is false (0). In negative logic a high is a false (0) and a low is true (1).

BS Computer Science

1 reply

You're right, but I just usually call it active low...unless you meant something different. All the LEDs, buzzer, switches, 7 segments, are all a good example of this on the CPLD included with this last box.