在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1583|回复: 1

可重触发数据寻峰VHDL代码(原)

[复制链接]
发表于 2009-1-9 10:19:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

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--------------------------
-------------------------------------------------------------------
头像被屏蔽
发表于 2009-1-9 13:11:13 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-16 16:01 , Processed in 0.015281 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表