Figure 10.10. ASM chart for the bit counter.. Figure 10.13. Verilog code for the bit-counting circuit (Part a). module bitcount (Clock, Resetn, LA, s,

Slides:



Advertisements
Similar presentations
Counters Discussion D8.3.
Advertisements

Traffic light contoller using FSM
George Mason University ECE 448 – FPGA and ASIC Design with VHDL ECE 448 Lecture 12 Sorting Example.
Verilog in transistor level using Microwind
CPSC 321 Computer Architecture Andreas Klappenecker
CDA 3100 Recitation Week 11.
Multiplication and Division
Verilog Modules for Common Digital Functions
Table 7.1 Verilog Operators.
FSM Revisit Synchronous sequential circuit can be drawn like below  These are called FSMs  Super-important in digital circuit design FSM is composed.
//HDL Example 6-1 // //Behavioral description of //Universal shift register // Fig. 6-7 and Table 6-3 module shftreg.
FSM examples.
ELEN468 Lecture 101 ELEN 468 Advanced Logic Design Lecture 10 Behavioral Descriptions IV.
Pulse-Width Modulated DAC
1 COMP541 Sequencing and Control Montek Singh Mar 29, 2007.
Logic Design Review – 3 Basic Sequential Circuits Lecture L14.3 Verilog.
Arbitrary Waveform Discussion 12.2 Example 34. Recall Divide-by-8 Counter Use q2, q1, q0 as inputs to a combinational circuit to produce an arbitrary.
Counters Discussion 12.1 Example 33. Counters 3-Bit, Divide-by-8 Counter 3-Bit Behavioral Counter in Verilog Modulo-5 Counter An N-Bit Counter.
2-to-1 Multiplexer: if Statement Discussion D7.1 Example 4.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Registers and Shift Registers Discussion D8.2. D Flip-Flop X 0 Q 0 ~Q 0 D CLK Q ~Q D gets latched to Q on the rising edge of the clock. Positive.
Generic Multiplexers: Parameters Discussion D7.5 Example 8.
Verilog Descriptions of Digital Systems. Electronic Lock // // Electronic combinational lock // module lock(seg7,key, valid_key, col, row, mclk, resetL)
CS/EE 3700 : Fundamentals of Digital System Design
Figure 7.1. Control of an alarm system. Memory element Alarm Sensor Reset Set OnOff 
Verilog Digital System Design Z. Navabi, 2006
CoE3DJ4 Digital Systems Design Register transfers, sequencing and control (from chapters 7 and 8 of Mano and Kime)
Figure A flip-flop with an enable input. D Q Q Q R Clock E 0 1.
Lecture 9 RTL Design Methodology Sorting Example.
Chapter 4: Behavioral Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 4-1 Ders – 4: Davranışsal Modelleme.
George Mason University Design of Controllers Finite State Machines and Algorithmic State Machine (ASM) Charts ECE 545 Lecture 14.
ECE 551 Digital Design And Synthesis
1 ECE 545—Digital System Design with VHDL Lecture 6 Behavioral VHDL Coding (for Synthesis): Finite State Machines and ASMs 9/30/08.
Final Project. System Overview Description of Inputs reset: When LOW, a power on reset is performed. mode: When LOW, NORMal mode selected When HIGH,
Lecture 9 RTL Design Methodology. Structure of a Typical Digital System Datapath (Execution Unit) Controller (Control Unit) Data Inputs Data Outputs Control.
Brief Verilog.
Figure 7.6. Gated SR latch. (a) Circuit Q Q R S R S R Clk Q Q S Time (c) Timing diagram Clk ? ? SR xx Q(t) (no change) 0 1.
Algorithmic State Machines Sorting Signed & Unsigned Data Types
 A test bench is an HDL program used for applying stimulus to an HDL design in order to test it and observe its response during simulation.  In addition.
SYEN 3330 Digital SystemsJung H. Kim 1 SYEN 3330 Digital Systems Chapter 7 – Part 2.
Chapter 6: Hierarchical Structural Modeling Digital System Designs and Practices Using Verilog HDL and 2008~2010, John Wiley 6-1 Chapter 6: Hierarchical.
1 Verilog: Function, Task Verilog: Functions A function call is an operand in an expression. It is called from within the expression and returns a value.
1 (c) W. J. Dally Digital Design: A Systems Approach Lecture 7: Data Path State Machines.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Figure Implementation of an FSM in a CPLD..
Supplement on Verilog FF circuit examples
Supplement on Verilog for Algorithm State Machine Chart
Figure 8.1. The general form of a sequential circuit.
Verilog Modules for Common Digital Functions
Figure 7.1 Control of an alarm system
Behavioral Modeling Structural modeling Behavioral modeling
Supplement on Verilog Sequential circuit examples: FSM
RTL Design Methodology
Lecture 18 SORTING in Hardware.
VHDL (VHSIC Hardware Description Language)
ECE 448 Lecture 13 Multipliers Timing Parameters
ECE 545 Lecture 12 Design of Controllers Finite State Machines and Algorithmic State Machine (ASM) Charts.
ECE 545 Lecture 10 Design of Controllers Finite State Machines and Algorithmic State Machine (ASM) Charts.
ECE 545 Lecture 9 Design of Controllers Finite State Machines and Algorithmic State Machine (ASM) Charts.
RTL Design Methodology Transition from Pseudocode & Interface
Supplement on Verilog Sequential circuit examples: FSM
Register-Transfer Level Components in Verilog
ASM and Micro-programmed State Machines
The Verilog Hardware Description Language
RTL Design Methodology
RTL Design Methodology
RTL Design Methodology
RTL Design Methodology
RTL Design Methodology
RTL Design Methodology
Presentation transcript:

Figure ASM chart for the bit counter.

Figure Verilog code for the bit-counting circuit (Part a). module bitcount (Clock, Resetn, LA, s, Data, B, Done); input Clock, Resetn, LA, s; input [7:0] Data; output [3:0] B; output Done; wire [7:0] A; wire z; reg [1:0] Y, y; reg [3:0] B; reg Done, EA, EB, LB; // control circuit parameter S1 = 2'b00, S2 = 2'b01, S3 = 2'b10; or y or z) begin: State_table case (y) S1:if (!s) Y = S1; else Y = S2; S2:if (z == 0) Y = S2; else Y = S3; S3:if (s) Y = S3; else Y = S1; default: Y = 2'bxx; endcase end Clock or negedge Resetn) begin: State_flipflops if (Resetn == 0) y <= S1; else y <= Y; end … continued in Part b.

or A[0]) begin: FSM_outputs // defaults EA = 0; LB = 0; EB = 0; Done = 0; case (y) S1:LB = 1; S2:begin EA = 1; if (A[0]) EB = 1; else EB = 0; end S3:Done = 1; endcase end // datapath circuit // counter B Resetn or posedge Clock) if (!Resetn) B <= 0; else if (LB) B <= 0; else if (EB) B <= B + 1; shiftrne ShiftA (Data, LA, EA, 0, Clock, A); assign z = ~| A; endmodule Figure Verilog code for the bit-counting circuit (Part b).

