hi...every one...
can anyone help me with a verilog program for counting the number of pulses within a particular time period??say 1 ms..actully i am working on an encoder and i wanted to count its pulses to calculate the speed of my dc motor....
thank you
Can't give you the code, but the algorithm is pretty straight forward.
Have a timer give you a 1 ms wide pulse. Use that pulse as the enable signal for a counter; when the enable goes high, start counting; when the enable goes low, you've got your answer.
Can't give you the code, but the algorithm is pretty straight forward.
Have a timer give you a 1 ms wide pulse. Use that pulse as the enable signal for a counter; when the enable goes high, start counting; when the enable goes low, you've got your answer.
wire clock;
wire reset;
reg [7:0] counter_out;
always@(posedge clock)
begin
a=a-1;
if(a!=1'b0)
begin
if( reset==1'b1)
begin
counter_out<=#1 8'b00000000;
end
else
begin
counter_out<=#1 counter_out+1;
end
end
else
a<=50000
end
endmodule"
the Verilog code you wrote will just count up at each rising edge of the 'clock' signal, irrespective of the frequency of the 'clock' waveform. Is this what you want? Your question seems a little bit different, isn't it?