⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a2d.vhd.bak

📁 将AD转换得到的八位数据存入RAM
💻 BAK
字号:
-- tlc0820ac ---a/d转换
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all; 
use ieee.std_logic_unsigned.all;
entity a2d is
port(clk :in std_logic;--输入时钟信号50MHz
	 sw0 : in std_logic;  --复位
	
--	 mode :out std_logic;  --0820模式,1为写0为读,悬空相当于低
	 adcs : out std_logic;
	 rd : out std_logic;
	 int : in std_logic; 
	 datain : in std_logic_vector(7 downto 0);
	 ld: out std_logic_vector(7 downto 0);
	--ram
	ramcs: out std_logic;
	ramsck: out std_logic;
	ramsi: out std_logic;
	ramso: in std_logic;
	--da
	dacs:out std_logic;
	dasck:out std_logic;
	dadin:out std_logic
	);
end a2d;
architecture aa of a2d is
signal t_rd, t_adcs : std_logic;
signal count1: integer range 0 to 4999; --控制AD,total采样间隔为50+2600=3100ns
signal count2: integer range 0 to 199; --控制回放,每1us回放一次,total采样间隔为1微妙
signal t_int: integer range 0 to 15;		--350ns 肯定够int变为高了
signal t_addata :std_logic_vector(7 downto 0);
signal time: integer range 0 to 1000;
signal t_ramcs,t_sck,t_ramsi:std_logic;
signal t_ramso:std_logic_vector(7 downto 0);
signal count3:integer range 0 to 3;
signal ram_part_addr: integer range 0 to 15;
signal t_ramaddr:std_logic_vector(15 downto 0);
signal t_dacs,t_dasck,t_dadin:std_logic;

begin
process(clk,int,sw0)
variable t_ramdata:std_logic_vector(7 downto 0):="00000000";
variable t_dadata:std_logic_vector(15 downto 0):="0000000000000000";
begin

--异步复位
if sw0='0' then
	count1 <= 0;
	time<=0;
	t_adcs <= '1';
	t_rd <= '1';
	t_addata <= "00000000";
	t_ramcs<='1';
	t_ramaddr<="0000000000000000";--initiate address as "0000000000000000"

