E15/24 Fundamentals of Digital Systems: Lab #2
Modern Digital Design
in partnership with mas chano and karl petre
09-12-2004

labs home    |    lab1    |    lab2    |    lab3    |    lab4    |    lab5    |    final project


ABSTRACT

In this lab we used ALTERA to simulate traffic lights and program a parity checker that also displays the values of digits in hexadecimal on the 7-segment display. We also devised VHDL code that takes two 8-bit 2's complement numbers and outputs their difference in the 7-segment displays as a hexadecimal number. Using ALTERA, we programmed the ALTERA boards to perform these tasks.

Task 1

For this task, we implemented the traffic light from lab 1 using the altera board. This time, however, the time range of a full cycle in a traffic light pattern was extended to 32 stages from 16. Furthermore, a range in which the signal to all directions of an intersection is flashing red was added. In order to design the circuit that would simulate this task, we first drew the Karnaugh maps for the six different outputs and then we tested our circuit using the graphical design tools and the waveform editor. The Karnaugh maps and the circuit are shown below.

We also coded a 5-bit counter to act as the input to the traffic lights circuit. We used the code presented by Dr. Maxwell in lab as a basis for our counter and modified it slightly to obtain the behavior we wanted. After we obtained the desired circuit using Altera's digital design tool, we loaded the program onto the ALTERA board and connected wires to the LEDs to similate traffic lights on the board.

Problems Encountered

Our program worked as we expected it to; and we verified that using both the waveform editor (comparing all possible inputs with the desired outputs) and the altera board (physically observing the behavior of the output on LEDs).

E/W RED
CD\AB
00
01
11
10
00
1
1
1
0
01
1
1
1
0
11
1
0
1
0
10
1
1
1
0
 
E
0
 
 
00
01
11
10
00
1
1
0
0
01
1
1
0
0
11
1
0
0
0
10
1
0
0
0
 
E
1
         
E/W YELLOW
CD\AB
00
01
11
10
00
0
0
0
0
01
0
0
0
0
11
0
0
0
0
10
0
0
0
1
 
E
0
 
 
00
01
11
10
00
0
0
0
0
01
0
0
0
0
11
0
0
0
1
10
0
0
0
1
 
E
1
         
E/W GREEN
CD\AB
00
01
11
10
00
0
0
0
1
01
0
0
0
1
11
0
1
0
0
10
0
0
0
1
 
E
0
 
 
00
01
11
10
00
0
0
0
1
01
0
0
0
1
11
0
1
0
0
10
0
1
0
0
 
E
1
         
     
N/S RED
CD\AB
00
01
11
10
00
0
0
1
1
01
0
0
1
1
11
0
1
1
1
10
0
1
1
1
 
E
0
 
 
00
01
11
10
00
0
0
0
1
01
0
1
0
1
11
0
1
0
1
10
0
1
0
1
 
E
1
         
N/S YELLOW
CD\AB
00
01
11
10
00
0
1
0
0
01
0
1
0
0
11
0
0
0
0
10
0
0
0
0
 
E
0
 
 
00
01
11
10
00
0
1
0
0
01
0
0
0
0
11
0
0
0
0
10
0
0
0
0
 
E
1
         
N/S GREEN
CD\AB
00
01
11
10
00
1
0
0
0
01
1
0
0
0
11
1
0
0
0
10
1
0
0
0
 
E
0
 
 
00
01
11
10
00
1
0
0
0
01
1
0
0
0
11
1
0
0
0
10
1
0
0
0
 
E
1
         

 

Task 2

In this part of the lab, we designed code to check the parity of an eight-bit integer.  The number was selected from a bank of DIP switches, and our design also used a DIP switch to select the parity.

In order to accomplish this task, we wrote three different sections of code.  The first checked to see whether the inputted parity matched the correct parity for the selected number.  This was fairly simple to do, and involved (as we found in the previous lab) a one-line XOR statement.  When each of the input bits – the 8 bits from the integer and the bit from the parity – were XORed together, the parity was correct only if the end result of the statement was 0.  When the expression returned a 1, the program turned on one of the LED's on the Altera Board.

The second portion of the code converted the 8-bit binary number so that it could be displayed by the 7-segment displays on the Altera Board.  To do this, the program split the 8-bit number into two 4-bit numbers, each of which was to be represented on a single 7-segment LED.  The most reasonable way to convert each of these 4-bit numbers to the LED outputs was to use a case statement which selected which LED's were to be turned on for every individual number.

The final part of the code was a program that tied the two subroutines together in order to execute them.

Task 3

For this part of the lab, we were to write a program that takes as input two 8-bit 2's complement numbers (8 bits from each DIP switch panel) and outputs their difference in the 7-segment displays as a hexadecimal number.  The 7-segment display shows the calculated magnitude of the number, and other LED's on the board were used to show the sign of the number and whether or not there was an overflow during the operation.

Our code inputted the 8-bit numbers as a SIGNED type, so that performing the subtraction was simple.  In order to determine the sign of the number, our program converted the SIGNED type answer to a string, and set the sign LED to on (meaning a negative number) if the most significant bit in the 8-bit answer was a 1.  The overflow LED was turned on if the signs of the two input numbers were different; this was implemented by using an XOR statement.  After performing the subtraction, the result was sent to the same conversion program as used in the previous part of the lab to output the magnitude of the number to the 7-segment LED's.

Testing the circuit: Parts 2 and 3

To test these two parts of the lab, we programmed our code to our Altera Board and tested the output produced from several different input states.  For part 2, we made sure that the parity light turned on and off every time that we changed one of the DIP switches, and this was also the point where we checked to see if our 7-segment display conversion program worked correctly.

For convenience, we set the input and output ports for the third part of the lab so that we did not have to rewire any of the connections that were left on the board from the second part.  To test the third part of the lab, we worked out on paper the correct outputs for a few different input states, and checked to see if the answers given by the code matched these.  Also, we checked that cases providing an overload situation would indeed cause the overflow Led to become lit.  We checked to see if the sign LED worked correctly by inputting 8-bit numbers that would produce both positive and negative answers.

Problems Encountered

The only problem that was encountered was that the diagram for the 7-segment displays was mislabeled in the Altera Board book.  This was a relatively minor problem, as we merely had to rewrite all of the entries in our case statement for the 8-bit-binary-to-seven-segment-display conversion program. However before we figured the mislabeling, we thought there was a problem with the code and tried to change it which cost us some time.

What We Learned

Through the course of this experiment, we learned about the ALTERA board and the various ALTERA tools such as graphical design tools and VHDL programmer and the waveform editor. We particularly learned to code in VHDL and to program the chip on the Altera board.