Verilog Newbie Question

Feb 24, 2004 5 Replies

The following code is my first Verilog program. It's running at 25MHz and that's what the counter is for. I'm trying to accomplish the same thing by shifting bits instead of hard coding the output in case statements. I tried LED>1 to no avail. Any comments and suggestions are appreciated!



Thanks! Kate



module ledbounce(clk, LED); input clk; output [3:0] LED;



reg [19:0] cnt1; reg [2:0] cnt2; reg a, b, c, d; wire cnt1max = (cnt1==1000000);



always @(posedge clk) if(cnt1max) cnt1


by

tried

[snip code]

First, it's worth noting that you are more likely to get an answer on comp.lang.verilog than here - although many of us read both groups.

Second, you can't manipulate output LED as you tried, because it's a wire, not a reg - you declared it correctly as an output, but outputs are wires by default. You need to do the shift operations on the register you've represented as a,b,c,d.

Third, although I can see the sense in your counter arrangement, the second counter is not really necessary - you could use the "bouncing bit" 4-bit register as its own counter.

Fourth, you REALLY need to think about reset strategy - in many FPGA and CPLD devices, flip-flops start life with zero in them, but it's a bad idea to rely on this.

So, here's my suggestion:

(1) Throw away your cnt2 logic and registers a,b,c,d. (2) Make the bouncing-bit counter like this:

reg LeftNotRight; reg [3:0] LED; // This in addition to the output declaration ... always @(posedge clk or posedge reset) if (reset) begin LED

I don't see why what she's done wouldn't work. Her registers a,b,c, and d change at the clock edge and the LED wires are connected to the outputs of the registers.

The only problem I might see is that it runs a bit fast. The "state machine" changes states at 25Hz and it might be hard to see the LEDs blink that quickly.

-Kevin

The code as presented was fine, yes. I was talking about the attempt to set LED > 1, as mentioned at the start of the original post. Sorry I didn't make that clear.

--

Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK Tel: +44 (0)1425 471223 mail: snipped-for-privacy@doulos.com Fax: +44 (0)1425 471573 Web:

formatting link

The contents of this message may contain personal views which are not the views of Doulos Ltd., unless specifically stated.

BEAUTIFUL!!! Thanks Jonathan! This is exactly what I was looking for! I appreciate your response! I'll move my further discussions to comp.lang.verilog.

Thanks again! Kate

and

UK

snipped-for-privacy@doulos.com

formatting link

Thanks much Jonathan!!! Worked like a charm!!! I'll move all further discussions to comp.lang.verilog

Thanks again!

and

UK

snipped-for-privacy@doulos.com

formatting link

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required