-
Notifications
You must be signed in to change notification settings - Fork 195
Chapter 11: 2 to 1 multiplexor
Examples of this chapter on github
The multiplexers are combinational circuts that allow us to select from multiple data sources. In this chapter we will use a multiplexer of 2 to 1 to select between 2 sequences to display on the LEDs and alternate between them.
A 2 to 1 multipleser selects between 2 data sources according to the value of its sel selection input. If sel is 0, source 0 is output, if 1 then the source 1 is used.
We can describe multiplexers in Verilog using the if ... else statement:
always @(source0 or source1 or sel)
if (sel == 0)
dout <= source0;
else
dout <= source1;
It is every importnat that there is the else. Because this is a combinational circuit, all cases must be covered. If they are not, you will infer a latch. It is also very important for simulation to palce all the input signal into the sensitivity list: source0, source1, and sel.
The sensitivity list can be written abbreviated with the argument @ *
always @*
This list automatically includes all input signals.
As an example use case, we will make a 2-state sequencer: a circuit that alternately sends two nibbles (4-bits) to the LEDs. The schematic of the circuit is as follows:
Two fixed data sources are used (they are wired to fixed values) that determine the status of the LEDs at any given time. The multiplexer selects alternatively between one and another through a clock signal that passes through a presaler (to reduce the fequency so we can appreciate the toggling of the LEDs).
The verilog code is as follows:
//-- mux2.v
module mux2(input wire clk, output reg [3:0] data);
//-- Parametros del secuenciador:
parameter NP = 22; //-- Bits del prescaler
parameter VAL0 = 4'b1010; //-- Valor secuencia 0
parameter VAL1 = 4'b0101; //-- Valor secuencia 1
//-- wires of the three inputs of the multiplexer
wire [3:0] val0;
wire [3:0] val1;
wire sel;
//-- for the inputs of the mux we wire the input data;
assign val0 = VAL0;
assign val1 = VAL1;
//-- Implementation of the multiplexer
always @(sel or val0 or val1)
if (sel==0)
data <= val0;
else
data <= val1;
//-- Prescaler to control the select signal of the multiplexer
prescaler #(.N(NP))
PRES (
.clk_in(clk),
.clk_out(sel)
);
endmodule
The implementation of the multiplexer is simple so it is included directly in a process instead of defining it in a seperate file and then instantiating it (hierarchical design).
To synthesize the design into the FPGA we will connect the data outputs to the LEDs, and the clock input to the iCEstick board.
Synthesize with the command:
$ make sint
The resources used are:
Resource | utilization |
---|---|
PIOs | 3 / 96 |
PLBs | 7 / 160 |
BRAMs | 0 / 16 |
to load in the FPGA we execute:
$ sudo iceprog mux2.bin
In this Youtube video you can see the output of the LEDs:
The simulation is basic, with an instantiation of the sequncer (passing in 1 for the prescaler parameter) and a simple clock and initialization process. It is for visual inspection of the output.
The simulation is done with:
$ make sim
The result in gtkwave is:
We see how the two outputs are alternating: 1010 and 0101 alternately, each associated with a level of the sel signal which comes from the clock.
- Exercise 1: Change the input values of the multiplexer to output another different sequence by the FPGA.
- Exercise 2: Write a self checking testbench
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á