K
Kate Smith
Guest
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<=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 <= 0;
else
cnt1 <= cnt1 +1;
always @(posedge clk)
if(cnt1max)
begin
if(cnt2==5)
cnt2<=0;
else
cnt2<=cnt2+1;
end
always @(posedge clk)
begin
case(cnt2)
0 : begin
a = 1;
b = 0;
c = 0;
d = 0;
end
1 : begin
a = 0;
b = 1;
c = 0;
d = 0;
end
2 : begin
a = 0;
b = 0;
c = 1;
d = 0;
end
3 : begin
a = 0;
b = 0;
c = 0;
d = 1;
end
4 : begin
a = 0;
b = 0;
c = 1;
d = 0;
end
5 : begin
a = 0;
b = 1;
c = 0;
d = 0;
end
endcase
end
assign LED[0] = a;
assign LED[1] = b;
assign LED[2] = c;
assign LED[3] = d;
endmodule
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<=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 <= 0;
else
cnt1 <= cnt1 +1;
always @(posedge clk)
if(cnt1max)
begin
if(cnt2==5)
cnt2<=0;
else
cnt2<=cnt2+1;
end
always @(posedge clk)
begin
case(cnt2)
0 : begin
a = 1;
b = 0;
c = 0;
d = 0;
end
1 : begin
a = 0;
b = 1;
c = 0;
d = 0;
end
2 : begin
a = 0;
b = 0;
c = 1;
d = 0;
end
3 : begin
a = 0;
b = 0;
c = 0;
d = 1;
end
4 : begin
a = 0;
b = 0;
c = 1;
d = 0;
end
5 : begin
a = 0;
b = 1;
c = 0;
d = 0;
end
endcase
end
assign LED[0] = a;
assign LED[1] = b;
assign LED[2] = c;
assign LED[3] = d;
endmodule