Trying to implement a freq counter in Verilog. What I need is a clock input, a count output, and a reset input. The behaviour should be like this:
- an internal reg or wire variable counts the clock pulses applied to the clock input
- whenever a reset pulse comes, it should transfer the count value to output to keep there until the next clock pulse comes, and reset the internal variable.
A simple code is given below:
module counter(
input rst,
input clk,
output [31:0] countout
//output [31:0] count
);
wire rst;
wire clk;
reg [31:0] countout=0;
reg [31:0] count=0;
always @ (posedge clk)
begin
count = count + 1'b1;
end
always @ ( posedge rst )
begin
countout = count;
end
always @ ( negedge rst )
begin
count = 0;
end
endmodule
However, Vivado won't allow this as the count variable is a multi-driven net. Apparently, count cannot be changed in 2 different always block. Do you have any idea how I can implement this? Thanks.