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

📄 amp.vhd

📁 FPGA的串口通信程序
💻 VHD
字号:
library ieee ;
use ieee.std_logic_1164.all ;
use ieee.std_logic_arith.all ;

entity amp is
port (clk	 	: in std_logic ;
   	  panel 	: in std_logic_vector (7 downto 0);
	  amp	  	: in std_logic_vector (7 downto 0);
	  panelsel 	: out std_logic;					--控制cd4053决定放大器所测屏是LCD OR PDP
	  pu  		: out std_logic;
	  pd   		: out std_logic						--控制电位器x9511的电阻变化情况
) ;
end amp ;

architecture rtl of amp is

signal clkout : std_logic ;
signal ctrl : std_logic ;
signal ctrl31_enable : std_logic ;
signal ctrl52_enable : std_logic ;
signal ctrl56_enable : std_logic ;
signal ctrl58_enable : std_logic ;
signal ctrl59_enable : std_logic ;
signal ctrl60_enable : std_logic ;
signal amp1	: std_logic_vector (3 downto 0);
signal amp2	: std_logic_vector (3 downto 0);
signal count31 : unsigned (26 downto 0); 
signal count52 : unsigned (27 downto 0); 
signal count56 : unsigned (27 downto 0); 
signal count58 : unsigned (27 downto 0); 
signal count59 : unsigned (27 downto 0); 
signal count60 : unsigned (27 downto 0); 

COMPONENT count IS
port 
(
	  clkin	 	: in std_logic ;
	  clkout	: out std_logic
) ;
END COMPONENT;

begin
U1: count
PORT MAP
(
		 clkin    => clk,
		 clkout   => clkout
);

process(clk)
begin
if clk'event and clk = '1' then
case panel is
WHEN "00000000"=> panelsel <= '0';		--所测屏为LCD
WHEN "10000000"=> panelsel <= '1';		--所测屏为PDP
when others    => panelsel <= '0';
end case;
end if;
end process;

process(clk)
begin
if clk'event and clk = '1' then
case amp is
WHEN "00000000"=> amp1 <= "0000";
				  amp2 <=  amp1 ;
WHEN "10000000"=> amp1 <= "0001";
				  amp2 <=  amp1 ;
WHEN "11000000"=> amp1 <= "0011";
				  amp2 <=  amp1 ;
WHEN "10100000"=> amp1 <= "0101";
				  amp2 <=  amp1 ;
WHEN "11100000"=> amp1 <= "0111";
				  amp2 <=  amp1 ;
WHEN "10010000"=> amp1 <= "1001";
				  amp2 <=  amp1 ;
WHEN "11010000"=> amp1 <= "1011";
				  amp2 <=  amp1 ;
WHEN "10110000"=> amp1 <= "1101";
				  amp2 <=  amp1 ;
WHEN "11110000"=> amp1 <= "1111";
				  amp2 <=  amp1 ;
when others    => amp1 <= "0001";
				  amp2 <=  amp1 ;
end case;
end if;
end process;

process(clk)
begin
if clk'event and clk = '1' then
if amp1=amp2 then
ctrl <= '0';
else ctrl <= '1';
end if;
end if;
end process;

process(clk)
begin
if clk'event and clk = '1' then
if ctrl = '1' then
	ctrl31_enable <= '1';
elsif std_logic_vector(count31) = "101000000000000000000000000" then
	ctrl31_enable <= '0';		   
end if;
end if;
end process;			

process (clk, ctrl31_enable)
begin
if clk'event and clk = '1' then
	if ctrl31_enable = '0' then
		count31 <= "000000000000000000000000000" ;
	else
		count31 <= count31 + "000000000000000000000000001" ;
end if ;
end if ;
end process ;			--将电位器示数调整位最大,x9511共有31级(10k/31是每一级的阻值)

process(clk)
begin
if clk'event and clk = '1' then
if ctrl = '1' then
	ctrl52_enable <= '1';
elsif std_logic_vector(count52) = "1000001000000000000000000000" then
	ctrl52_enable <= '0';			
end if;
end if;
end process;

process (clk, ctrl52_enable)
begin
if clk'event and clk = '1' then
	if ctrl52_enable = '0' then
		count52 <= "0000000000000000000000000000" ;
	else
		count52 <= count52 + "0000000000000000000000000001" ;
end if ;
end if ;
end process ;		--从电位器最大值调整至3倍的放大倍数

process(clk)
begin
if clk'event and clk = '1' then
if ctrl = '1' then
	ctrl56_enable <= '1';
elsif std_logic_vector(count56) = "1000101010000000000000000000" then
	ctrl56_enable <= '0';			
end if;
end if;
end process;

