[an error occurred while processing this directive]
[an error occurred while processing this directive]
|
с потолка.
Скажем, задача такая: на вход схемы поступает асинхронный сигнал (определение какое-то кривое, ну да ладно). Надо выделить передний фронт этого сигнала, то есть "преобразовать" его в импульс длительностью в один период тактового сигнала (clk) нашей схемы, причем этот импульс должен быть синхронизирован с clk.
inp - входной сигнал;
front - выходной импульс.
library ieee;
use ieee.STD_logic_1164.ALL;
entity moore is
port(clk : in std_logic;
reset : in std_logic;
inp : in std_logic;
front : out std_logic
);
end moore;
architecture behavior of moore is
type state_type is (S0, S1, S2, S3);
signal curr_state : state_type := S0;
signal next_state : state_type := S0;
begin
fsm: process(clk, reset, curr_state, inp)
begin
case curr_state is
when S0 =>
front <= '0';
if inp = '0' then
next_state <= S1;
else next_state <= S0;
end if;
when S1 =>
front <= '0';
if inp = '0' then
next_state <= S1;
else next_state <= S2;
end if;
when S2 =>
front <= '1';
next_state <= S3;
when S3 =>
front <= '0';
if inp = '1' then
next_state <= S3;
else next_state <= S1;
end if;
end case;
if (clk'event and clk = '1') then
if reset = '0' then
curr_state <= S0;
else curr_state <= next_state;
end if;
end if;
end process fsm;
end behavior;
Ограничения - временной промежуток между изменениями входного сигнала не должен быть меньше периода clk. В противном случае возможен пропуск фронта (при неблагоприятном фазовом соотношении входного и тактового сигналов, или проще говоря, если положительный уровень входного сигнале не пригодится на передний фронт clk).
Далее: требуется задержать выходной сигнал (front) на один такт clk относительно предыдущего примера. В fsm вводится еще одно состояние SD. В следующем примере звездами (*****) помечены изменения по сравнению с предыдущим примером.
library ieee;
use ieee.STD_logic_1164.ALL;
entity moore_ is
port(clk : in std_logic;
reset : in std_logic;
inp : in std_logic;
front : out std_logic
);
end moore;
architecture behavior of moore is
type state_type is (S0, S1, SD, S2, S3); --**********
signal curr_state : state_type := S0;
signal next_state : state_type := S0;
begin
fsm: process(clk, reset, curr_state, inp)
begin
case curr_state is
when S0 =>
front <= '0';
if inp = '0' then
next_state <= S1;
else next_state <= S0;
end if;
when S1 =>
front <= '0';
if inp = '0' then
next_state <= S1;
else next_state <= SD; --*********
end if;
--**************************************
when SD =>
front <= '0';
next_state <= S2;
--**************************************
when S2 =>
front <= '1';
next_state <= S3;
when S3 =>
front <= '0';
if inp = '1' then
next_state <= S3;
else next_state <= S1;
end if;
end case;
if (clk'event and clk = '1') then
if reset = '0' then
curr_state <= S0;
else curr_state <= next_state;
end if;
end if;
end process fsm;
end behavior;
Промоделируйте сами, посмотрите какие появились дополнительные ограничения.
Уфф, писать упарился...
E-mail: info@telesys.ru