In: Electrical Engineering
Create a 3-bit counter in verilog that cycles through this sequence, 6,2,4,5,0,7,3,1, with a synchronous rest 4.
State Table
PRESENT STATE |
NEXT STATE |
||||
Q2 |
Q1 |
Q0 |
Q2+ |
Q1+ |
Q0+ |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module counter (clock, reset, Q);
input clock, reset;
output [2:0] Q;
reg [2:0] r;
always @(posedge clock)
begin
if (reset)
r <= 3'b100;
else begin
r[2] <= (~r[1] && ~r[0])
|| (~r[2] && ~r[1]) || (~r[2] && ~r[0]);
r[1] <= ~(r[2] ^ r[1]);
r[0] <= ~(r[1] ^ r[0]);
end
end
assign Q = r;
endmodule
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////