diff --git a/libraries/base/dp/src/vhdl/dp_counter_func.vhd b/libraries/base/dp/src/vhdl/dp_counter_func.vhd index 68f51e6475f3f8eaf641dd4682ec35c4c9267756..48674aca67582da8af6ba8b8b687092144e0e9ff 100644 --- a/libraries/base/dp/src/vhdl/dp_counter_func.vhd +++ b/libraries/base/dp/src/vhdl/dp_counter_func.vhd @@ -30,7 +30,7 @@ -- . Faster changing dimensions carry over in slower changing dimensions -- when dimension maximum is reached -- . The outputs are in sync with / apply to src_out. --- . range(0,2,1) = [0, 1] is the smallest count range allowed +-- . range(0,1,1) = [0] is the smallest count range -- Usage: -- . The count values themselves (c0..c4) are very useful to tag streaming -- data with corresponding ID indices. diff --git a/libraries/base/dp/src/vhdl/dp_counter_func_single.vhd b/libraries/base/dp/src/vhdl/dp_counter_func_single.vhd index 1b14612f8eabbd7331bc1e2faf1ad200ae652c4d..a76d3a585bf3c7315a6d91f1564beb9fe5bb5a92 100644 --- a/libraries/base/dp/src/vhdl/dp_counter_func_single.vhd +++ b/libraries/base/dp/src/vhdl/dp_counter_func_single.vhd @@ -94,27 +94,33 @@ BEGIN v.count_max := '0'; v.count_init := '0'; - -- Start counting / init - IF r.count_en='0' AND count_en='1' THEN - v.count_en := '1'; - v.count := TO_UVEC(g_range_start+count_offset, c_count_w); - v.count_min := '1'; - v.count_init := '1'; - - -- keep counting - ELSIF count_en='1' THEN - v.count := INCR_UVEC(r.count, g_range_step); - IF check_max='1' AND r.count = TO_UVEC(c_count_max-g_range_step, c_count_w) THEN -- count max almost reached - v.count_max := '1'; - ELSIF r.count = TO_UVEC(c_count_max, c_count_w) THEN -- count max reached - -- Reset count to start value - v.count := TO_UVEC(g_range_start, c_count_w); + IF count_en='1' THEN + + -- Start counting / init + IF r.count_en='0' THEN + v.count_en := '1'; + v.count := TO_UVEC(g_range_start+count_offset, c_count_w); v.count_min := '1'; + v.count_init := '1'; + -- keep counting + ELSE + v.count := INCR_UVEC(r.count, g_range_step); + IF c_count_max>0 AND check_max='1' AND r.count = TO_UVEC(c_count_max-g_range_step, c_count_w) THEN -- count max almost reached + v.count_max := '1'; + ELSIF r.count = TO_UVEC(c_count_max, c_count_w) THEN -- count max reached + -- Reset count to start value + v.count := TO_UVEC(g_range_start, c_count_w); + v.count_min := '1'; + END IF; END IF; - ELSIF check_max='1' THEN - IF r.count = TO_UVEC(c_count_max, c_count_w) THEN -- count max reached - v.count_max := '1'; - END IF; + + -- If the maximum count is 0, count_max is always high. + IF c_count_max=0 THEN + v.count_max := '1'; + END IF; + + ELSIF check_max='1' AND r.count = TO_UVEC(c_count_max, c_count_w) THEN -- count max reached + v.count_max := '1'; END IF; IF rst = '1' THEN diff --git a/libraries/base/dp/tb/vhdl/tb_dp_counter.vhd b/libraries/base/dp/tb/vhdl/tb_dp_counter.vhd index 9598fd6c7c9917cda22b758356d84637353af3e9..517bb00692919a000e37ab37d8841825d8d966ee 100644 --- a/libraries/base/dp/tb/vhdl/tb_dp_counter.vhd +++ b/libraries/base/dp/tb/vhdl/tb_dp_counter.vhd @@ -52,7 +52,7 @@ ENTITY tb_dp_counter IS g_nof_counters : NATURAL := 3; -- min range = [0,2,1] => (0,1) 'the Python way' g_range_start : t_nat_natural_arr(9 DOWNTO 0) := (0,0,0,0,0,0,0, 1, 0, 0); - g_range_stop : t_nat_natural_arr(9 DOWNTO 0) := (2,2,2,2,2,2,7,16,16,16); + g_range_stop : t_nat_natural_arr(9 DOWNTO 0) := (2,2,2,2,2,2,7,16,16, 1); g_range_step : t_nat_natural_arr(9 DOWNTO 0) := (1,1,1,1,1,1,2, 2, 2, 1) ); END tb_dp_counter;