Programming a counter?

Guest #4572384
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
OP #4572424
I have searched Google, and none of it makes any sense.

I need to program a module in Verilog to step through the 
red-green-yellow states of a traffic light on clock pulses.

I don't know how to do this. I don't know how to start.
Guest #4572470
What you have to read is all you can find about "state machines".
You Start your counter when a car arrives, when it reaches its value you 
change the state.
Guest #4572499
The sequence, how a traffic light changes, changes from country to 
country.
So it is impossible to say: The sequence.
The sequence of witch country you mean?
Guest #4572559
Actually this is a pretty common task. What is your problem with the 
results you got?
Do you know the basics of verilog?
Guest #4572870
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
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

A question of your own? This thread is over 10 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.