Forum Discussion
Altera_Forum
Honored Contributor
12 years agocounting output pulse(project)
Hi everyone, I would like to count the number of pulse outputting to a device, so that ,at some point, i can stop it from outputting. However i dont know how to do that.. I thought of us...
Altera_Forum
Honored Contributor
11 years agoHi Sam,
Please use this as reference. module pulse_atN(Clk, Reset, Pulse, N); parameter WIDTH = 10; input Clk, Reset; input [WIDTH-1:0] N; reg [WIDTH-1:0] Nlast; reg [WIDTH-1:0] Count; output Pulse; assign Pulse = (Count == N-1) && (N != 0); always @ (posedge Clk, posedge Reset) begin : PULSE_GENERATOR if(Reset) Count <= 0; else begin // nonblocking so check occurs with old Nlast Nlast <= N; if(Nlast != N) Count <= 0; else if(Count == N-1) begin Count <= 0; Pulse = 1; end else begin Count <= Count + 1; Pulse = 0; end end end endmodule