Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4-Bit Counter using LEDS

Status
Not open for further replies.

Jimmy Duy Nguyen

Newbie level 1
Newbie level 1
Joined
Sep 6, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
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
 

for one, you have to declare your counter as actually being 4-bits.

Code:
reg [3:0] Counter;

In your current version Counter is a 1-bit counter...

Also, something like this:

Code:
wire divided_stuff;

assign divided_stuff = Counter[3]; // divide by 8

- - - Updated - - -

Also I noticed now you have Counter and clk_div. In the above I have used (or abused) Counter to be the clock divider counter.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top