Presentation is loading. Please wait.

Presentation is loading. Please wait.

Registers and Shift Registers Discussion D8.2. D Flip-Flop 0 0 1 1 1 0 X 0 Q 0 ~Q 0 D CLK Q ~Q D gets latched to Q on the rising edge of the clock. Positive.

Similar presentations


Presentation on theme: "Registers and Shift Registers Discussion D8.2. D Flip-Flop 0 0 1 1 1 0 X 0 Q 0 ~Q 0 D CLK Q ~Q D gets latched to Q on the rising edge of the clock. Positive."— Presentation transcript:

1 Registers and Shift Registers Discussion D8.2

2 D Flip-Flop 0 0 1 1 1 0 X 0 Q 0 ~Q 0 D CLK Q ~Q D gets latched to Q on the rising edge of the clock. Positive edge triggered

3 A 1-Bit Register

4 If LOAD = 1, then INP0 gets latched to Q0 on the rising edge of the clock, CLK

5 A 4-Bit Register

6 Implementing Registers in Verilog //A 4-bit register with asynchronous clear and load module reg4(Clk,Clear,Load,D,Q); input [3:0] D; input Clk,Clear,Load; output [3:0] Q; reg [3:0] Q; always @(posedge Clk or posedge Clear) if(Clear == 1) Q <= 0; else if(Load) Q <= D; endmodule

7 4-Bit Shift Register

8 shift4.v module ShiftReg(clk,clr,data_in,Q); input clk; input clr; input data_in; output [3:0] Q; reg [3:0] Q; // 4-bit Shift Register always @(posedge clk or posedge clr) begin if(clr == 1) Q <= 0; else begin Q[3] <= data_in; Q[2:0] <= Q[3:1]; end endmodule Note non-blocking assignment

9 shift4 simulation

10 Ring Counter

11 ring4.v module ring4(clk,clr,Q); input clk; input clr; output [3:0] Q; reg [3:0] Q; // 4-bit Ring Counter always @(posedge clk or posedge clr) begin if(clr == 1) Q <= 1; else begin Q[3] <= Q[0]; Q[2:0] <= Q[3:1]; end endmodule

12 ring4 simulation

13 Johnson Counter

14 module johnson4(clk,clr,Q); input clk; input clr; output [3:0] Q; reg [3:0] Q; // 4-bit Johnson Counter always @(posedge clk or posedge clr) begin if(clr == 1) Q <= 0; else begin Q[3] <= ~Q[0]; Q[2:0] <= Q[3:1]; end endmodule johnson4.v

15 Johnson Counter

16 A Random Number Generator

17 Q3 Q2 Q1 Q0 0 0 0 1 1 1 0 0 0 8 1 1 0 0 C 1 1 1 0 E 1 1 1 1 F 0 1 1 1 7 1 0 1 1 B 0 1 0 1 5 Q3 Q2 Q1 Q0 1 0 1 0 A 1 1 0 1 D 0 1 1 0 6 0 0 1 1 3 1 0 0 1 9 0 1 0 0 4 0 0 1 0 2 0 0 0 1 1

18 module rand4(clk,clr,Q); input clk; input clr; output [3:0] Q; reg [3:0] Q; // 4-bit Random number generator always @(posedge clk or posedge clr) begin if(clr == 1) Q <= 1; else begin Q[3] <= Q[3] ^ Q[0]; Q[2:0] <= Q[3:1]; end endmodule rand4.v

19 A Random Number Generator

20 clk inp Q2 Q0 Q1 outp Clock Pulse

21 module clk_pulse(clk,clr,inp,outp); input clk; input clr; input inp; output outp; wire outp; reg [2:0] Q; // clock pulse generator always @(posedge clk or posedge clr) begin if(clr == 1) Q <= 0; else begin Q[2] <= inp; Q[1:0] <= Q[2:1]; end assign outp = Q[2] & Q[1] & ~Q[0]; endmodule clk_pulse.v

22 clk inp Q2 Q0 Q1 outp


Download ppt "Registers and Shift Registers Discussion D8.2. D Flip-Flop 0 0 1 1 1 0 X 0 Q 0 ~Q 0 D CLK Q ~Q D gets latched to Q on the rising edge of the clock. Positive."

Similar presentations


Ads by Google