Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers

Dynamic Counter

Altera_Forum
Honored Contributor II
1,039 Views

Hi, 

Is it possible to load a counter dynamically(run time). The no. of bits to be counted is fixed (16 bit). so Is it possible to change the counter max. value on fly that can lie with in 16 bits. 

 

Thank you
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
337 Views

module my_counter( input clk, input reset_n, input load, input new_count, output reg event ) reg count_val; reg counter; always @(posedge clk) if(load) count_val <= new_count; always @(posedge clk or negedge reset_n) if(!reset_n) counter <= 16'd0; else if(!counter) counter <= count_val; else counter <= counter - 16'd1; endmodule  

 

Jake
0 Kudos
Reply