Forum Discussion
Altera_Forum
Honored Contributor
12 years agoAccording to your diagram, the right code is (without the double register)
if rising_edge(clk) then
if Rst_n='0' then
cs <= '0';
cr <= 0;
else
cs <= ns;
cr <= cr + muxo;
--cr <= nr;
end if;
end if; To improve readability I would pull everything into the process.
if rising_edge(clk) then
if Rst_n='0' then
cs <= '0';
cr <= 0;
else
cs <= not cs;
if cs = '0' then
cr <= cr + D_in;
else
cr <= cr - D_in;
end if;
end if;
end if; P.S.: Different from your code, the diagram seems to suggest an asynchronous reset.