contents.gifindex.gif

Creating Counters Using VHDL

The following equations show how to implement up, down, and bidirectional counters:

process (CLK, CLEAR)
begin
if CLEAR='1' then
COUNT <= 0;
elsif CLK='1' and CLK'event then
if LOAD='1' then
COUNT <= DIN;
else
if CE='1' then
if UP='1' then
COUNT <= COUNT + 1;
else
COUNT <= COUNT - 1;
end if;
end if;
end if;
end if;
end process;