【正文】
when read_data_high = count1:=count1+1。 when others =null。 end if。 SCL=39。 then count1:=0。 when 3 =if SDA=39。 when 2 =SCL=39。 檢查應(yīng)答 case count1 is when 1 =SDA=39。 end case。 end if。current_state=read_check_ack1。count1:=0。039。139。讀地址 case count1 is when 1 =SDA=read_address(t1)。 end case。current_state=read_slave_address。039。039。139。139。 read conversion when read_start = count1:=count1+1。 when others=null。 when 15=count1:=0。 when 3=SDA=39。 when 2=SCL=39。停止 case count1 is when 1=SDA=39。 end case。 when 16 =current_state=start。039。039。current_state=stop。039。139。Z39。 when check_ack2 = count1:=count1+1。 when others=null。 else current_state=transmit_reg。 if t1=0 then t1:=8。 when 5=t1:=t11。 when 4=SCL=39。 when 2=SCL=39。 when transmit_reg = count1:=count1+1。 when others =null。 end if。SCL=39。 then count1:=0。 when 3 =if SDA=39。 when 2 =SCL=39。 應(yīng)答信號(hào)檢查 case count1 is when 1 =SDA=39。 end case。 end if。current_state=check_ack1。count1:=0。039。139。寫地址 case count1 is when 1 =SDA=slave_address(t1)。 end case。current_state=transmit_slave_address。039。039。139。139。 選擇 VINO 通道,參考電壓選擇內(nèi)部 杭州電子科技大學(xué)繼續(xù)教育學(xué)院畢業(yè)設(shè)計(jì)(論文) 31 elsif rising_edge(clock) then case current_state is when start = count1:=count1+1。 read_address:=01010001。 slave_address:=01010000。1 byte length AD_CONVERSION_SPEED=39。139。139。139。 data_reg=000000000000。039。 variable t2 :integer range 0 to 16。 variable t: std_logic_vector(6 downto 0)。 AD7991 IIC 協(xié)議進(jìn)程 process(clock,RESET) variable count1:integer range 0 to 16。 end if。 else count:=count+1。 elsif rising_edge(CLK) then if count=500000 then count:=0。039。 無葉風(fēng)扇電機(jī)有惰性,所以采樣速度要放慢 process(CLK,RESET) variable count : integer range 0 to 500000。 signal current_state : state:=start。 signal data_reg: std_logic_vector(11 downto 0)。 end ack_check。 SCL : out std_logic。ad 采樣信號(hào),用于觀察采集頻率 LED3:out std_logic。 Sampling_fre: out std_logic。 entity ack_check is port( CLK : in std_logic。 use 。 備注: 12AD 最小分辨率: 5/4096=1mv; library IEEE。 程序介紹 該 AD 轉(zhuǎn)換采用的是 12bits 的串行 iic 協(xié)議的 AD7991, AD7991 可以在三種模式下運(yùn)行,分別是 標(biāo)準(zhǔn)模式,快速模式,高速模式,對(duì)應(yīng)的時(shí)鐘最高分別為 100K, 400K,和 。 end process。 end case。釋放后結(jié)束 current_state=s0。高電平出現(xiàn)后延時(shí) 10ms,消除杭州電子科技大學(xué)繼續(xù)教育學(xué)院畢業(yè)設(shè)計(jì)(論文) 29 上升沿抖動(dòng) when s5 = KOUT=39。出現(xiàn)后先不急著電平翻轉(zhuǎn),在等個(gè) 10ms 消除釋放抖動(dòng) end if。 then current_state=s3。 when s3 = if KEY=39。current_state=s3。再次檢測(cè)有鍵按下否 else KOUT=39。039。139。 end if。 then current_state=s0。延時(shí) 10ms if KEY=39。 when s1 = KOUT=39。 else current_state=s1。139。039。current_state=s0。 then KOUT=39。 process(clk100hz,RESET)按鍵消抖程序塊 begin if RESET=39。 end if。 else count:=count+1。 elsif rising_edge(CLK) then if count=5000001 then count:=0。clk100hz=39。039。 begin process(CLK,RESET)產(chǎn)生 10ms 周期的時(shí)鐘信號(hào) variable count:integer range 0 to 500000。 type state is (s0,s1,s2,s3,s4,s5)。 end Independent_Keys。CPU RESET KEY : in std_logic。 entity Independent_Keys is port( 杭州電子科技大學(xué)繼續(xù)教育學(xué)院畢業(yè)設(shè)計(jì)(論文) 28 CLK : in std_logic。 use 。 程序功能:單個(gè)按鍵按下并要求釋放后才算一次按鍵,按下和釋放都去抖了,一次按鍵按下并釋放后 按鍵輸出只持續(xù) 10ms 高電平 library IEEE。 end generate。 end ponent 。CPU RESET KEY : in std_logic。 architecture Behavioral of ManyKeys is ponent Independent_Keys port( CLK : in std_logic。四個(gè)按鍵 KEY_OUT : out std_logic_vector(3 downto 0) 按鍵輸出指示 , 對(duì)應(yīng)key1~key4 )。 RESET : in std_logic。 use 。 use 。 end Behavioral。 UD : PWM port map ( CLK = CLK , RESET = RESET , DUTY =duty_reg, PWM_OUT= PWM_OUT )。 UB : ack_check port map ( CLK = CLK , RESET = RESET , Sampling_fre=sampling_reg, LED3=LED3, SDA =SDA, SCL=SCL, AD_CONVERSION_SPEED = AD_CONVERSION_SPEED, DATA_OUT= ad_reg )。 杭州電子科技大學(xué)繼續(xù)教育學(xué)院畢業(yè)設(shè)計(jì)(論文) 26 signal sv_smg,pv_smg : std_logic_vector(11 downto 0)。 signal ad_reg : std_logic_vector(11 downto 0)。 signal key_reg : std_logic_vector(3 downto 0)。gfedcba Anode BIT8 :out std_logic_vector(0 to 7)bit8(7) to the first smg )。 DOT: out std_logic。 DATA_SV : in std_logic_vector(11 downto 0)。 數(shù)碼管顯示 ponent Smg_Display port( CLK :in std_logic。從 0~100% PWM_OUT : out std_logic )。 RESET : in std_logic。 end ponent 。給數(shù)碼管顯示的設(shè)定數(shù)據(jù); SMG_DATA_PV : out std_logic_vector(11 downto 0)。人體紅外熱釋電感應(yīng)到就燈亮 SAMPLING_DATA : in std_logic_vector