Jimmy Duy Nguyen
Newbie level 1
- Joined
- Sep 6, 2013
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 11
I am trying to build a 4-bit counter using LEDS. The count should update about every second. The up and down buttons on the board to control the direction of the count. The clock frequency is 100MHz therefore a clock divider should be used to slow it down. I am confused on how to implement the actual clock divider, I believe that I have the counter correct. The code I have is as follows:
module Switch2(
output [3:0] LEDS,
input Reset,
input UP,
input DOWN,
input CLOCK
);
assign LEDS[3:0] = CLOCK;
reg Counter;
reg clk_div;
always@(posedge Reset or posedge CLOCK)
begin
if (Reset)
Counter <= 0;
else if (UP)
Counter = Counter + 1;
else
Counter = Counter - 1;
end
endmodule
module clk_div(
input Reset,
input CLOCK,
input UP,
input DOWN
output clk_1);
always@(posedge Reset or posedge CLOCK)
begin
counter <= counter + 1'b1
endmodule
module Switch2(
output [3:0] LEDS,
input Reset,
input UP,
input DOWN,
input CLOCK
);
assign LEDS[3:0] = CLOCK;
reg Counter;
reg clk_div;
always@(posedge Reset or posedge CLOCK)
begin
if (Reset)
Counter <= 0;
else if (UP)
Counter = Counter + 1;
else
Counter = Counter - 1;
end
endmodule
module clk_div(
input Reset,
input CLOCK,
input UP,
input DOWN
output clk_1);
always@(posedge Reset or posedge CLOCK)
begin
counter <= counter + 1'b1
endmodule