process (clk, ctrl56_enable)
begin
if clk'event and clk = '1' then
	if ctrl56_enable = '0' then
		count56 <= "0000000000000000000000000000" ;
	else
		count56 <= count56 + "0000000000000000000000000001" ;
end if ;
end if ;
end process ;		--5倍的放大倍数

process(clk)
begin
if clk'event and clk = '1' then
if ctrl = '1' then
	ctrl58_enable <= '1';
elsif std_logic_vector(count58) = "1000111110000000000000000000" then
	ctrl58_enable <= '0';			
end if;
end if;
end process;

process (clk, ctrl58_enable)
begin
if clk'event and clk = '1' then
	if ctrl58_enable = '0' then
		count58 <= "0000000000000000000000000000" ;
	else
		count58 <= count58 + "0000000000000000000000000001" ;
end if ;
end if ;
end process ;		--7倍的放大倍数

process(clk)
begin
if clk'event and clk = '1' then
if ctrl = '1' then
	ctrl59_enable <= '1';
elsif std_logic_vector(count59) = "1001001000000000000000000000" then
	ctrl59_enable <= '0';			
end if;
end if;
end process;		

process (clk, ctrl59_enable)
begin
if clk'event and clk = '1' then
	if ctrl59_enable = '0' then
		count59 <= "0000000000000000000000000000" ;
	else
		count59 <= count59 + "0000000000000000000000000001" ;
end if ;
end if ;
end process ;		--9,11倍的放大倍数

process(clk)
begin
if clk'event and clk = '1' then
if ctrl = '1' then
	ctrl60_enable <= '1';
elsif std_logic_vector(count60) = "1001010010000000000000000000" then
	ctrl60_enable <= '0';          
end if;
end if;
end process;

process (clk, ctrl60_enable)
begin
if clk'event and clk = '1' then
	if ctrl60_enable = '0' then
		count60 <= "0000000000000000000000000000" ;
	else            
		count60 <= count60 + "0000000000000000000000000001" ;
end if ;
end if ;
end process ;		--13,15倍的放大倍数

process(clk,amp1)
begin
if clk'event and clk = '1' then
if amp1 = "0001" then
	pu <= clkout;
	pd <= '0';
elsif amp1 = "0011" then
	if ctrl31_enable = '1' and ctrl52_enable = '1' then
	pu <= clkout;
	pd <= '0';
	elsif ctrl31_enable = '0' and ctrl52_enable = '1' then
	pu <= '0';
	pd <= clkout;
	else pu <= '0';
		 pd <= '0';
	end if;
elsif amp1 = "0101" then
	if ctrl31_enable = '1' and ctrl56_enable = '1' then
	pu <= clkout;
	pd <= '0';
	elsif ctrl31_enable = '0' and ctrl56_enable = '1' then
	pu <= '0';
	pd <= clkout;
	else pu <= '0';
		 pd <= '0';
	end if;
elsif amp1 = "0111" then
	if ctrl31_enable = '1' and ctrl58_enable = '1' then
	pu <= clkout;
	pd <= '0';
	elsif ctrl31_enable = '0' and ctrl58_enable = '1' then
	pu <= '0';
	pd <= clkout;
	else pu <= '0';
		 pd <= '0';
	end if;
elsif amp1 = "1001" then
	if ctrl31_enable = '1' and ctrl59_enable = '1' then
	pu <= clkout;
	pd <= '0';
	elsif ctrl31_enable = '0' and ctrl59_enable = '1' then
	pu <= '0';
	pd <= clkout;
	else pu <= '0';
		 pd <= '0';
	end if;
elsif amp1 = "1011" then
	if ctrl31_enable = '1' and ctrl59_enable = '1' then
	pu <= clkout;
	pd <= '0';
	elsif ctrl31_enable = '0' and ctrl59_enable = '1' then
	pu <= '0';
	pd <= clkout;
	else pu <= '0';
		 pd <= '0';
	end if;
elsif amp1 = "1101" then
	if ctrl31_enable = '1' and ctrl60_enable = '1' then
	pu <= clkout;
	pd <= '0';
	elsif ctrl31_enable = '0' and ctrl60_enable = '1' then
	pu <= '0';
	pd <= clkout;
	else pu <= '0';
		 pd <= '0';
	end if;
elsif amp1 = "1111" then
	if ctrl31_enable = '1' and ctrl60_enable = '1' then
	pu <= clkout;
	pd <= '0';
	elsif ctrl31_enable = '0' and ctrl60_enable = '1' then
	pu <= '0';
	pd <= clkout;
	else pu <= '0';
		 pd <= '0';
	end if;
end if;
end if;
end process;		--调整过程:接收到数据后先将电位器调整为最大值,之后再按要求往下调整

end;

⌨️ 快捷键说明

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