?? dalia.vhd
字號(hào):
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity dali is port( IRQ,rst,clk_main,data_in,lamp_failure : in std_logic; tch0,tch1 : out std_logic_vector(15 downto 0); data_out: out std_logic );end dali;architecture behavior of dali is signal limit_error,rec_active,rec_active1,startbit_error,stopbit_error,databit_error,rst_real: std_logic :='0';--not signal rec_position : integer range 0 to 15 ; signal rec_bit : integer range 0 to 18 ; signal address,command,level,state_no,fade_time : std_logic_vector(7 downto 0) ; signal tsco:std_logic; signal clk_dali,clk_20:std_logic; signal short_address:std_logic_vector(7 downto 0); signal input_level2,input_level3,input_level4,input_level:std_logic_vector(7 downto 0); signal min_level:std_logic_vector(7 downto 0); signal max_level:std_logic_vector(7 downto 0); signal power_failure,withdraw:std_logic; signal fade_rate:std_logic_vector(7 downto 0); signal fade_start_level:std_logic_vector(7 downto 0); signal fade_stop_level:std_logic_vector(7 downto 0); signal new_level:std_logic_vector(7 downto 0); signal fade_total:std_logic_vector(12 downto 0); signal state_time:std_logic_vector(12 downto 0); signal random_addr_out1,random_addr_out2,random_addr_out3,address_time :std_logic_vector(7 downto 0); signal system_failure_level,power_on_level:std_logic_vector(7 downto 0); signal answer,dtr,selection:std_logic_vector(7 downto 0); signal search_address_h,search_address_m,search_address_l:std_logic_vector(7 downto 0); signal random_address_h,random_address_m,random_address_l:std_logic_vector(7 downto 0); signal send_position,dataout1,dataout2,datain11,datain12,datain13,datain21,datain22,datain23 : std_logic_vector(7 downto 0); signal low_counter : std_logic_vector(15 downto 0); signal send_value : std_logic; signal physical_min_level: std_logic_vector(7 downto 0);--physical_min_level not initialized!!!! signal fg:std_logic:='0'; signal addr11,addr12,addr13,addr21,addr22,addr23 :integer range 0 to 1; signal dataout11,dataout12,dataout13,dataout21,dataout22,dataout23 :std_logic_vector(7 downto 0); component lamp_setlevel is port (new_level: in std_logic_vector(7 downto 0);--equal to the light control command min_level: in std_logic_vector(7 downto 0); max_level: in std_logic_vector(7 downto 0); level: out std_logic_vector(7 downto 0); limit_error: out std_logic;-- if exceed the limit, limit_error will be 1 tsco: out std_logic; --check if the lamp is working at full power.1 yes 0 no tch0: out std_logic_vector(15 downto 0); tch1: out std_logic_vector(15 downto 0) ); end component; component ram is port( clk_dali: in std_logic; addr : in integer range 0 to 1; datain : in std_logic_vector(7 downto 0); dataout : out std_logic_vector(7 downto 0) ); end component; component ram1 is port( clk_dali: in std_logic; datain : in std_logic_vector(7 downto 0); dataout : out std_logic_vector(7 downto 0) ); end component;
beginp0: process(rst,clk_dali) variable i:integer:=0; begin if(rst='1') then while(i<=9) loop if(rising_edge(clk_20))then i:=i+1; end if; end loop; if(rst='1') then rst_real<='1'; else rst_real<='0'; end if; end if; end process p0;
p1: process(IRQ) begin if(falling_edge(IRQ))then rec_active1<='1'; end if; end process p1;
p2: process(rst_real,clk_dali,data_in)--ini variable rec_value,temp_value : std_logic; begin if(rst_real='1') then rec_active<='1'; rec_bit<=0; rec_position<=0; address<="00000000"; command<="00000000"; datain11<="00000000"; addr11<=0; stopbit_error<='0'; startbit_error<='0'; databit_error<='0'; datain11<="00000000"; system_failure_level<="11111110"; --not elsif (rec_active='1' and rec_active1='1') then if(rising_edge(clk_dali)) then temp_value:=data_in; rec_position<=rec_position+1; if(temp_value/=rec_value) then CASE rec_bit IS when 0=> rec_bit<=rec_bit+1; rec_position <=0; datain11<="00000000"; when 17=> if(rec_position>6) then rec_active<='0'; rec_bit<=0; end if; datain11<="00000000"; when 18=> rec_active<='0'; rec_bit<=0; datain11<="00000000"; when others=> if(rec_position>6) then if(temp_value='1') then if(rec_bit<=8) then address(8-rec_bit)<=temp_value; else command(16-rec_bit)<=temp_value; end if; end if; rec_bit<=rec_bit+1; rec_position <=0; end if; datain11<="00000000"; end CASE ; rec_value := temp_value; else CASE rec_bit IS when 0=> if(rec_position=8) then rec_active<='0'; rec_bit<=0; end if; datain11<="00000000"; when 17=> if(rec_position=8) then if(temp_value='0') then rec_active<='0'; rec_bit<=0; end if; end if; datain11<="00000000"; when 18=> if(rec_position=8) then rec_active<='0'; datain11<="00000001"; addr11<=0; rec_bit<=0; rec_position<=0; end if; when others=> if(rec_position=10) then rec_active<='0'; rec_bit<=0; end if; datain11<="00000000"; end CASE ; end if; end if; end if; end process p2;
p3: process(address,command,rst_real) variable a,b,c,fadetime : std_logic_vector(7 downto 0); variable m,n : std_logic_vector(23 downto 0); variable fade_rate_temp:std_logic_vector(7 downto 0); variable divide_temp,ddtemp,d1,d2,d3,d4:std_logic_vector(11 downto 0); variable fade_total_temp:std_logic_vector(3 downto 0); variable fade_total_temp1,fade_total_temp2:std_logic_vector(12 downto 0); variable nn:integer range 0 to 16; variable fg_temp:std_logic:='0';
begin if(rst_real='1') then max_level<="11111110"; min_level<=physical_min_level; fade_rate<="00000111"; fade_time<="00000000"; random_address_h<="11111111"; random_address_m<="11111111"; random_address_l<="11111111"; end if; if(dataout1="00000001") then datain12<="00000000"; addr12<=0; a:=address and "11100001"; if((address(7)='0')or(a="10100001")or(a="10110001")) then b:=address and "01111110"; c:='0'& b(7 downto 1) ; if((address(7)='0') and (c=short_address)) then if(address(0)='0') then -- for lamp_setlevel --else if(command/="11111111") then if(fade_time="00000000")then input_level2<=command; --component used ATTENTION!!!!!! datain21<="00000000"; addr21<=1; else fade_start_level<=level; fade_stop_level<=command; nn:=conv_integer(fade_time-"00000001"); case nn is when 0=> fade_total_temp1:="0000000100011" ; when 1=> fade_total_temp1:="0000000110010"; when 2=> fade_total_temp1:="0000001000111"; when 3=> fade_total_temp1:="0000001100100"; when 4=> fade_total_temp1:="0000010001101"; when 5=> fade_total_temp1:="0000011001000"; when 6=> fade_total_temp1:="0000100011011"; when 7=> fade_total_temp1:="0000110010000"; when 8=> fade_total_temp1:="0001000110110"; when 9=> fade_total_temp1:="0001100100000"; when 10=>fade_total_temp1:="0010001101011"; when 11=>fade_total_temp1:="0011001000000"; when 12=>fade_total_temp1:="0100011010111"; when 13=>fade_total_temp1:="0110010000000"; when 14=>fade_total_temp1:="1000110101110"; when others=>null; end case; state_time<=fade_total_temp1; fg_temp:=not fg_temp; fade_total<=fade_total_temp1; datain21<="00000000"; addr21<=1; end if; end if; else --for common command nn:=conv_integer(fade_rate);--get the answer of the fade rate by the case.
case nn is when 0 =>fade_rate_temp:="01001000"; when 1 =>fade_rate_temp:="00110011"; when 2 =>fade_rate_temp:="00100100"; when 3 =>fade_rate_temp:="00011001"; when 4 =>fade_rate_temp:="00010010"; when 5 =>fade_rate_temp:="00001101"; when 6 =>fade_rate_temp:="00001001"; when 7 =>fade_rate_temp:="00000110"; when 8 =>fade_rate_temp:="00000100"; when 9 =>fade_rate_temp:="00000011"; when 10 to 11 =>fade_rate_temp:="00000010"; when 12 to 14 =>fade_rate_temp:="00000001"; when others =>null; end case;
case command is --OFF when "00000000" => power_failure<='0'; input_level2<="00000000"; datain21<="00000000"; addr21<=1; when "00000001"=> if(level/="00000000" and level/=max_level) then --up fade_start_level<=level; if(fade_rate_temp>(max_level-level)) then fade_stop_level<=max_level; divide_temp:="00001010"*(max_level-level);--12 bit ddtemp:=divide_temp-'0'&fade_rate_temp&"000"; if(ddtemp>"000000000000") then fade_total_temp(3):='1'; d1:=ddtemp; else fade_total_temp(3):='0'; d1:=divide_temp; end if; ddtemp:=d1-"00"&fade_rate_temp&"00"; if(ddtemp>"000000000000") then fade_total_temp(2):='1'; d2:=ddtemp; else fade_total_temp(2):='0'; d2:=d1; end if; ddtemp:=d2-"000"&fade_rate_temp&'0'; if(ddtemp>"000000000000") then fade_total_temp(1):='1'; d3:=ddtemp; else fade_total_temp(1):='0'; d3:=d2; end if; ddtemp:=d3-"0000"&fade_rate_temp; if(ddtemp>"000000000000") then fade_total_temp(0):='1'; d4:=ddtemp; else fade_total_temp(0):='0'; d4:=d3; end if; fade_total_temp2:="000000000"&fade_total_temp; else fade_stop_level<=level+fade_rate_temp; fade_total_temp2:="0000000001010"; end if; datain21<="00000010"; addr21<=1; state_time<=fade_total_temp2; fg_temp:=not fg_temp; fade_total<=fade_total_temp2; end if;
when "00000010"=> if(level/="00000000" and level/=min_level) then --down fade_start_level<=level; if(fade_rate_temp>(level-min_level)) then fade_stop_level<=min_level; divide_temp:="00001010"*(level-min_level); ddtemp:=divide_temp-'0'&fade_rate_temp&"000"; if(ddtemp>"000000000000") then fade_total_temp(3):='1'; d1:=ddtemp; else fade_total_temp(3):='0'; d1:=divide_temp; end if; ddtemp:=d1-"00"&fade_rate_temp&"00"; if(ddtemp>"000000000000") then fade_total_temp(2):='1'; d2:=ddtemp; else fade_total_temp(2):='0'; d2:=d1; end if; ddtemp:=d2-"000"&fade_rate_temp&'0'; if(ddtemp>"000000000000") then fade_total_temp(1):='1'; d3:=ddtemp; else fade_total_temp(1):='0'; d3:=d2; end if; ddtemp:=d3-"0000"&fade_rate_temp; if(ddtemp>"000000000000") then fade_total_temp(0):='1'; d4:=ddtemp; else fade_total_temp(0):='0'; d4:=d3; end if; fade_total_temp2:="000000000"&fade_total_temp;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -