em đang làm 1 cái ví dụ về FSM moore thì gặp phải vấn đền như thế này, mạch trạng thái của em là tìm chuỗi 1011, nếu đúng thì đầu ra bằng 1 sai thì bằng 0, em viết code và test bằng ISE thì có cái hiện tượng là như thế này
code ko có lệnh else trong mạch tổ hợp thái tiếp theo
thì giản đồ sau khi mô phỏng là hình ở trên (các bác thông cảm nhìn ở phía dưới có hình đấy ak)
còn trong trường hợp có câu lệnh else trong vòng case
thì kết quả mô phỏng lại ra hình ở dưới
em không hiểu là tại sao nó lại như vậy
testbench cho cả 2 trg hợp là như nhau
còn đây là sơ đồ trạng thái của ví dụ em đang làm
code ko có lệnh else trong mạch tổ hợp thái tiếp theo
Code:
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 14:59:47 06/22/2014
-- Design Name:
-- Module Name: FSM_1011_moore - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity FSM_1011_moore is
port ( clk : in std_logic;
rst : in std_logic;
data_in : in std_logic;
data_out :out std_logic);
end FSM_1011_moore;
architecture Behavioral of FSM_1011_moore is
type state_type is (d1,d10,d101,d1011,idel);
signal current_state,next_state : state_type;
signal y : std_logic;
begin
data_out<=y;
-- moo tar thanh ghi trang thai
process(clk)
begin
if rising_edge(clk) then
if rst='1' then
current_state<=idel;
else
current_state<=next_state;
end if;
end if;
end process;
-- mo ta mach to hop gia tri dau ra
process(current_state,clk)
begin
if current_state=d1011 then
y<='1';
else
y<='0';
end if;
end process;
-- mo ta mach to hop trang thai tiep theo
process(current_state,data_in)
begin
next_state<=current_state;
case current_state is
when idel =>
if data_in='1' then
next_state<=d1;
--else
-- next_state<=idel;
end if;
when d1 =>
if data_in='0' then
next_state<=d10;
--else
--next_state<=d1;
end if;
when d10 =>
if data_in='1' then
next_state<=d101;
--else
--next_state<=idel;
end if;
when d101 =>
if data_in='1' then
next_state<=d1011;
--else
--next_state<=d10;
end if;
when d1011 =>
if data_in='1' then
next_state<=d1;
--else
--next_state<=d10;
end if;
when others =>
next_state<=idel;
end case;
end process;
end Behavioral;
còn trong trường hợp có câu lệnh else trong vòng case
Code:
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 14:59:47 06/22/2014
-- Design Name:
-- Module Name: FSM_1011_moore - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity FSM_1011_moore is
port ( clk : in std_logic;
rst : in std_logic;
data_in : in std_logic;
data_out :out std_logic);
end FSM_1011_moore;
architecture Behavioral of FSM_1011_moore is
type state_type is (d1,d10,d101,d1011,idel);
signal current_state,next_state : state_type;
signal y : std_logic;
begin
data_out<=y;
-- moo tar thanh ghi trang thai
process(clk)
begin
if rising_edge(clk) then
if rst='1' then
current_state<=idel;
else
current_state<=next_state;
end if;
end if;
end process;
-- mo ta mach to hop gia tri dau ra
process(current_state,clk)
begin
if current_state=d1011 then
y<='1';
else
y<='0';
end if;
end process;
-- mo ta mach to hop trang thai tiep theo
process(current_state,data_in)
begin
next_state<=current_state;
case current_state is
when idel =>
if data_in='1' then
next_state<=d1;
else
next_state<=idel;
end if;
when d1 =>
if data_in='0' then
next_state<=d10;
else
next_state<=d1;
end if;
when d10 =>
if data_in='1' then
next_state<=d101;
else
next_state<=idel;
end if;
when d101 =>
if data_in='1' then
next_state<=d1011;
else
next_state<=d10;
end if;
when d1011 =>
if data_in='1' then
next_state<=d1;
else
next_state<=d10;
end if;
when others =>
next_state<=idel;
end case;
end process;
end Behavioral;
em không hiểu là tại sao nó lại như vậy
testbench cho cả 2 trg hợp là như nhau
Code:
--------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 15:17:48 06/22/2014
-- Design Name:
-- Module Name: E:/New folder/practice/FSM_1011/FSM_1011_tb.vhd
-- Project Name: FSM_1011
-- Target Device:
-- Tool versions:
-- Description:
--
-- VHDL Test Bench Created by ISE for module: FSM_1011_moore
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
-- Notes:
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test. Xilinx recommends
-- that these types always be used for the top-level I/O of a design in order
-- to guarantee that the testbench will bind correctly to the post-implementation
-- simulation model.
--------------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY FSM_1011_tb IS
END FSM_1011_tb;
ARCHITECTURE behavior OF FSM_1011_tb IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT FSM_1011_moore
PORT(
clk : IN std_logic;
rst : IN std_logic;
data_in : IN std_logic;
data_out : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal rst : std_logic := '0';
signal data_in : std_logic := '0';
--Outputs
signal data_out : std_logic;
-- Clock period definitions
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: FSM_1011_moore PORT MAP (
clk => clk,
rst => rst,
data_in => data_in,
data_out => data_out
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 5 ns ;
data_in<='1';
wait for 10 ns;
data_in<='0';
wait for 10 ns;
data_in<='1';
wait for 10 ns;
data_in<='1';
wait for 10 ns;
data_in<='0';
wait for 10 ns;
data_in<='0';
wait for 10 ns;
--wait;
end process;
END;

Comment