📄 nu_uwave.vhd
字号:
-- This tutorial example is a simple control unit of a microwave oven.-- It comprises of a state machine and two decrementors for counting-- minutes and seconds.-- The difference between this new hdl and the old hdl (uwave.vhd) are-- the addition of the cancel port, change the width of of min_cook.-- The above will lead to changes of the internal logics.Library IEEE;use IEEE.STD_LOGIC_1164.all;use IEEE.STD_LOGIC_UNSIGNED.all;use IEEE.STD_LOGIC_MISC.all;entity uwave_ctl is port ( -- input port for the cancel cooking -- ECO#1 cancel : in STD_LOGIC; -- input signals to the control unit clk,reset,set_time,start_cook,test:in STD_LOGIC; -- cook time set in minutes and seconds cook_time_m : in STD_LOGIC_VECTOR(6 downto 0); -- ECO#2 cook_time_s : in STD_LOGIC_VECTOR(6 downto 0); -- cook time remaining in cooking mode min_cook : out STD_LOGIC_VECTOR(6 downto 0); -- ECO#2 sec_cook : out STD_LOGIC_VECTOR(6 downto 0); -- flags for cooking in progress, test mode, -- cooking completed, setting clock cooking,load_8888,load_done,load_clk:out STD_LOGIC );end uwave_ctl;architecture first of uwave_ctl is -- used to avoid port mode BUFFER signal xcooking : STD_LOGIC; signal xmin_cook : STD_LOGIC_VECTOR(6 downto 0); signal xsec_cook : STD_LOGIC_VECTOR(6 downto 0);-- outputs of the decrementors signal s_cook_val : STD_LOGIC_VECTOR(6 downto 0); signal m_cook_val : STD_LOGIC_VECTOR(6 downto 0);-- internal signals signal outvec : STD_LOGIC_VECTOR(3 downto 0); signal set_hr_min, go_cook, done_cook : STD_LOGIC; signal dec_min_sec : STD_LOGIC; attribute ENUM_ENCODING : STRING; type states is (idle,timer,lamp_test,set_clock,done_msg); attribute ENUM_ENCODING of states : type is "000 001 010 011 100"; signal nxt_state,cur_state : states; attribute STATE_VECTOR : STRING; attribute STATE_VECTOR of first : architecture is "cur_state"; begin-- concurrent assignments cooking <= xcooking; min_cook <= xmin_cook; sec_cook <= xsec_cook; dec_min_sec <= not(OR_REDUCE(xsec_cook)) and (OR_REDUCE(xmin_cook)); set_hr_min <= set_time and not(test); done_cook <= (not(OR_REDUCE(xsec_cook)) and not(OR_REDUCE(xmin_cook))) or cancel; go_cook <= not(done_cook) and not(test) and not(set_time) and start_cook;-- initializationprocess(clk, reset) begin if clk'event and clk = '1' then if reset = '1' then cur_state <= idle; else cur_state <= nxt_state; end if; end if;end process;-- state machineprocess(clk, reset) begin if clk'event and clk = '1' then if reset = '1' then xcooking <= '0'; load_8888 <= '0'; load_done <= '0'; load_clk <= '0'; else xcooking <= outvec(3); load_8888 <= outvec(2); load_done <= outvec(1); load_clk <= outvec(0); end if; end if;end process;process(cur_state,test,set_hr_min, go_cook, done_cook) begin nxt_state <= idle; --default next state is idle outvec <= "0000"; case cur_state is when lamp_test => outvec <= "0100"; when set_clock => outvec <= "0001"; when done_msg => outvec <= "0010"; when idle => if test = '1' then nxt_state <= lamp_test; outvec <= "0100"; elsif (go_cook = '1') then nxt_state <= timer; outvec <= "1000"; elsif (set_hr_min = '1') then nxt_state <= set_clock; outvec <= "0001"; else nxt_state <= idle; outvec <= "0000"; end if; when timer => if done_cook = '1' then nxt_state <= done_msg; outvec <= "0010"; else nxt_state <= timer; outvec <= "1000"; end if; end case;end process;-- decrementing cook time in secondsprocess(start_cook, xsec_cook, cook_time_s, xcooking, dec_min_sec) begin if start_cook = '1' then s_cook_val <= cook_time_s; elsif xcooking = '1' then if dec_min_sec = '1' then s_cook_val <= "0111011"; else s_cook_val <= xsec_cook - "0000001"; end if; else s_cook_val <= "0000000"; end if;end process;-- decrementing cook time in minutesprocess(start_cook, xmin_cook, cook_time_m, xcooking, dec_min_sec) begin if start_cook = '1' then m_cook_val <= cook_time_m; elsif xcooking = '1' then if dec_min_sec = '1' then m_cook_val <= xmin_cook - "0000001"; else m_cook_val <= xmin_cook; end if; else m_cook_val <= "0000000"; end if;end process;process(clk) begin if clk'event and clk = '1' then xmin_cook <= m_cook_val; xsec_cook <= s_cook_val; end if; end process;end first;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -