[an error occurred while processing this directive]
|
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity hello is
port (
clk, rstn :in std_logic; -- тактовый сигнал от AVR, !- добавьте сброс -!
ENABLE0 :in STD_LOGIC; -- указание на отправку FPGA->AVR младшего байта результата
ENABLE1 :in std_logic; -- указание на отправку FPGA->AVR старшего байта результата
FIOREA :in std_logic; -- разрешение на передачу байа данных от FPGA к AVR
PIN :in std_logic; -- входной сигнал
DATATOAVR :out std_logic_vector(7 downto 0) -- байт данных для отправки от FPGA к AVR
);
end hello;
architecture fpslic of hello is
SIGNAL pin_reg : std_logic;
SIGNAL coun_reg : std_logic_vector(15 downto 0);
SIGNAL count : unsigned(15 downto 0);
begin
process (clk, rstn) -- схема должна быть синхронной
begin
if rstn = '0' then -- положим сброс по нулю
pin_reg <= '0';
coun_reg <= (others=>'0');
count <= (others=>'0');
elsif rising_edge(clk) then
pin_reg <= PIN; -- пишем значение на каждом такте PIN в регистр
if PIN = '1' and pin_reg = '0' then -- детектируем передний фронт PIN по его
-- текущему значению и сохранненому в регистре
-- значению за предыдущий такт
coun_reg <= STD_LOGIC_VECTOR(count); -- сохрянем отсчеты за период PIN
count <= (others => '0'); -- сбрасываем счетчик
else
if count /= 16#FFFF# then -- лочим переполнение
count <= count + 1;
end if;
end if;
end if;
end process;
-- Сигнал FIOREA нужен если только у вас разделяемая шина и необходимо держать её в три-стейте
process (clk, rstn) -- схема должна быть синхронной
begin
if rstn = '0' then
DATATOAVR <= (others=>'Z');
elsif rising_edge(clk) then
if FIOREA = '1' then -- на следующий такт после FIOREA = '1' и ENABLE0/1 = '1'
-- на выходе будет значение счетчика. При FIOREA = '0' на следущем такте будет 'Z'
if ENABLE0 = '1' then
DATATOAVR <= coun_reg(7 downto 0);
end if;
if ENABLE1 = '1' then
DATATOAVR <= coun_reg(15 downto 8);
end if;
else
DATATOAVR <= (others=>'Z');
end if;
end if;
end process;
end fpslic;