Today: Verilog and Sequential Logic Today: Verilog and Sequential - - PDF document

today verilog and sequential logic today verilog and
SMART_READER_LITE
LIVE PREVIEW

Today: Verilog and Sequential Logic Today: Verilog and Sequential - - PDF document

Today: Verilog and Sequential Logic Today: Verilog and Sequential Logic T Flip-f lops S represent at ion of clocks - t iming of st at e changes S asynchronous vs. synchronous T Count ers (St at e Machines) S st ruct ural view (FFs


slide-1
SLIDE 1

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 1

Today: Verilog and Sequential Logic Today: Verilog and Sequential Logic

T Flip-f lops S represent at ion of clocks - t iming of st at e changes S asynchronous vs. synchronous T Count ers (St at e Machines) S st ruct ural view (FFs separat e f rom combinat ional logic) S behavioral view (synt hesis of sequencers) T More Advanced Verilog Feat ures

S $display() and $time() st at ement s

S non-blocking (RTL) assignment

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 2

module dff (CLK, d, q); input CLK, d;

  • utput q;

reg q; always @(CLK) q = d; endmodule

Incorrect Flip-flop in Verilog Incorrect Flip-flop in Verilog

T Use always block' s sensit ivit y list t o wait f or clock t o change

Not correct ! Q will change whenever t he clock changes, not j ust on t he edge.

slide-2
SLIDE 2

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 3

module dff (CLK, d, q); input CLK, d;

  • utput q;

reg q; always @(posedge CLK) q = d; endmodule

Correct Flip-flop in Verilog Correct Flip-flop in Verilog

T Use always block' s sensit ivit y list AND t he posedge keyword t o wait f or clock edge

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 4

module dff (CLK, s, r, d, q); input CLK, s, r, d;

  • utput q;

reg q; always @(posedge CLK) if (r) q = 1'b0; else if (s) q = 1'b1; else q = d; endmodule module dff (CLK, s, r, d, q); input CLK, s, r, d;

  • utput q;

reg q; always @(posedge r) q = 1'b0; always @(posedge s) q = 1'b1; always @(posedge CLK) q = d; endmodule

More Flip-flops More Flip-flops

T Synchronous/ asynchronous reset / set S single t hread t hat wait s f or t he clock S t hree parallel t hreads – only one of which wait s f or t he clock

Synchronous Synchronous Asynchronous Asynchronous

slide-3
SLIDE 3

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 5

module Ctr (CLK, in, out); input CLK; input in;

  • utput
  • ut;

reg

  • ut;

// state variable reg [1:0] state; // local variable reg [1:0] next_state; always @(posedge CLK) // registers state = next_state; always @(state or in) // Compute next_state[1:0] logic (D inputs) whenever state/inputs change. // Make sure state is always assigned to in every execution path! // assign to the outputs endmodule

Verilog Implementation of a Counter (State Verilog Implementation of a Counter (State Machine) Machine)

T General view of a count er or st at e machine in verilog

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 6

module BCDCount (CLK, clear, load, a0, a1); input CLK, reset, in;

  • utput a0, a1;

reg a0, a1; reg [1:0] state; // state variables reg [1:0] next_state; always @(posedge CLK) begin state = next_state; end always @(state or clear or load) begin case (state) 2’b00: next_state = 2’b01; 2’b01: next_state = 2’b10; 2’b10: next_state = 2’b11; 2’b11: next_state = 2’b00; endcase if (clear) next_state = 2’b00; … // handle load end assign a0 = state[0]; assign a0 = state[1]; endmodule

Verilog Verilog BCD Counter Example BCD Counter Example

slide-4
SLIDE 4

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 7

$display and $time statements $display and $time statements

T Document at ion in t he online manual (p. 56) T Doesn’t synt hesize t o anyt hing! T Format s similar t o print f () in C S %h Hex, %d Decimal, %o Octal, %b Binary, %% Display a “%” sign T Examples of $ display() S $display(”output %d is %h", i, vec[i]); S $display("%d%% completed", (count * 100) / max_count); T The $ t ime f unct ion ret urns syst em simulat ion t ime as a 32-bit int eger S $display("Got an event at time %d", $time);

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 8

always @(posedge CLK) begin temp = B; B = A; A = temp; end always @(posedge CLK) begin A <= B; B <= A; end

Blocking and Non-Blocking Assignments Blocking and Non-Blocking Assignments

T Blocking assignment s (X=A) S complet es t he assignment bef ore cont inuing on t o next st at ement T Non-blocking assignment s (X< =A) S complet es in zero t ime and doesn’t change t he value of t he t arget unt il a blocking point (delay/ wait ) is encount ered T Example: swap

slide-5
SLIDE 5

CSE 370 - Spring 1999 - Verilog for Sequential Systems - 9

RTL Assignment RTL Assignment

T Non-blocking assignment is also known as an RTL assignment S if used in an always block t riggered by a clock edge S mimic regist er-t ransf er-level semant ics – all f lip-f lops change t oget her

// B, C, and D all get the value of A always @(posedge clk) begin B = A; C = B; D = C; end // implements a shift operation too always @(posedge clk) begin B <= A; C <= B; D <= C; end // this implements a shift operation always @(posedge clk) begin {D, C, B} = {C, B, A}; end