Figure ASM chart for the multiplier.

Figure Datapath circuit for the multiplier.

Figure ASM chart for the multiplier control circuit.

module multiply (Clock, Resetn, LA, LB, s, DataA, DataB, P, Done); parameter n = 8; input Clock, Resetn, LA, LB, s; input [n-1:0] DataA, DataB; output [n+n-1:0] P; output Done; wire z; reg [n+n-1:0] A, DataP; wire [n+n-1:0] Sum; reg [1:0] y, Y; reg [n-1:0] B; reg Done, EA, EB, EP, Psel; integer k; // control circuit parameter S1 = 2'b00, S2 = 2'b01, S3 = 2'b10; or y or z) begin: State_table case (y) S1:if (s == 0) Y = S1; else Y = S2; S2:if (z == 0) Y = S2; else Y = S3; S3:if (s == 1) Y = S3; else Y = S1; default: Y = 2'bxx; endcase end Clock or negedge Resetn) begin: State_flipflops if (Resetn == 0) y <= S1; else y <= Y; end … continued in Part b. Figure Verilog code for the multiplier circuit (Part a).

or y or B[0]) begin: FSM_outputs // defaults EA = 0; EB = 0; EP = 0; Done = 0; Psel = 0; case (y) S1:EP = 1; S2: begin EA = 1; EB = 1; Psel = 1; if (B[0]) EP = 1; else EP = 0; end S3:Done = 1; endcase end //datapath circuit shiftrne ShiftB (DataB, LB, EB, 0, Clock, B); defparam ShiftB.n = 8; shiftlne ShiftA ({{n{1'b0}}, DataA}, LA, EA, 0, Clock, A); defparam ShiftA.n = 16; assign z = (B == 0); assign Sum = A + P; // define the 2n 2-to-1 multiplexers or Sum) for (k = 0; k < n+n; k = k+1) DataP[k] = Psel ? Sum[k] : 0; regne RegP (DataP, Clock, Resetn, EP, P); defparam RegP.n = 16; endmodule Figure Verilog code for the multiplier circuit (Part b).

