-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter 2: From bit to data. Fport
Examples of this chapter in github
Now, instead of just one bit we will output four of them, and display them using the LEDs. It's a fixed value, wired "within the hardware". If we wanted to display any other number on the LEDs, we will need to synthesize again.
We will name this component "Fport" (Fixed port). It has a 4-bit output bus, labeled as "data", wired to the binary value "1010".
This circuit is similar to the one in the last tutorial, (setbit.v) but instead of having just 1 output bits, it has 4 bits. It's described like this:
//-- Fichero Fport.v
module Fport(output [3:0] data);
//-- Module output is a 4 wire bus.
wire [3:0] data;
//-- Output the value through that 4-bit bus.
assign data = 4'b1010; //-- 4'hA
endmodule
The output is now a 4 wire array. You can express that by writing [3:0] before the wire name. In order to assign a value to that wire, we write the value using Verilog's notation: First, the number of bits, then the ' character, after that, the base of the number (in this case, "b" for "binary") and finally, the 4 binary digits. This number could be expressed like a single hexadecimal digit, by writing 4'hA. We could also write it in decimal as 4'd10.
Each one of the 4 output bits will be assigned to the pins connected to each one of the 4 leds of the FPGA:
This is specified in the Fport.pcf file:
set_io data[0] 99
set_io data[1] 98
set_io data[2] 97
set_io data[3] 96
In order to synthesize, we navigate to the tutorial/T02-Fport folder, and execute the command make sint:
$ make sint
The final message will print out how many resources this circuits requires in the FPGA, and how many of them are available:
After placement:
PIOs 2 / 96
PLBs 1 / 160
BRAMs 0 / 16
These resources are:
- PIO = Programmable Inputs and Outputs
- PLBs = Programmable Logic Blocks
- BRAMs = Block RAM Memory
Now we upload the Fport.bin file into the FPGA:
$ sudo iceprog Fport.bin
Upon finishing, two LEDs will be on, and two LEDs will be off, given that we are sending the value "1010":
This testbench is similar to the one in the last chapter. But now, instead of checking just one bit, we check the whole 4-bit bus. If it's not exacly as expected, it throws an error. The diagram is the following:
The testbench (Fport_tb.v) has this three elements:
- The UUT (Unit Under Test): Fport
- The checking block
- The DATA wire
The testbench code is:
//-- Fport_tb.v
module Fport_tb;
//-- 4-wire bus, to connect it to the Fport component output.
wire [3:0] DATA;
//--Instantiating the component. Connect output to DATA.
Fport FP1 (
.data (DATA)
);
//-- Begin the test
initial begin
//-- File in which store the results.
$dumpfile("Fport_tb.vcd");
$dumpvars(0, Fport_tb);
//-- After 10 time units we check
//-- whether the cable has the previously given pattern or not.
# 10 if (DATA != 4'b1010)
$display("---->¡ERROR! Salida Erronea");
else
$display("Componente ok!");
//-- Finish the simulation 10 time units after that.
# 10 $finish;
end
endmodule
Note that the component output is labeled "data" and it is connected to "DATA". With this we want to make clear that the names can be different.
To make the simulation we execute make sim:
$ make sim
This is the result displayed with gtkwave:
We can check that the output is always "1010".
- Change the value in order to output another pattern through the LEDs. Simulate, synthesize, and upload into the FPGA.
- Modify the component so it features a 5-bit bus instead of 4. Output the 5th bit through the 44 pin in the FPGA (this one is not connected to any LED)
TODO
0 You are leaving the privative sector (EN)
1 ¡Hola mundo! (EN) (RU)
2 De un bit a datos (EN)
3 Puerta NOT (EN)
4 Contador de 26 bits (EN)
5 Prescaler de N bits (EN)
6 Múltiples prescalers (EN)
7 Contador de 4 bits con prescaler (EN)
8 Registro de 4 bits (EN)
9 Inicializador (EN)
10 Registro de desplazamiento (EN)
11 Multiplexor de 2 a 1 (EN)
12 Multiplexor de M a 1 (EN)
13 Inicializando registros (EN)
14 Registro de N bits con reset síncrono
15 Divisor de frecuencias
16 Contador de segundos
17 Generando tonos audibles
18 Tocando notas
19 Secuenciando notas
20 Comunicaciones serie asíncronas
21 Baudios y transmisión
22 Reglas de diseño síncrono
23 Controladores y autómatas finitos
24 Unidad de transmisión serie asíncrona
25 Unidad de recepción serie asíncrona
26 Memoria ROM
27 Memoria ROM genérica
28 Memoria RAM
29 Puertas triestado
30 Hacia el microprocesador y más allá