Professional Documents
Culture Documents
Verilog RTL Modeling Serial Communication: Encoding
Verilog RTL Modeling Serial Communication: Encoding
3/25/2003 BR 1 3/25/2003 BR 2
1
Serializer Module
The Task
• Should wait until start is asserted
• You are to design the serializer module (in file ser.v) using
• Send value on din serially over sout
Verilog RTL
– May need several modules within file ser.v, top level module is • Request new value on din by asserting d_rdy
called serializer and has the interface shown – In testbench, there is a clock cycle latency between assertion of
– Your ser.v code must be synthesizeable d_rdy and a new din value being provided
• I have designed deserializer module (in file deser.v) and • Continually send serial data until reset is asserted.
testbench (tbser.v). • Main clock is signal clk. The serial clock is serclk which
– Testbench connects the serializer/deserializer modules together has 1 clock pulse for every 4 pulses on clk.
– Also sends 32 bytes to serializer/deserializer for testing purposes – New serial data should be provided for every pulse on serclk.
– Both clk and serclk provided by testbench.
3/25/2003 BR 7 3/25/2003 BR 8
If last bit = this bit, then Finite State Machine for desnrz
NRZI Decode
output a ‘1’ else ‘0’.
module desnrz (sout,newbit,clk, reset,sin);
equal sin_nrz
sin_nrzi newbit is output sout,newbit;
D Q
D Q en asserted input clk,reset,sin; reg declaration required
en LD anytime a signal is assigned a
LD when reg l_sin,en,sout,newbit;
newbit sin_nrz has reg [2:0] state,nstate; value from an assignment
D Q valid data. `define S0 'b000 statement in a procedure
S0 `define S1 'b001 block.
`define S2 'b010
sin_nrzi `define S3 'b011 Does not imply that a
S1 S0 is reset state. Sin_nrzi = 0 is start `define S4 'b100
en ‘register’ will be synthesized
of transmission (idle state is ‘1’, a ‘0’ `define S5 'b101
`define S6 'b110
S2 bit is always transmitted first). `define S7 'b111
2
Procedural block for FSM state storage Triggered on rising edge of Combinational Block Triggered on any changes to
clock, so outputs will have state or sin
always @(posedge clk) begin always @(state or sin) begin
if (reset) begin
a rising-edge DFF nstate = state; Default output assignments
state <= `S0; synthesized. en = 0;
(en negated, stay in same
l_sin <= 1; case (state)
sout <= 1; `S0: // wait for start edge state)
end
Synchronous reset if (!sin) nstate = `S1;
else state <= nstate; `S1: begin
newbit <= 0;
en asserted by FSM en = 1; nstate = `S2;
end
logic every 4 clocks
if (en) begin `S2: nstate = `S3; Need begin/end if more
if (l_sin != sin) sout = 0; since we know serial `S3: nstate = `S4;
else sout <= 1; than one statement in
clock is ¼ clock freq. `S4: nstate = `S1;
newbit <= 1; block.
l_sin <= sin; default: nstate = `S0;
endcase
end
l_sin is last serial input. If last serial input not equal end
end
to current serial input, then was a ‘0’ value. If the last endmodule
serial bit is equal to current bit, then a ‘1’. The newbit
asserted to indicate a valid serial output bit.
3/25/2003 BR 13 3/25/2003 BR 14
3/25/2003 BR 17 3/25/2003 BR 18
3
Deserializer module – connects other modules together
Asynchronous vs Synchronous Inputs
module deserializer (dout, clk, reset, sin);
output [7:0] dout;
input clk, reset, sin; Must explicitly declare the reg q; Synchronous reset,
wire [2:0] bitcnt; widths of any wires whose always @(posedge clk) begin high true
if (r) q <= 0;
wire [7:0] sdout;
wire [7:0] dout;
width is not 1. (default else q <= d;
width is 1).
module tbser;
Clock generation
reg clk,reset,start; Declaration of wires
wire [7:0] din; always #(200/2) clk = ~clk;
wire [4:0] addr;
with non-default widths
serclkgen u_serclk (serclk, clk, reset);
wire [7:0] dout; serializer u_ser (sout, d_rdy, din, clk,serclk,reset, start);
reg [7:0] last_dout; deserializer u_des (dout, clk, reset, sout);
initial begin Any block with ‘initial’ cnt5 u_cnt5 (addr, clk, reset, d_rdy);
clk = 0; keyword only executed rom u_rom (din, addr);
reset = 1; once.
start = 0; ‘serclkgen’ module generates serial clock.
last_dout = 'h00;
end ‘rom’, ‘cnt5’ used to generate 8-bit input values to serializer
module (‘rom’ provides data values, ‘cnt5’ is 5-bit counter
that provides address to ‘rom’ module. ‘cnt5’ incremented
anytime that ‘d_rdy’ is asserted.
3/25/2003 BR 21 3/25/2003 BR 22