Syllabus   Labs   Homework   Quizzes  
Scores   Notes   Blank

Lab 6, due 3/24/21 (Wed)
Dr. Tong Lai Yu

HEX 7-Segment LED Decoder

You may refer to your lecture notes to look up information needed in the lab.

  1. Preparation
    1. Objective: To practice K-map for gate-level circuit minimization, and use a Spartan 3 FPGA to implement a hex 7-segment decoder to display hexadecimal digits or to build a 7-segment decoder using a PLD device.
    2. Provided: Spartan 3 FPGA Board, GAL16L8 chip, 7-segment LED
    3. Background: Brief introduction to 7-segment decoder
    4. Preparation
        The PLD or code-converter (decoder) has 4 input lines (W, X, Y, Z) and 7 output lines (a, b, c, d, e, f, g).
      Develop your input-output table with your lab partner. Individually, simplify each output column (a, b, ..., g) using a K-map. Double check your results with your partner. Your 7-segment LED should display all 16 hex digits: 0, 1, 2, ....,9, A, B, ..., d, E, F.

      A) Building a 7-seg decoder using a PLD Do not simplify beyond the SOPs derived from K-maps. Based on your SOPs type-in and save the following file on a USB drive. Save the file with a .PLD extension. Bring the USB drive and a printout of the file to the lab. Here &, #, and ! represent AND, OR, and NOT respectively.

      PARTNO       PLD01;
      NAME         CODECONV;
      DATE         today's date;
      REV          01;
      DESIGNER     your name;
      COMPANY      CSUSB;
      DEVICE       G16V8A;
      LOCATION     JBH-356;
      /* INPUTS */
      PIN 1 = W;
      PIN 2 = X;
      PIN 3 = Y;
      PIN 4 = Z;
      /* OUTPUTS */
      PIN 12 = a;
      PIN 13 = b;
      PIN 14 = c;
      PIN 15 = d;
      PIN 16 = e;
      PIN 17 = f;
      PIN 18 = g;
      /* Note: here a is just an example, not your solution */
      a = !X&!Z # Z&W # Z&X # Y&!X;
      b = ...;

      B) Developing a verilog module that implements the coder
      Your code could look like the following:

      //EN is enable, the board's 7-seg leds are negative active,
      //  so we need to invert it
      module seg7 (output a, b, c, d, e, f, g, output [3:0] EN, input W, X, Y, Z );
         wire a0, b0, c0, d0, e0, f0, g0;
         assign a0 = Y & X | ~W & Y | ~X & ~Z  | ~W & X & Z | W & ~X & ~Y | W & ~Z;
         assign g0 = W & ~X | Y & ~Z | W & Z | ~W & X & ~Y | ~X & Y;
         assign a = ~a0;
         assign EN = 4'b1110;  //1 is disable, 0 is enable
                               // we use the first 7-seg LED
    5. You can obtain the template .ucf file by clicking here . Your .ucf file could look like the following:
      # digit enable
      NET EN[0] LOC = D14;    #rightmost 7-seg display
      NET EN[3]  LOC = E13;      #disable
      NET Z LOC = F12;   #SW0   bit 0
      NET W LOC = H13;   #SW3   bit 3
      #NET "point"  LOC = P16; # decimal point
      NET a  LOC = E14; # segment a
      NET g  LOC = N16; # segment g
  2. Experiment: Hex 7-segment code conversion display
      A) Circuit Assembly
      1. Use the WINCUPL program on the lab machines to compile your PLD program. Under the compiler options use JED name = PLD name. Perform a device dependent compile. This will create a JED file. Save the JED file on your storage device. (You may give your USB to the TA to do the compilation and chip-programming for you. If you are interested, you could ask the TA to show you all the steps; then you are responsible to do the compilation and programming for the next group.)
      2. Run Chip Master 5000 program. Choose device ATF16V8B. Lock in your IC chip on the programmer control box. Erase the chip. Load your JED file. Program the chip.
      3. Your PLD pin assignment is as follows.
        ATMEL ATF16V8B PLD
            |1  +--+ 20| VCC
         I  |2       19|
         N  |3       18|
         P  |4       17| INPUT/
         U  |5       16| OUTPUT
         T  |6       15| PORTS
         S  |7       14|
            |8       13|
            |9       12|
        GND |10      11| /OE
      4. Connect the inputs to W, X, Y, Z to the switches of your breadboard and the outputs a, b, c, d, e, f, g to a 7-segment LED. Test your circuitry.
        Click here to see a sample circuit.

      B) Verilog Programming

      1. Use the Spartan 3 FPGA to implement your hex 7-segment decoder and display you developed above. Refer to Lab 4 or Lab 5 for programming Spartan 3. Demonstrate your results to the instructor.
      2. Write a verilog modulus and its stimulus to simulate the 7-seg decoder using a differnet method like the following:
        `timescale 1ns / 1ps
        module seg7 ( output reg [1:7] leds, input [3:0] bcd );
                always @(bcd)
                case (bcd)       //abcdefg
                        0: leds = 7'b1111110;
                        1: leds = 7'b0110000;
                        2: leds = 7'b1101101;
                        3: leds = 7'b1111001;
                        4: leds = 7'b0110011;
        initial begin
        #160 $finish;
        You may refer to the previous lab to see how you write the stimulus.
        Also, write a testbench to test the seg7 module you developed in B).

      C) C/C++ Programming

      1. Write a C/C++ program to simulate the 7-segment LED display and its BCD decoder. Draw a thick line to simulate a segment being on and a thin line to simulate 'off'. The user enters four bits corresponding to w, x, y, and z discussed above and the program displays the corresponding digit. The following figure shows the number 3: You may review lab 2 of cse 202 to make simple graphics. ( ) Examples of drawing thin and thick vertical and horizontal lines and reading from the console could be found in the directory: /pool/u/class/cse310/labs/lab6 MS Windows putty users may need to install Xming Font to run the program.


            You may declare a public class to simulate the 7 segments, a, b, c, d, e, f, g:

        	class SevenSeg
            		int a, b, c, d, e, f, g;
            		SevenSeg () {
              		  a = b = c = d = e = f = g = 0;

            Write a function that takes w, x, y, z as inputs, calculates a, b, c, d, e, f and g, and returns them as a SevenSeg object:

        	//inputs: w, x, y, z
        	//outputs: seg7
        	void segDecoder ( int w, int x, int y, int z, SevenSeg &seg7 )
        		seg.a = !w & y | .... 
        		seg.b = ....

            Then write a function that displays the digits.

        	void display ( const SevenSeg &s )
          	  Point p0, p1;
          	  p0 = Point (-1.9, 4 );
          	  p1 = Point (1.9,  4 );
          	  HLine ( p0, p1, s.a );
      2. Extra Credit (10 points)

        Extend your C/C++ program so that it could read in 8 bits and display two hex digits.

        Write a simple report that shows your work, which answers the questions in the manual. Comment on and self-evaluate your work; state explicitly whether you have finished each part successfully! If you have finished all parts successfully, and have shown the results to the instructor, give yourself 30 points, otherwise deduct some points that you feel appropriate.

      Note: All your work must be saved in pdf file format and submitted online! Include all the code you've written if there's any. You must also put down your name but not your student ID in your submitted report.
      To submit your lab, you must first login by choosing your name, entering your student id, and clicking Login below.
      After submission, click on the link displayed, to make sure you could see what you have submitted with your browser.

      Choose your name:
      Enter your student id (xxxxxxxxx):