Piranti Terprogram - FSM
Piranti Terprogram - FSM
Piranti Terprogram - FSM
EEPIS
Piranti Terprogram
Perancangan Finite State Machine
(Pertemuan ke- 7)
1
Created by AI
EEPIS
2
Created by AI
EEPIS
3. Beri nama project dan letakkan project pada folder yang ditentukan serta Top-level
source type adalah HDL
4. Setting jenis FPGA dan konfigurasi lainnya sesuai gambar dibawah, dimana
Family: Spartan-3E
Package: CP132
Speed: -4
3
Created by AI
EEPIS
5. Klik Next dan anda akan mendapat konfirmasi konfigurasi yang telah dilakukan.
Selanjutnya klik Finish
6. Selanjutnya buat file VHDL dengan cara klik kanan pada nama project, selanjutnya
pilih New Source
8. VHDL FSM
-----------------------------------------------------
-- VHDL FSM (Finite State Machine) modeling
-- by WZ
--
-- FSM model consists of two concurrent processes
-- state_reg and comb_logic
-- we use case statement to describe the state
4
Created by AI
EEPIS
library ieee ;
use ieee.std_logic_1164.all;
-----------------------------------------------------
entity seq_design is
port( a: in std_logic;
clock: in std_logic;
reset: in std_logic;
x: out std_logic
);
end seq_design;
-----------------------------------------------------
begin
if (reset='1') then
current_state <= S0;
elsif (clock'event and clock='1') then
current_state <= next_state;
end if;
end process;
case current_state is
5
Created by AI
EEPIS
end if;
end case;
end process;
end FSM;
-----------------------------------------------------
-----------------------------------------------------------------
-- test bench for FSM (ESD book figure 2.7)
-- by WZ
-----------------------------------------------------------------
library ieee;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;
-----------------------------------------------------------------
architecture TB of fsm_tb is
component seq_design
port( a: in std_logic;
clock: in std_logic;
reset: in std_logic;
x: out std_logic
);
6
Created by AI
EEPIS
end component;
begin
process
begin
T_clock <= '1'; -- clock cycle 10 ns
wait for 5 ns;
T_clock <= '0';
wait for 5 ns;
end process;
process
begin
-- case 1
T_reset <= '1';
wait for 20 ns;
assert (T_x='0') report "Failed Case 1" severity error;
if (T_x/='0') then
err_cnt:=err_cnt+1;
end if;
-- case 2
T_reset <= '0';
T_a <= '0';
wait for 20 ns;
assert (T_x='0') report "Failed Case 2" severity error;
if (T_x/='0') then
err_cnt:=err_cnt+1;
end if;
-- case 3
wait for 30 ns;
T_a <= '1';
wait for 35 ns;
assert (T_x='1') report "Failed Case 3" severity error;
if (T_x/='1') then
err_cnt:=err_cnt+1;
end if;
-- case 4
wait for 70 ns;
T_reset <= '1';
wait for 10 ns;
assert (T_x='0') report "Failed Case 4" severity error;
if (T_x/='0') then
err_cnt:=err_cnt+1;
end if;
7
Created by AI
EEPIS
assert true
report "Something wrong, Check again pls!"
severity error;
end if;
wait;
end process;
end TB;
----------------------------------------------------------------------
configuration CFG_TB of fsm_TB is
for TB
end for;
end CFG_TB;
-----------------------------------------------------------------------