Figure ASM chart for the divider. RB  ? R0  C n1–   s 01 S1 S2 0 Load A Load B Shift left R||A CC1  Shift 0 into Q Shift 1 into Q RRB  C0= ? 1 10 S3 Reset Done S4 0 1 s – –

Figure ASM chart for the divider control circuit.

Figure ASM chart for the enhanced divider control circuit.

Figure Datapath circuit for the enhanced divider.

module divider (Clock, Resetn, s, LA, EB, DataA, DataB, R, Q, Done); parameter n = 8, logn = 3; input Clock, Resetn, s, LA, EB; input [n-1:0] DataA, DataB; output [n-1:0] R, Q; output Done; wire Cout, z; wire [n-1:0] DataR; wire [n:0] Sum; reg [1:0] y, Y; reg [n-1:0] A, B; reg [logn-1:0] Count; reg Done, EA, Rsel, LR, ER, ER0, LC, EC, R0; integer k; // control circuit parameter S1 = 2'b00, S2 = 2'b01, S3 = 2'b10; or y or z) begin: State_table case (y) S1:if (s == 0) Y = S1; else Y = S2; S2:if (z == 0) Y = S2; else Y = S3; S3:if (s == 1) Y = S3; else Y = S1; default: Y = 2'bxx; endcase end Clock or negedge Resetn) begin: State_flipflops if (Resetn == 0) y <= S1; else y <= Y; end … continued in Part b. Figure Verilog code for the divider circuit (Part a).

Figure Verilog code for the divider circuit (Part b). or s or Cout or z) begin: FSM_outputs // defaults LR = 0; ER = 0; ER0 = 0; LC = 0; EC = 0; EA = 0; Rsel = 0; Done = 0; case (y) S1:begin LC = 1; ER = 1; if (s == 0) begin LR = 1; ER0 = 0; end else begin LR = 0; EA = 1; ER0 = 1; end S2:begin Rsel = 1; ER = 1; ER0 = 1; EA = 1; if (Cout) LR = 1; else LR = 0; if (z == 0) EC = 1; else EC = 0; end S3:Done = 1; endcase end

//datapath circuit regne RegB (DataB, Clock, Resetn, EB, B); defparam RegB.n = n; shiftlne ShiftR (DataR, LR, ER, R0, Clock, R); defparam ShiftR.n = n; muxdff FF_R0 (0, A[n-1], ER0, Clock, R0); shiftlne ShiftA (DataA, LA, EA, Cout, Clock, A); defparam ShiftA.n = n; assign Q = A; downcount Counter (Clock, EC, LC, Count); defparam Counter.n = logn; assign z = (Count == 0); assign Sum = {R, R0} + (~B + 1); assign Cout = Sum[n]; // define the n 2-to-1 multiplexers assign DataR = Rsel ? Sum : 0; endmodule Figure Verilog code for the divider circuit (Part c).

Figure An algorithm for finding the mean of k numbers. Sum =0 ; for i=k1 downto 0 do Sum = +R ; i endfor; M = Sum ÷k ; (a)Pseudo-code (b)ASMchart Sum0  Ck1– , s 0 1 S1 S2 Done s Reset 1 0 Sum R i +  S4 C0= ? MSumk  CC1–  0 1 S3 Load registers –

Figure Datapath circuit for the mean operation.

Figure ASM chart for the mean operation control circuit.

Figure ASM chart for the sort operation.

Figure ASM chart for the control circuit.