--计数器
elsif(clk'event and clk='1') then
	
		if time<1001 then	--%6----用于AD和写RAM,其中0用于WREN命令的写入
			if count1=4999 then --100ns
				count1<=0;
				time<=time+1;
				t_ramaddr<=t_ramaddr+1; --最终的1000各点存储在0~999的ram存里面
			else 
				count1<=count1+1;
			end if;	
		elsif count2=199 then	--该值应该根据DA的速度而定,最终定为200*20=4000ns=0.25MHZ
			count2<=0;
			if t_ramaddr="000001111100111" then --%000001111100111--
				t_ramaddr<="0000000000000000";
			else
				t_ramaddr<=t_ramaddr+1;
			end if;
		else
			count2<=count2+1;			
		end if;
		
	if time<1000 then	--%5--  --AD and write data into ram 
----------------AD和存储时序控制start---------------
		if count1 < 3 then
			t_adcs<='1';
			t_rd<='1';
		elsif count1 < 23 then
			t_adcs<='0';
			t_rd<='1';
		elsif count1<155 then
			t_adcs<='0';
			t_rd<='0';
			if int='0' then
				t_int<=t_int+1;
			else
				t_int<=0;
			end if;
			if t_int = 2 then
				t_addata <= datain;
			end if;
		else 	
			t_adcs<='1';
			t_rd<='1';
		end if;
--------------AD和存储时序控制end-----------------
-------------存储操纵代码start-----------------
---------------write WREN pro-code:start---------------------
		if count1<155 then --40ns后让sck开始驱动
			t_ramcs<='1';
		elsif count1<157 then
			t_ramcs<='0';
			count3<=3;
			t_sck<='0';
			t_ramdata:="00000110";
			ram_part_addr<=7;
			t_ramsi<=t_ramdata(7);
		elsif count1< 189 then --285=286-1,minus 1 to ensure write 1 byte a time
			t_ramcs<='0';		--286=156+130,130=(40+8*80)/20=34
			if count3=3 then
				count3<=0;
				t_sck<=not t_sck;
			elsif count3=0 then
				count3<=count3+1;	
				ram_part_addr<=ram_part_addr-1;
			elsif count3=1 then	--提前一个时钟将数据写到si
				t_sck<=not t_sck;
				t_ramsi<=t_ramdata(ram_part_addr);
				count3<=count3+1;
			else
				count3<=count3+1;
			end if;
		elsif count1<191 then
			t_ramcs<='1';
---------------write WREN pro-code:end---------------------
----------------写数据:start-------------------------------
		elsif count1<193 then --40ns后让sck开始驱动
			t_ramcs<='0';
			count3<=3;
			t_sck<='0';
			t_ramdata:="00000010";
			ram_part_addr<=7;
			t_ramsi<=t_ramdata(7);
		elsif count1< 321 then --285=157+128,minus 1 to ensure write 1 byte a time
			t_ramcs<='0';		--286=156+130,130=(40+32*80)/20
			if count1< 225-2 then--189=157+32 --减2由于读信号在下降沿
				t_ramdata:="00000010";			
			elsif count1<257-2 then	--221=189+32
				t_ramdata:=t_ramaddr(15 downto 8);
			elsif count1<289-2 then
				t_ramdata:=t_ramaddr(7 downto 0);
			else 
				t_ramdata:=t_addata;
			end if;
			if count3=3 then
				count3<=0;
				t_sck<=not t_sck;
			elsif count3=0 then
				count3<=count3+1;
				if ram_part_addr=0 then		--ram_part_addr perhaps should be variable?
					ram_part_addr<=7;
				else
					ram_part_addr<=ram_part_addr-1;
				end if;
			elsif count3=1 then	--提前一个时钟将数据写到si
				count3<=count3+1;	
				t_sck<=not t_sck;
				t_ramsi<=t_ramdata(ram_part_addr);
			else
				count3<=count3+1;			
			end if;
		else
			t_ramcs<='1';
		end if;	
----------------写数据:end-------------------------------
-------------存储操纵代码到此-----------------------------
	elsif time=5 then --%1000--
--------------写入WRDI pro-code:start---------
		t_ramaddr<="0000000000000000";   --为ram读做准备,存在0-999处
		if count1<2 then --40ns后让sck开始驱动
			t_ramcs<='0';
			count3<=3;
			t_sck<='0';
			t_ramdata:="00000100";
			ram_part_addr<=7;
			t_ramsi<=t_ramdata(7);
		elsif count1< 34 then --285=286-1,minus 1 to ensure write 1 byte a time
			t_ramcs<='0';		--286=156+130,130=(40+8*80)/20=34
			if count3=3 then
				count3<=0;
				t_sck<=not t_sck;
			elsif count3=0 then
				ram_part_addr<=ram_part_addr-1;
				count3<=count3+1;
			elsif count3=1 then	--提前一个时钟将数据写到si
				t_ramsi<=t_ramdata(ram_part_addr);
				count3<=count3+1;	
				t_sck<=not t_sck;
			else
				count3<=count3+1;
			end if;
		else
			t_ramcs<='1';
		end if;		
--------------写入WRDI pro-code:end---------
	else --time=1001,read RAM and D/A to display
----------------回放(即DA)时序控制------------------------
-----------1. read ram:start-----------------------------
		if count2<2 then --40ns后让sck开始驱动
			t_ramcs<='0';
			count3<=3;
			t_sck<='0';
			t_ramdata:="00000011"; --read mode
			ram_part_addr<=7;
			t_ramsi<=t_ramdata(7);
		elsif count2< 129 then --130=2+128,--(129,130)
			t_ramcs<='0';		--286=156+130,130=(40+32*80)/20
			
			if count2< 34-2 then--34=2+32
				t_ramdata:="00000011";			
			elsif count2<66-2 then	--221=34+32
				t_ramdata:=t_ramaddr(15 downto 8);
			elsif count2<98-2 then
				t_ramdata:=t_ramaddr(7 downto 0);
			else 
				t_ramdata:="ZZZZZZZZ";
				if count3=3 then
					t_ramso(ram_part_addr)<=ramso;
				end if;
			end if;
			
			if count3=3 then
				count3<=0;
				t_sck<=not t_sck;
			elsif count3=0 then
				count3<=count3+1;
				if ram_part_addr=0 then		--ram_part_addr perhaps should be variable?
					ram_part_addr<=7;
				else
					ram_part_addr<=ram_part_addr-1;
				end if;
			elsif count3=1 then	--提前一个时钟将数据写到si
				t_ramsi<=t_ramdata(ram_part_addr);
				count3<=count3+1;	
				t_sck<=not t_sck;
			else	
				count3<=count3+1;					
			end if;
		else
			t_ramcs<='1';
		end if;	
-----------1. read ram:end-----------------------------
-----------2. DA recovery:start------------------------
		if count2<130 then --follow 1
			t_dacs<='1';
		elsif count2<132 then	--40ns后让dasck开始驱动	
			t_dacs<='0';
			count3<=3;
			t_dasck<='1';
			t_dadata:="01000000"&t_ramso;
			ram_part_addr<=15;	--借用ram的
			t_ramsi<=t_dadata(15);
		elsif count2< 196 then --196=132+64,
			t_dacs<='0';		--286=156+130,130=(40+32*80)/20
			if count3=3 then
				count3<=0;
				t_dasck<=not t_dasck;
			elsif count3=0 then
				count3<=count3+1;
				if ram_part_addr=0 then		--ram_part_addr perhaps should be variable?
					ram_part_addr<=15;
				else
					ram_part_addr<=ram_part_addr-1;
				end if;	
			elsif count3=1 then	--提前一个时钟将数据写到si
				t_dadin<=t_dadata(ram_part_addr);
				count3<=count3+1;	
				t_dasck<=not t_dasck;
			else
				count3<=count3+1;	
			end if;
		else
			t_adcs<='1';
		end if;	

-----------2. DA recovery:end------------------------

end if; --time>1000		
end if; --clk
end process;
adcs<=t_adcs;
rd<=t_rd;
ramcs<=t_ramcs;
ramsck<=t_sck;
ramsi<=t_ramsi;
dacs<=t_dacs;
dasck<=t_dasck;
dadin<=t_dadin;
--dataout<=t_addata;
--dclk <= count1;
ld <= t_addata;
end aa;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -