【正文】
_down:out std_logic_vector(2 downto 0) )。end key_f。architecture a of key_f issignal up_down_f:std_logic_vector(2 downto 0)。signal np_f:std_logic。signal step_p_f:std_logic。signal start_stop_f:std_logic。beginprocess(key_valid) begin if key_valid39。event and key_valid=39。039。 then case key is when0000= start_stop_f=not start_stop_f。 when0001= if up_down_f111 then up_down_f=up_down_f+1。 end if。 when0010= if up_down_f000 then up_down_f=up_down_f1。 end if。 when0011= step_p_f=not step_p_f。 when0100= np_f=not np_f。 when others= end case。 end if。end process。start_stop=start_stop_f。step_p=step_p_f。np=np_f。up_down=up_down_f。end a。附錄B3掃描觸發(fā)消抖編碼模塊LIBRARY ieee。USE 。 LIBRARY work。ENTITY key_al8 IS port ( clk_3m : IN STD_LOGIC。 clk_1k : IN STD_LOGIC。 col : IN STD_LOGIC_VECTOR(7 downto 0)。 key_valid : OUT STD_LOGIC。 butt_code : OUT STD_LOGIC_VECTOR(3 downto 0) )。END key_al8。ARCHITECTURE bdf_type OF key_al8 IS ponent key_scan PORT(col : IN STD_LOGIC_VECTOR(7 downto 0)。 scan_t : IN STD_LOGIC_VECTOR(2 downto 0)。 key_pressed : OUT STD_LOGIC )。end ponent。ponent debounce PORT(key_pressed : IN STD_LOGIC。 clk_3m : IN STD_LOGIC。 clk_1k : IN STD_LOGIC。 key_valid : OUT STD_LOGIC )。end ponent。ponent scan_count PORT(clk_3m : IN STD_LOGIC。 clk_1k : IN STD_LOGIC。 key_pressed : IN STD_LOGIC。 scan_t : OUT STD_LOGIC_VECTOR(2 downto 0) )。end ponent。ponent code_tran PORT(clk_3m : IN STD_LOGIC。 KEY_VALID : IN STD_LOGIC。 scan_t : IN STD_LOGIC_VECTOR(2 downto 0)。 butt_code : OUT STD_LOGIC_VECTOR(3 downto 0) )。end ponent。signal SYNTHESIZED_WIRE_5 : STD_LOGIC_VECTOR(2 downto 0)。signal SYNTHESIZED_WIRE_6 : STD_LOGIC。signal SYNTHESIZED_WIRE_3 : STD_LOGIC。BEGIN key_valid = SYNTHESIZED_WIRE_3。b2v_inst : key_scanPORT MAP(col = col, scan_t = SYNTHESIZED_WIRE_5, key_pressed = SYNTHESIZED_WIRE_6)。b2v_inst10 : debouncePORT MAP(key_pressed = SYNTHESIZED_WIRE_6, clk_3m = clk_3m, clk_1k = clk_1k, key_valid = SYNTHESIZED_WIRE_3)。b2v_inst12 : scan_countPORT MAP(clk_3m = clk_3m, clk_1k = clk_1k, key_pressed = SYNTHESIZED_WIRE_6, scan_t = SYNTHESIZED_WIRE_5)。b2v_inst13 : code_tranPORT MAP(clk_3m = clk_3m, KEY_VALID = SYNTHESIZED_WIRE_3, scan_t = SYNTHESIZED_WIRE_5, butt_code = butt_code)。END。 附錄B4 環(huán)形脈沖分配模塊library ieee。use 。use 。use 。entity step3_6 isport( clk: in std_logic。 步進(jìn)電機(jī)轉(zhuǎn)速控制時鐘 up_down:in std_logic_vector(2 downto 0)。八部調(diào)速控制 start_stop: in std_logic。 啟動停止控制位 step_p: in std_logic。 np:in std_logic。 此信號為正轉(zhuǎn),反轉(zhuǎn)。 step:out std_logic_vector(3 downto 0) )。end step3_6。architecture a of step3_6 istype states is(st0,st1,st2,st3,st4,st5,st6,st7)。signal temp:std_logic_vector(14 downto 0)。signal cp:std_logic。signal current_state,next_state:states:=st0。beginp_f:process(CLK,up_down) begin if clk39。event and clk=39。139。 then temp=temp+1。 end if。 case up_down is when000=cp=temp(0)。2分頻 when001=cp=temp(1)。4分頻 when010=cp=temp(2)。8分頻 when011=cp=temp(3)。16分頻 when100=cp=temp(4)。32分頻 when101=cp=temp(5)。64分頻 when110=cp=temp(6)。128分頻 when111=cp=temp(7)。256分頻 when others= end case。end process p_f。p_a:process(current_state,np) begin case current_state is when st0= if np=39。039。 then next_state=st1。 else next_state=st7。 end if。 when st1= if np=39。039。 then next_state=st2。 else next_state=st0。 end if。 when st2= if np=39。039。 then next_state=st3。 else next_state=st1。 end if。 when st3= if np=39。039。 then next_state=st4。 else next_state=st2。 end if。 when st4= if np=39。039。 then next_state=st5。 else next_state=st3。 end if。 when st5= if np=39。039。 then next_state=st6。 else next_state=st4。 end if。 when st6= if np=39。039。 then next_state=st7。 else next_state=st5。 end if。 when st7= if np=39。039。 then next_state=st0。 else next_state=st6。 end if。 when others= next_state=st0。 end case。end process p_a。p_b:process(cp,start_stop,step_p)variable step_p_1,step_p_2:std_logic。 begin if cp39。event and cp=39。139。 then step_p_2:=step_p_1 xor step_p。 if start_stop=39。139。 or step_p_2=39。039。 then current_state=next_state。 if step_p=39。039。 then step_p_1:=39。139。 else step_p_1:=39。039。 end if。 end if。 end if。 end process p_b。p_c:process(current_state) begin if current_state=st0 then step=0001。 elsif current_state=st1 then step=1001。 elsif current_state=st2 then step=1000。 elsif current_state=st3 then step=1010。 elsif current_state=st4 then step=0010。 elsif current_state=st5 then step=0110。 elsif current_state=st6 then step=0100。 elsif current_state=st7 then step=0101。 end if。 end process p_c。end