----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 11:13:45 03/09/2017
-- Design Name:
-- Module Name: top - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Descrip
tion:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
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 using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
library UNISIM;
use UNISIM.VComponents.all;
entity top is
Port (
clk : in STD_LOGIC;
-- data_in : in STD_LOGIC_VECTOR (13 downto 0);
-- clk8k: out STD_LOGIC;--AD时钟
-- dds_rdy : OUT STD_LOGIC;
--
--
-- accumulate1_SCLR:IN STD_LOGIC;
-- accumulate1_S:OUT STD_LOGIC_VECTOR(31 downto 0);
-- accumulate2_SCLR:IN STD_LOGIC;
-- accumulate2_S:OUT STD_LOGIC_VECTOR(31 downto 0);
pdb : inout std_logic_vector(7 downto 0);
astb : in std_logic;
dstb : in std_logic;
pwr : in std_logic;
pwait: out std_logic;
Q: out STD_LOGIC_VECTOR (31 downto 0)
);
end top;
architecture Behavioral of top is
COMPONENT dds
PORT (
clk : IN STD_LOGIC;
ce : IN STD_LOGIC;
we : IN STD_LOGIC;
sclr : IN STD_LOGIC;
data : IN STD_LOGIC_VECTOR(24 DOWNTO 0);
rdy : OUT STD_LOGIC;
cosine : OUT STD_LOGIC_VECTOR(13 DOWNTO 0);
sine : OUT STD_LOGIC_VECTOR(13 DOWNTO 0);
phase_out : OUT std_logic_vector(24 downto 0)
);
END COMPONENT;
component accumulate1
port(
CLK:In STD_LOGIC;
A:IN STD_LOGIC_VECTOR(13 downto 0);
B:IN STD_LOGIC_VECTOR(13 downto 0);
CE:IN STD_LOGIC;
SCLR:IN STD_LOGIC;
S:OUT STD_LOGIC_VECTOR(31 downto 0)
);
END component;
component accumulate2
port(
CLK:In STD_LOGIC;
A:IN STD_LOGIC_VECTOR(13 downto 0);
B:IN STD_LOGIC_VECTOR(13 downto 0);
CE:IN STD_LOGIC;
SCLR:IN STD_LOGIC;
S:OUT STD_LOGIC_VECTOR(31 downto 0)
);
END component;
constant stEppReady : std_logic_vector(7 downto 0) := "0000" & "0000" ;
constant stEppAwrA : std_logic_vector(7 downto 0) := "0001" & "0100" ;
constant stEppAwrB : std_logic_vector(7 downto 0) := "0010" & "0001" ;
constant stEppArdA : std_logic_vector(7 downto 0) := "0011" & "0010" ;
constant stEppArdB : std_logic_vector(7 downto 0) := "0100" & "0011" ;
constant stEppDwrA : std_logic_vector(7 downto 0) := "0101" & "1000" ;
constant stEppDwrB : std_logic_vector(7 downto 0) := "0110" & "0001" ;
constant stEppDrdA : std_logic_vector(7 downto 0) := "0111" & "0010" ;
constant stEppDrdB : std_logic_vector(7 downto 0) := "1000" & "0011" ;
signal stEppCur : std_logic_vector(7 downto 0) := stEppReady;
signal stEppNext : std_logic_vector(7 downto 0) ;
signal clkMain : std_logic; --u***时钟
signal ctlEppWait : std_logic;
signal ctlEppAstb : std_logic;
signal ctlEppDstb : std_logic;
signal ctlEppDir : std_logic;
signal ctlEppWr : std_logic;
signal ctlEppAwr : std_logic;
signal ctlEppDwr : std_logic;
signal busEppOut : std_logic_vector(7 downto 0);
signal busEppIn : std_logic_vector(7 downto 0);
signal busEppData : std_logic_vector(7 downto 0);
signal regEppAdr : std_logic_vector(3 downto 0);
-- Registers
signal regData0 : std_logic_vector(7 downto 0);
signal regData1 : std_logic_vector(7 downto 0);
signal regData2 : std_logic_vector(7 downto 0);
signal regData3 : std_logic_vector(7 downto 0);
signal regData4 : std_logic_vector(7 downto 0);
signal regData5 : std_logic_vector(7 downto 0);
signal regData6 : std_logic_vector(7 downto 0);
signal regData7 : std_logic_vector(7 downto 0);
signal regLed : std_logic_vector(7 downto 0);
signal dout1,dout2,data_out,sine,cosine : std_logic_vector(13 downto 0);--dout1是参考sine dout2是参考cosine data_out是AD转换后序列
----signal cntr: std_logic_vector(23 downto 0);
signal dds_we,dds_sclr,dds_ce,clk_8k : std_logic;
signal accumulate1_ce,accumulate2_ce,rdy: std_logic;
signal flag: std_logic:='1';
signal dds_data,phase_out: std_logic_vector(24 downto 0);
signal dataout1,dataout2 : std_logic_vector(31 downto 0);
begin
ctlEppAstb <= astb;
ctlEppDstb <= dstb;
ctlEPPWr <= pwr;
pwait <= ctlEppWait;
busEppIn <= pdb;
pdb <= busEppOut When ctlEppWr = '1' and ctlEppDir = '1' else "ZZZZZZZZ";
busEppOut <= "0000" & regEppAdr When ctlEppAstb = '0' else busEppData; --选择地址或数据xuantong
-- rgLed <= choose_freq(3 downto 0);
-- ldg <= '1';
ctlEppWait <= stEppCur(0);
ctlEppDir <= stEppCur(1);
ctlEppAwr <= stEppCur(2);
ctlEppDwr <= stEppCur(3);
busEppData <= regData0 when regEppAdr = "0000" else
regData1 when regEppAdr = "0001" else
regData2 when regEppAdr = "0010" else
regData3 when regEppAdr = "0011" else
regData4 when regEppAdr = "0100" else
regData5 when regEppAdr = "0101" else
regData6 when regEppAdr = "0110" else
regData7 when regEppAdr = "0111" else
"00000000";
Inst_dds : dds
PORT MAP (
clk => clk_8k,
sclr=>flag,
ce=>not flag,
we =>not flag,
data => dds_data,
rdy=>rdy,
cosine => cosine,
sine => sine,
phase_out => phase_out
);
Inst_accumulate1 : accumulate1
port map (
CLK=>clk_8k, --成累加一次周期
A=>dout1,
B=>dout2,
CE=>rdy,
SCLR=> flag,
S=>dataout1
);
--Inst_accumulate2 : accumulate2
--port map (
--CLK=>clk_8k, --成累加一次周期
--A=>dout2,
--B=>data_out,
--CE=>rdy,
--SCLR=> reset,
--S=>dataout2
--);
------------------------------------------------
dout1(13) <= not sine(13);
dout1(12 downto 0) <= sine(12 downto 0);
dout2(13) <= not cosine(13);
dout2(12 downto 0) <= cosine(12 downto 0);
process
variable count: integer :=0 ;
begin
wait until clk'Event and clk='1'; --设置周期采样点个数
if (count<500)
then count:=count+1;
else
clk_8k<=not clk_8k;
count:=0;
end if;
end process;
process
variable count: integer :=0 ;
begin
wait until clk'Event and clk='1';
--设置解调周期
if (count<=8000)
then flag<='1';
count:=count+1;
elsif (80000
then flag<='0'; --结束标志
count:=count+1;
else count:=0;
end if;
end process;
process (clk)
begin
if clk = '1' and clk'Event then
stEppCur <= stEppNext;
end if;
end process;
process (stEppCur, stEppNext, ctlEppAstb, ctlEppDstb, ctlEppWr)
begin
case stEppCur is
When stEppReady =>
if ctlEppAstb = '0' then
if ctlEppWr = '0' then
stEppNext <= stEppAwrA; --ctlEppNext=1读
else
stEppNext <= stEppArdA;
end if;
elsif ctlEppDstb = '0' then
if ctlEppWr = '0' then
stEppNext <= stEppDwrA;
else
stEppNext <= stEppDrdA;
end if;
else
stEppNext <= stEppReady;
end if;
When stEppAwrA =>
stEppNext <= stEppAwrB;
When stEppAwrB => -- xie地址线
if ctlEppAstb = '0' then
stEppNext <= stEppAwrB;
else
stEppNext <= stEppReady;
end if;
When stEppArdA =>
stEppNext <= stEppArdB;
When stEppArdB =>
if ctlEppAstb = '0' then --读地址线
stEppNext <= stEppArdB;
else
stEppNext <= stEppReady;
end if;
When stEppDwrA =>
stEppNext <= stEppDwrB;
When stEppDwrB => --写数据线
if ctlEppDstb = '0' then
stEppNext <= stEppDwrB;
else
stEppNext <= stEppReady;
end if;
When stEppDrdA =>
stEppNext <= stEppDrdB;
When stEppDrdB =>
if ctlEppDstb = '0' then --写地址线
stEppNext <= stEppDrdB;
else
stEppNext <= stEppReady;
end if;
When others =>
stEppNext <= stEppReady;
end case;
end process;
process (clk, ctlEppAwr) --?
begin
if clk = '1' and clk'Event then
if ctlEppAwr = '1' then
regEppAdr <= busEppIn (3 downto 0);
end if;
end if;
end process;
process (clk, regEppAdr, ctlEppDwr, busEppIn)
begin
if clk = '1' and clk'Event then
if ctlEppDwr = '1' and regEppAdr = "0001" then --地址为1时,写入控制第一个dds
regData1 <= dataout1(7 downto 0); --这里怎么写?
end if;
end if;
end process;
process (clk, regEppAdr, ctlEppDwr, busEppIn)
begin
if clk = '1' and clk'Event then
if ctlEppDwr = '1' and regEppAdr = "0010" then --地址为2
regData2 <= dataout1(15 downto 8);
end if;
end if;
end process;
process (clk, regEppAdr, ctlEppDwr, busEppIn)
begin
if clk= '1' and clk'Event then
if ctlEppDwr = '1' and regEppAdr = "0011" then --地址为3
regData3 <= dataout1(23 downto 16);
end if;
end if;
end process;
process (clk, regEppAdr, ctlEppDwr, busEppIn)
begin
if clk = '1' and clk'Event then
if ctlEppDwr = '1' and regEppAdr = "0100" then --地址为4
regData4 <= dataout1(31 downto 24);
end if;
end if;
end process;
Q <= dataout1;
--R <= dataout2;
dds_data <= "0000000000001000001100010"; --1k
--ad9240clk<=clk_8k;
--dds_ce<='1';
--dds_we <= '1';
--ce<='1';
--clk8k<=clk_8k;
--dds_rdy<=rdy;
--dds_sclr<=flag;
--dds_we<=not flag;
--dds_ce<=not flag;
--accumulate1_ce<=not flag;
--accumulate2_ce<=not flag;
end Behavioral;