library IEEE;
use IEEE.std_logic_1164.all;
entity INCUBATOR2 is
port(temperature: in std_logic_vector(7 downto 0);
CLK,RESET: in std_logic;
on_cooler,on_heater: out std_logic;
CRS:out std_logic_vector(3 downto 0));
end entity INCUBATOR2;
architecture ARCH of INCUBATOR2 is
TYPE STATE_TYPE_left IS (S1, S2, S3);
SIGNAL STATE,NEXT_STATE : STATE_TYPE_left;
TYPE STATE_TYPE_right IS (S_OUT,S_1, S_2, S_3);
SIGNAL cooler_STATE,cooler_NEXT_STATE : STATE_TYPE_right;
begin
--T<= temprature;
REG: process (clk, reset) begin
if reset='1' then
STATE <= S1 ;
cooler_STATE<=S_OUT;
elsif clk'event and clk='1' then
STATE <= NEXT_STATE ;
cooler_STATE<=cooler_NEXT_STATE;
end if ;
end process REG ;
CMB:process(STATE,temperature ,cooler_STATE)
begin
case STATE is
when S1 =>
if(temperature > "00100011" ) then
NEXT_STATE<=S2;
elsif(temperature < "00001111") then
NEXT_STATE<= S3;
end if;
--cooler_NEXT_STATE<=S_OUT;
when S2 =>
if(temperature < "00011001" ) then
NEXT_STATE<=S1;
end if;
case cooler_STATE is
when S_OUT=>
if(temperature>"00100011") then
cooler_NEXT_STATE<=S_1;
end if;
when S_1=>
if(temperature>"00101000") then
cooler_NEXT_STATE<=S_2;
elsif(temperature<"00011001") then
cooler_NEXT_STATE<=S_OUT;
end if;
when S_2=>
if(temperature>"00101101") then
cooler_NEXT_STATE<=S_3;
elsif(temperature<"00100011") then
cooler_NEXT_STATE<=S_1;
end if;
when S_3=>
if(temperature<"00101000") then
cooler_NEXT_STATE<=S_2;
end if;
end case;
when S3 =>
if(temperature>"00011110" ) then
NEXT_STATE<=S1;
end if;
--cooler_NEXT_STATE<=S_OUT;
end case;
end process CMB;
-- with STATE select
-- heater<= '0' when S1|S2,
-- '1' when S3;
-- cooler<= '0' when S1|S3,
-- '1' when S2;
-- label if( cooler='1') generate
-- modul: COOLER port map(temprature=>T,CRS=>CRS,clk=>clk,reset=>reset);
--end generate;
OUTPUT : process(STATE,cooler_STATE)
begin
case STATE is
when S1 =>
on_heater<='0';
on_cooler<='0';
when S2 =>
on_cooler<='1';
on_heater<='0';
case cooler_STATE is
when S_OUT =>
CRS<="0000";
when S_1 =>
CRS<="0100";
when S_2 =>
CRS<="0110";
when S_3 =>
CRS<="1000";
when others=>
CRS<="0000";
end case;
when S3 =>
on_heater<='1';
on_cooler<='0';
end case;
end process OUTPUT;
end ARCH;
а вот и тестовый стенд:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity incubator_tb is
end entity;
architecture testbench of incubator_tb is
component INCUBATOR2 is
port(temperature: in std_logic_vector(7 downto 0);
CLK,RESET: in std_logic;
on_cooler,on_heater: out std_logic;
CRS:out std_logic_vector(3 downto 0));
end component INCUBATOR2;
signal CLK, reset: std_logic;
signal on_cooler,on_heater:std_logic;
signal temperature:std_logic_vector(7 downto 0);
signal CRS: std_logic_vector(3 downto 0);
begin
modul: INCUBATOR2 port map(
temperature => temperature, clk => clk, reset => reset,
on_cooler => on_cooler,on_heater=>on_heater,CRS=>CRS);
stim: process
begin
temperature <= "00100110";
clk <= '0';
reset <= '1';
wait for 20 ns;
temperature <= "00100110";
clk <= '1';
reset <= '0';
wait for 20 ns;
reset <= '0';
clk <= '0';
temperature <= "00001010";
wait for 20 ns;
reset <= '0';
clk <= '1';
temperature <= "00001010";
wait for 20 ns;
reset <= '0';
clk <= '0';
temperature <= "00100110";
wait for 20 ns;
--clk <= '1';
reset <= '0';
clk <= '1';
temperature <= "00100110";
wait for 20 ns;
reset <= '0';
clk <= '1';
temperature <= "00101010";
wait for 20 ns;
wait;
end process;
end architecture testbench;
как на картинке ниже показано, что выходы некоторых входов рассчитываются неправильно, и on_heater никогда не активируется... (предполагается, что он переключится на 1, когда температура равна a)
Может ли кто-нибудь сказать мне, что я делаю неправильно? Я так сбит с толку, что любая помощь будет очень признательна.
can anyone tell me that where am i doing wrong?
не является конкретным и fsm работает некорректно.) Немного поискав и устранив неполадки, вы обнаружите отсутствует тактовый интервал для перехода к состоянию S3 в тестовой среде. (Вы должны иметь возможность добавить сигналы инкубатора к вашей волне, как это сделано здесь. Вы обнаружите, что просто не достигаете S3, потому что температура изменилась на более высокое значение.) - person   schedule 07.08.2020on_heater
= '1' не появляется, что-то обнаруживаемое при устранении неполадок. Если › не является числовой операцией, она будет основана на сравнении элементов, включая метазначения, что может привести к несоответствию симуляции и синтеза (вероятно, здесь это не так, предостережение - используйте арифметические реляционные операторы). В вашем дизайне нет ничего принципиально неправильного. - person   schedule 11.08.2020