การสร้างวงจรจากโลจิกเกท และสเตทไดอะแกรม ด้วย VHDL

1. จากแผนภาพลอจิกต่อไปนี้ จงเขียนโมเดล VHDL

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity no1 is

port (A, B, C, clk: in std_logic;

Q : out std_logic);

end no1;

architecture beh of no1 is

signal q1,q2 : std_logic;

begin

PROCESS (clk)

BEGIN

IF(CLK'EVENT and CLK = '1') THEN

q1 <= C;

q2 <= B and q1;

ELSE

q1 <= q1;

q2 <= q2;

END IF;

END PROCESS;

Q <= q2 and A;

end beh;

-------------------------------------------------------------------------------------------------------------------------

2.จากแผนภาพลอจิกต่อไปนี้ จงเขียนโมเดล VHDL

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity no2 is

port (xin, reset, clk: in std_logic;

yout : out std_logic);

end no2;

architecture beh of no2 is

signal q1,q2 : std_logic;

begin

PROCESS (clk)

BEGIN

IF(CLK'EVENT and CLK = '1') THEN

IF reset = '0' THEN

q1 <= '0';

q2 <= '0';

ELSE

q1 <= xin xor (not q2);

q2 <= xin or q1;

END IF;

ELSE

q1 <= q1;

q2 <= q2;

END IF;

END PROCESS;

yout <= q2;

end beh;

-------------------------------------------------------------------------------------------------------------------------

3.จากสเตทไดอะแกรมต่อไปนี้ จงเขียนโมเดล VHDL แบบเอาท์พุทไม่มีสัญญาณนาฬิกา

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity no3 is

port (x, clk: in std_logic;

z : out std_logic);

end no3;

architecture moore_beh of no3 is

type state_type is (a, b, c, d);

signal state: state_type;

begin

state_proc: process (clk)

begin

if clk = '1' and clk'event then

case state is

when a => if x = '1' then state <= b;

else state <= a;

end if;

when b => if x = '1' then state <= c;

else state <= a;

end if;

when c => if x = '1' then state <=c;

else state <= d;

end if;

when d => if x = '1' then state <= b;

else state <= a;

end if;

end case;

end if;

end process;

output_proce: process (state)

begin

case state is

when a => z <= '0';

when b => z <= '1';

when c => z <= '0';

when d => z <= '1';

end case;

end process;

end moore_beh;

-------------------------------------------------------------------------------------------------------------------------

4. จงเขียนโมเดล VHDL ของวงจรหารความถี่ กำหนดให้สัญญาณอินพุท Fin มีความถี่ 10 MHz และสัญญาณเอาท์พุท Fout มีความถี่ 2.5 MHz

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity no4 is

port ( Fin: in std_logic;

Fout : out std_logic);

end no4;

architecture div4_beh of no4 is

signal c : INTEGER range 0 to 7;

begin

count: process (Fin)

begin

if Fin='1' and Fin'event then

if c >= 3 then c <= 0;

else c <= c+1;

end if;

else

c <= c;

end if;

if c <= 1 then Fout <= '0';

else Fout <= '1';

end if;

end process;

end div4_beh;