저는 ModelSim에서 VHDL을 배우기 시작했습니다. 그래서 내가하고있는 일이 정말로 멍청한 것 같으면 미리 사과드립니다."if-statement"가 적은 VHDL 코드에서 BCD_counter를 다시 작성하는 더 좋은 방법이 있습니까?
기본적으로 내가 만들려고하는 것은 한자리 위/아래 BCD 카운터에 대한 합성 VHDL 코드입니다. 카운터는 "Enable"이 '1'일 때 카운트하거나 그렇지 않으면 카운터가 유지됩니다. 입력 "Init"가 초기화되면 카운터는 "Direction"입력의 값에 따라 0 또는 9로 설정됩니다. ("Direction"이 '1'일 때, 그것은 up counter 임).
100 개의 if 및 else 행을 사용하는 것 이외의 다른 작업에 사용할 수있는 더 좋은 도구가 있는지 궁금합니다.
여기에 제 코드가 있습니다. 지금 당장 테스트 벤치를 작성 중이므로 아직 제대로 작동하는지 확실하지 않습니다. 그래서 실수를 저지른 경우 나에게 지적하십시오. 여기
감사합니다 사전에 많이, 그리고 내 코드입니다
entity BCD_counter is
port(clk, direction, init, enable: in bit;
q_out: out integer);
end entity BCD_counter;
architecture behaviour of BCD_counter is
signal q: integer;
begin
process(clk)
begin
if(Clk'event and Clk = '1') then
if(direction = '1') then -- counting up
if(init = '1')then --initialize
q<=0; -- reset to 0
else
if(enable = '1')then -- counting
if (q<9) then
q<=q+1;
else
q<=0;
end if;
else
q<=q;
end if;
end if;
elsif(direction = '0') then --counting down
if(init = '1') then --initialize
q<=9; --reset to 9
else
if(enable = '1') then --counting
if (q>0) then
q<=q-1;
else
q<=9;
end if;
else
q<=q;
end if;
end if;
end if;
end if;
end process;
q_out <= q;
end architecture behaviour;