Programming a counter?

Guest #4572384
Rate this post
useful
not useful
You also neglected all the other information you could provide so 
someone can help you.

What don't you know?
What did you try?
What did not work?

Do you have sample code you wrote?
You didn't even post the complete task description, so even
if someone would want to help you without you doing any prior work or 
having thoughts nobody could do it.

You already mentioned all keywords to google.
"State Machine", "Verilog", "Module", "Testbench".

Sorry, I do not intend to offend or insult you, it is just that you
insult some people in treating their time so invaluable so they have to 
do all the thinking you are supposed to do.

Best Regards
Guest #4572870
Rate this post
useful
not useful
It is hard to help you from an unknown state of knowledge.
Do you know the basics of digital design? Do you know verilog?

Maybe a first step to get the task out of your mind and on paper.
Go to Wikipedia and search for "Finite-state machine".
Go to point 1, have a look at the example and try
to draw, write or somehow formulate the task. I always
like and recommend a state diagram.

When you have that formulated you should have a look into the basics
of verilog. With the keywords "state machine" and "verilog" you should 
be able to finde pleeeeenty of examples. Transfer your diagram into one
of those. Voila! Doesn't seem so hard, does it?

Good luck, and if you have any specific questions you are welcome to ask 
again. (Just try to solve it on your own first, problem solving is a 
very important skill)
OP #4573753
Rate this post
useful
not useful
Thanks for giving me someplace to start. :)

I got some code down (attached), but it's not doing what I thought it 
would.

Specifically, this part:
1
if (Y == 1) begin
2
  repeat (2) begin
3
  @ (posedge clk)
4
  highway = 3'b010; gravel = 3'b100;
5
  end
6
  repeat (3) begin
7
  @ (posedge clk)
8
  highway = 3'b100; gravel = 3'b001;
9
  end
10
  repeat (2) begin
11
  @ (posedge clk)
12
  highway = 3'b100; gravel = 3'b010;
13
  end
14
  begin
15
  @ (posedge clk)
16
  highway = 3'b001; gravel = 3'b100;
17
  end
18
end

What I wanted it to do was sit for two clock pulses, change the lights, 
sit for three pulses, change the lights, and so on. What happens in my 
testbench is that it changes once, and then the simulation ends after 
the next pulse.

Thanks again.
Attached files:

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now