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.

Help --> COUNTER WORKING

Status
Not open for further replies.

sameem_shabbir

Advanced Member level 4
Joined
Jan 5, 2008
Messages
104
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
Pakistan
Activity points
1,946
I am using Spartan 3 starter kit board.
I made a counter in verilog
The counter output is not true i.e. it counts its own counting not 1 2 3 4 ...
I connected the output to leds and the input clock to the slider button. I t was not working properly.
Is there any problem in my code. Plz help
CODE
module counter(load, p, clk, q);
parameter n = 2;
input load;
input [n-1:0] p;
input clk;
output [n-1:0] q;
reg [n-1:0] q;

always @(posedge clk)
if (load)
q = p;
else
q = q + 1;
endmodule


Plz help
 

You must debounce the slide switch (or push button), or else you will get many clock pulses each time you move the switch.

For synchronous logic, you should use non-blocking "<=" assignments instead of blocking "=" assignments.
 

I could not understand DEBOUNCE
Do u mean to say that as long as the switch is in 1 position it will get many clk pulses??
or else
 

the debounce is like when you change the slider or push button connected to clk, there are up and down (if you look at the waveform) on the clk signal and it might trigger many clk edges...

so the easy way is to make a wait for few milisecond for the signal to stable down before your system read another clk edge...

use state machine with 2 or multiple inputs will solve the bouncing signal. one input trigger an increment and only another input can trigger another increment...

using microcontroller is simpler, just hold the system for a period of time for signal to stable down then increment...

just my opinion, other might have better one...
 
Salam Sameem!!

Is this problem solved ????

I hope it would have been!!!!!!!


What u need the counter for ???

Do u want it to initialize it with load signal

and then count on every clock cycle??

or u want it to increment everyy tiem u assert load

The present code I hope will start once u assert load

and then keep counting for ever

To u it should look like a Haphazard or a Random Counter

bcoza it will be running at 50 Mhz or whatever the frequency u are using
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top