Lab 2b

Objectives of this lab:

  1. To become familiar with conditional statements;
  2. To become familiar with arrays;
  3. To observe some experimental results from Altera UP1 board.

 

Reference Files for Lab:

Lab Evaluation Form

Lab2bFiles.zip

 

1. Adder Program:

 

1.1.In this lab, you are required to create a simple adder using C language in Microsoft Visual Studio .Net 2003.

 

1.2.Use the following table as a reference to decide the outputs when you programming.

 

x

y

z

s

c

0

0

0

Sum[0]=0

Carry[0]=0

0

0

1

Sum[1]=1

Carry[1]=0

0

1

0

Sum[2]=1

Carry[2]=0

0

1

1

Sum[3]=0

Carry[3]=1

1

0

0

Sum[4]=1

Carry[4]=0

1

0

1

Sum[5]=0

Carry[5]=1

1

1

0

Sum[6]=0

Carry[6]=1

1

1

1

Sum[7]=1

Carry[7]=1

 

1.3.You need to create a new .Net project to implement the adder in C.

 

1.4.Initialize two integer arrays: Sum[8] and Carry[8], which are:

 

Sum [8] = {0, 1, 1, 0, 1, 0, 0, 1}; Carry [8] = {0, 0, 0, 1, 0, 1, 1, 1};

 

1.5.Create a function using nested conditional statements that use one variable (x, y, and z) at a time to print the correct value of sum bit, s, and carry out bit, c. The sum bit, s, should be one of the elements of Sum array and the carry out bit, c, should be one of the elements of Carry array according to the truth table.

 

1.1.Your program should read three 1-bit input values (x, y, and z) from terminal and then output the sum and carry out bits. After reading the inputs, if any of the inputs are not 0 or 1, you should set it to a 1. Your program should be in a loop which continuously reads the three inputs and produces the output and repeats itself.

 

1.2.Compile and run your program. Show it to your TA.

 

1.3.Now change the program to use a set of conditional statements, one corresponding to each entry in the table to produce the output corresponding to a specific input.

 

2. Hardware Implementation and Observation:

 

You are given a circuit in this step and this circuit manipulates three 1-bit inputs to add them and produce an out and a carry bit.  The truth table for this circuit matches the table given above.

 

Download this circuit from the lab web site and create a project for it using similar steps as in lab 2a with one difference. In the last lab, you were given the pin assignments.  Now you will choose your own.  Notice that the circuit has three inputs and two outputs.  You need to connect 3 dipswitches to the inputs, and connect the two outputs to two of the red LEDs on the board.  First use this picture to select pins to use for the inputs and for the outputs from the FPGA.  You may select any squares that are not shaded and that have numbers (notice that pin assignments from the last lab were all of this type).  Additionally, the three squares selected for the inputs should be consecutive in a row.  Use Assignments | Pins to set the input and output names equal to the numbers you have just chosen. 

 

The last step is to use wires to connect the dipswitches to the input pins you chose, and to connect the output pins you chose to the LEDs.  Use the group of eight wires, and connect one side to a set of dipswitches.  The other side should be connected to pins that surround the FPGA, specifically the pin numbers just chosen.  Use single wires to connect the pin numbers chosen for the outputs to the LEDs.  Be very sure that the pins you plug wires into are the same pins chosen from the picture.

 

Download the circuit to the Altera UP1 board and observe the combination of inputs and outputs.

 

Show the results to your TA for several combinations of inputs in arbitrary order.