Figure Verilog code for the sorting circuit (Part a). module sort (Clock, Resetn, s, WrInit, Rd, DataIn, RAdd, DataOut, Done); parameter n = 4; input Clock, Resetn, s, WrInit, Rd; input [n-1:0] DataIn; input [1:0] RAdd; output [n-1:0] DataOut; output Done; wire [1:0] Ci, Cj, CMux, IMux; wire [n-1:0] R0, R1, R2, R3, A, B, RData, ABMux; wire BltA, zi, zj; reg Int, Csel, Wr, Ain, Bin, Aout, Bout; reg LI, LJ, EI, EJ, Done, Rin0, Rin1, Rin2, Rin3; reg [3:0] y, Y; reg [n-1:0] ABData; // control circuit parameter S1 = 4'b0000, S2 = 4'b0001, S3 = 4'b0010, S4 = 4'b0011; parameter S5 = 4'b0100, S6 = 4'b0101, S7 = 4'b0110, S8 = 4'b0111, S9 = 4'b1000; or BltA or zj or zi) begin: State_table case (y) S1:if (s == 0) Y = S1; else Y = S2; S2: Y = S3; S3: Y = S4; S4: Y = S5; S5:if (BltA) Y = S6; else Y = S8; S6: Y = S7; S7: Y = S8; S8:if (!zj) Y = S4; else if (!zi) Y = S2; else Y = S9; S9:if (s) Y = S9; else Y = S1; default: Y = 4'bx; endcase end …continued in Part b.

Clock or negedge Resetn) begin: State_flipflops if (Resetn == 0) y <= S1; else y <= Y; end or zj or zi) begin: FSM_outputs // defaults Int = 1; Done = 0; LI = 0; LJ = 0; EI = 0; EJ = 0; Csel = 0; Wr = 0; Ain = 0; Bin = 0; Aout = 0; Bout = 0; case (y) S1:begin LI = 1; Int = 0; end S2: begin Ain = 1; LJ = 1; end S3:EJ = 1; S4:begin Bin = 1; Csel = 1; end S5:; // no outputs asserted in this state S6:begin Csel = 1; Wr = 1; Aout = 1; end S7:begin Wr = 1; Bout = 1; end S8:begin Ain = 1; if (!zj) EJ = 1; else begin EJ = 0; if (!zi) EI = 1; else EI = 0; end S9:Done = 1; endcase end …continued in Part c. Figure Verilog code for the sorting circuit (Part b).

//datapath circuit regne Reg0 (RData, Clock, Resetn, Rin0, R0); defparam Reg0.n = n; regne Reg1 (RData, Clock, Resetn, Rin1, R1); defparam Reg1.n = n; regne Reg2 (RData, Clock, Resetn, Rin2, R2); defparam Reg2.n = n; regne Reg3 (RData, Clock, Resetn, Rin3, R3); defparam Reg3.n = n; regne RegA (ABData, Clock, Resetn, Ain, A); defparam RegA.n = n; regne RegB (ABData, Clock, Resetn, Bin, B); defparam RegB.n = n; assign BltA = (B < A) ? 1 : 0; assign ABMux = (Bout == 0) ? A : B; assign RData = (WrInit == 0) ? ABMux : DataIn; upcount OuterLoop (0, Resetn, Clock, EI, LI, Ci); upcount InnerLoop (Ci, Resetn, Clock, EJ, LJ, Cj); assign CMux = (Csel == 0) ? Ci : Cj; assign IMux = (Int == 1) ? CMux : RAdd; …continued in Part d. Figure Verilog code for the sorting circuit (Part c).

or Wr or IMux) begin case (IMux) 0: ABData = R0; 1: ABData = R1; 2: ABData = R2; 3: ABData = R3; endcase if (WrInit || Wr) case (IMux) 0: {Rin3, Rin2, Rin1, Rin0} = 4'b0001; 1: {Rin3, Rin2, Rin1, Rin0} = 4'b0010; 2: {Rin3, Rin2, Rin1, Rin0} = 4'b0100; 3: {Rin3, Rin2, Rin1, Rin0} = 4'b1000; endcase else {Rin3, Rin2, Rin1, Rin0} = 4'b0000; end assign zi = (Ci == 2); assign zj = (Cj == 3); assign DataOut = (Rd == 0) ? 'bz : ABData; endmodule Figure Verilog code for the sorting circuit (Part d).

Figure Simulation results for the sort operation. (a) Loading the registers and starting the sort operation (b) Completing the sort operation and reading the registers