|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
--------------------------------------------------------------------------------
-- An example of data peak finder
--
--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity peakfinder is
port( clk : in std_logic;
timesig : in std_logic;
din : in std_logic_vector(15 downto 0);
dout : out std_logic_vector(15 downto 0)
);
end peakfinder;
architecture Behavioral of peakfinder is
signal datain_1 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_2 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_3 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_4 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_5 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_6 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_7 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_8 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_9 : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_a : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_b : std_logic_vector(15 downto 0):="0000000000000000";
signal datain_c : std_logic_vector(15 downto 0):="0000000000000000";
signal datasum_0 : std_logic_vector(15 downto 0):="0000000000000000";
signal datasum_1 : std_logic_vector(15 downto 0):="0000000000000000";
signal datasum_2 : std_logic_vector(15 downto 0):="0000000000000000";
signal datasum_3 : std_logic_vector(15 downto 0):="0000000000000000";
signal datasum_4 : std_logic_vector(15 downto 0):="0000000000000000";
signal datasum_5 : std_logic_vector(15 downto 0):="0000000000000000";
signal datamax : std_logic_vector(15 downto 0):="0000000000000000";
signal datamaxposition : std_logic_vector(4 downto 0):="00000";
signal peakfindcnt : std_logic_vector(4 downto 0):="00000";
signal Trigger : std_logic:='0';
signal PreReTrig : std_logic:='0';
signal ReTrig : std_logic:='0';
begin
-- 流水线赋值
process (clk)
begin
if clk'event and clk = '1' then
datain_1 <= din;
datain_2 <= datain_1;
datain_3 <= datain_2;
datain_4 <= datain_3;
datain_5 <= datain_4;
datain_6 <= datain_5;
datain_7 <= datain_6;
datain_8 <= datain_7;
datain_9 <= datain_8;
datain_a <= datain_9;
datain_b <= datain_a;
datain_c <= datain_b;
end if;
end process;
-- 流水线求和
process (clk)
begin
if clk'event and clk = '1' then
datasum_0 <= datain_1 + datain_2 + datain_3 + datain_4 + datain_5 + datain_6 + datain_7 + datain_8 + datain_9 + datain_a + datain_b + datain_c ;
datasum_1 <= datasum_0;
datasum_2 <= datasum_1;
datasum_3 <= datasum_2;
datasum_4 <= datasum_3;
datasum_5 <= datasum_4;
end if;
end process;
-- 数据寻峰 >>>>>>>>>>>>>>>>>>
-- get the trigger signal, then count from zero;
process(clk,timesig)
begin
if clk'event and clk = '1' then
if (timesig = '1' and peakfindcnt = "00000") then
Trigger <= '1';
else
Trigger <= '0';
end if;
end if;
end process;
-- get the retrigger siganl, then count from zero again;
process(clk,timesig)
begin
if clk'event and clk = '1' then
if (timesig = '0' and peakfindcnt > "00000" and peakfindcnt < "10000") then
PreReTrig <= '1';
elsif (timesig = '1' and PreReTrig = '1') then
ReTrig <= '1';
PreReTrig <= '0';
else --if peakfindcnt = "10000" then
ReTrig <= '0';
PreReTrig <= '0';
end if;
end if;
end process;
-- trigger count
process (clk,timesig)
begin
if clk'event and clk = '1' then
if Trigger = '1' or ReTrig = '1' then
peakfindcnt <= "00001";
elsif peakfindcnt > "00000" and peakfindcnt < "10000" then
peakfindcnt <= peakfindcnt + 1;
elsif timesig = '0' and peakfindcnt = "10000" then
peakfindcnt <= "00000";
end if;
end if;
end process;
process (clk,peakfindcnt,din,datamax)
begin
if clk'event and clk = '1' then
if peakfindcnt = "00000" then
datamax <= "0000000000000000";
datamaxposition <= "00000";
elsif peakfindcnt > "00000" and peakfindcnt < "10000" then
if din > datamax then
datamax <= din;
datamaxposition <= peakfindcnt;
end if;
end if;
end if;
end process;
process (clk,peakfindcnt,din,datamax)
begin
if clk'event and clk = '1' then
if peakfindcnt = "10000" then
if datamaxposition = "00101" then
dout <= datasum_5;
elsif datamaxposition = "00110" then
dout <= datasum_4;
elsif datamaxposition = "00111" then
dout <= datasum_3;
elsif datamaxposition = "01000" then
dout <= datasum_2;
elsif datamaxposition = "01001" then
dout <= datasum_1;
elsif datamaxposition = "01010" then
dout <= datasum_0;
end if;
else
dout <= "0000000000000000";
end if;
end if;
end process;
end Behavioral;
----------------------------------------------------------------
----------------------Retrigger Timing--------------------------
----------------------------------------------------------------
-- timesig: __|~~~|__________|~~~~~|_________________________
-- trigger: __|~|____________________________________________
-- PreReTrig: ______|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|___________
-- ReTrig: _________________|~|_____________________________
-- Peakcount: --|1|2|3|4|5|....|1|2|3|4|5|6|.......|16|--------
----------------------------------------------------------------
----------------------Retrigger Timing--------------------------
----------------------------------------------------------------
-------------------------------------------------------------------
-----------------------Data Output Timing--------------------------
-------------------------------------------------------------------
-- TimeSig: __|~~~~|_______________________________________________
-- Datain : -----------------------------*-------------------------
-- Count : ==|0|1|2|3|................................|f|10|
-- DataOut: ----------------------------------------------|dout|
-- Position: |<----datamaxposition----->|
-- MaxValue: V
-- range : |<--------- 6~10 --------->|<------10~6-----|
-------------------------------------------------------------------
-----------------------Data Output Timing--------------------------
------------------------------------------------------------------- |
|