0
\$\begingroup\$

I have the following code:

module one_second(OUT,clk);
output reg [3:0]OUT;
input clk; 
always @(posedge (clk))
begin
 OUT<=4'b1110; //LINE 1
 OUT<=4'b1101; //LINE 2
 OUT<=4'b1011; //LINE 3
 OUT<=4'b0111; //LINE 4
end
endmodule

I want the variable "OUT" to have different values from LINE 1- LINE 4 one by one after each clock pulse. After the 4th pulse it should repeat again.

JRE
75k10 gold badges115 silver badges197 bronze badges
asked Sep 27, 2021 at 11:08
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. \$\endgroup\$ Commented Sep 27, 2021 at 14:39

1 Answer 1

3
\$\begingroup\$

You need to write a state machine, which changes its state at every clock edge. The current state defines the output. This is one of the very fundamental methods in digital hardware design, so you'll find hundreds of guides that tell you how to write a state machine in verilog.

However, in your case, the output progression can be coded more simple by figuring out how to do a circular left shift in Verilog. Since this is just applying basic verilog operators, I don't think giving you an answer how to do that here helps you very much – you'll need to apply it to you code yourself. Here the idea:

NEXT <= (LAST<<1) | LAST[3]

Note that you still need something to set the initial state.

answered Sep 27, 2021 at 11:16
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.