Hi Gabra, sorry say this but I fear you need grasp digital design in deep as i usually told my pupils, error come from everywhere.
A BCD counter never count to 1010 that is ten decimal but remain in BCD domain {0..9} .
You can apply this method to ripple carry asyncronous reset but not to a syncronous counter as your appear to be.
This case require an enable count that happen on last digit value, when counter is 9 then load 0 as next state, at same time enable count on next digit. Your design miss this feature.
I suggest you start learning an HDL language and do this in a more simple fashion using state machine. I am proficient on VHDL and just read and understand Verilog I don't like so much, in HDL your design can be:
signal BCD : Std_Logic_Vector(3 downto 0);
signal enable : Std_Logic := '1'; -- enable count
signal sreset : std logic := '0'; -- reset to 0 clock gated
BCD_counter: process (clock, reset_n)
var count : integer range 0 to 9 := 0;
if reset_n = '0' then
count := 0; -- async reset
else
If rising_edge(clock, reset_n) then
BCD <= Std_Logic_Vector(to_unsigned(count, 4));
if enable = '1' then
if count = 9 or sreset = '1' then
Count := 0;
else
count := count +1;
end if; -- counter
end if; -- enable
end if; -- edge
end if; -- reset
end process;
Regards