名称:基于VHDL语言的洗衣机控制器设计VHDL代码Quartus仿真(文末获取)
软件:Quartus
语言:VHDL
代码功能:
基于VHDL语言的洗衣机控制器设计
设计要求
设计一个洗衣机洗涤程序控制器,控制洗衣机的电动机按下图所示的规律运转。
洗衣机仿真
1.要求
2.工程文件
3.程序文件
4.程序编译
5.VWF文件
6.仿真图
部分代码展示:
LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; --洗衣机 ENTITY washing_machine IS PORT ( clk_in : IN STD_LOGIC;--50Hz start_key : IN STD_LOGIC;--启动按键 led : OUT STD_LOGIC_VECTOR(2 DOWNTO 0);--正转,反转,暂停 end_led : OUT STD_LOGIC;--洗衣结束信号 dig_led1 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);--数码管1 dig_led2 : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)--数码管2 ); END washing_machine; ARCHITECTURE RTL OF washing_machine IS --定义中间信号 SIGNAL state : STD_LOGIC_VECTOR(1 DOWNTO 0) := "01"; SIGNAL washing_time : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000";--预置洗衣时间12分钟 SIGNAL end_led_buf : STD_LOGIC := '1'; SIGNAL second_cnt : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000"; SIGNAL min_en : STD_LOGIC := '0'; SIGNAL min_en_buf : STD_LOGIC := '0'; SIGNAL min_en_rise : STD_LOGIC; SIGNAL second_en_1s : STD_LOGIC := '0'; SIGNAL second_en : STD_LOGIC; SIGNAL second_div_cnt : STD_LOGIC_VECTOR(9 DOWNTO 0) := "0000000000"; SIGNAL shang : STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL yushu : STD_LOGIC_VECTOR(3 DOWNTO 0); SIGNAL state_div : STD_LOGIC_VECTOR(1 DOWNTO 0) := "00"; SIGNAL data_buf : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000"; SIGNAL shang_buf : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000"; SIGNAL yushu_buf : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000"; SIGNAL duanxuan2 : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000"; SIGNAL duanxuan1 : STD_LOGIC_VECTOR(7 DOWNTO 0) := "00000000"; BEGIN PROCESS (clk_in)--状态机 BEGIN IF (clk_in'EVENT AND clk_in = '1') THEN CASE state IS WHEN "00" =>--状态00,等待状态,若有启动信号则到状态01 IF (start_key = '1') THEN state <= "01"; ELSE state <= "00"; END IF; WHEN "01" =>--状态01,倒计时状态,直到计时到0,到状态01 IF (washing_time > "00000000") THEN state <= "01"; ELSE state <= "10"; END IF; WHEN "10" =>--结束状态,返回00 state <= "00"; WHEN OTHERS => state <= "00"; END CASE; END IF; END PROCESS; PROCESS (clk_in) BEGIN IF (clk_in'EVENT AND clk_in = '1') THEN IF (state = "00") THEN end_led_buf <= '1';--状态00,提示洗衣结束 ELSE end_led_buf <= '0'; END IF; END IF; END PROCESS; end_led <= end_led_buf; PROCESS (clk_in)--设输入clk为50Hz,分频到1Hz BEGIN IF (clk_in'EVENT AND clk_in = '1') THEN IF (second_div_cnt >= "0000110010") THEN--50 second_div_cnt <= "0000000000"; second_en_1s <= '1';--1S脉冲信号 ELSE second_div_cnt <= second_div_cnt + "0000000001"; second_en_1s <= '0'; END IF; END IF; END PROCESS; PROCESS (clk_in) BEGIN IF (clk_in'EVENT AND clk_in = '1') THEN IF (second_cnt = "00111011") THEN--秒计时到59,生产分计时脉冲 min_en <= '1'; ELSE min_en <= '0'; END IF; END IF; END PROCESS; PROCESS (clk_in) BEGIN IF (clk_in'EVENT AND clk_in = '1') THEN min_en_buf <= min_en; END IF; END PROCESS; min_en_rise <= min_en AND (NOT(min_en_buf)); PROCESS (clk_in) BEGIN IF (clk_in'EVENT AND clk_in = '1') THEN IF (start_key = '1') THEN washing_time <= "00001100";-- 预置计时时间12分钟 ELSIF (min_en_rise = '1') THEN--分钟脉冲到了,分钟时间减1 IF (washing_time > "00000000") THEN washing_time <= washing_time - "00000001"; ELSE washing_time <= "00000000"; END IF; ELSE washing_time <= washing_time; END IF; END IF; END PROCESS; second_en <= second_en_1s; --75秒为一个周期 PROCESS (clk_in) BEGIN IF (clk_in'EVENT AND clk_in = '1') THEN IF (start_key = '1') THEN second_cnt <= "00000000"; ELSIF (second_en = '1') THEN IF (second_cnt >= "01001010") THEN--秒计时到74返回0 second_cnt <= "00000000"; ELSE second_cnt <= second_cnt + "00000001"; END IF; ELSE second_cnt <= second_cnt; END IF; END IF; END PROCESS;
源代码
扫描文章末尾的公众号二维码