我做的一个自动门,源程序如下:library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity zdm is port ( clk: in std_logic; sen_1,sen_2 : in std_logic; device_open : out std_logic; device_close:out std_logic ; close_min:in std_logic; open_max: in std_logic); end zdm; architecture beh of zdm is type state_type is (qa,qb,qc,qd); signal state: state_type; begin process (clk,open_max,close_min) begin if clk'event and clk = '1' then case state is when qa =>device_open<='0'; device_close<='0'; if (sen_2 or sen_1)<='1' then state<=qb; else state<=qa; end if; when qb =>device_open<='1'; device_close<='0'; if (sen_2 or sen_1)<='1' then if open_max<='1' then state<=qd; else state<=qa; end if; else state<=qc; end if ; when qc =>device_open<='0'; device_close<='1'; if (sen_1 or sen_2)<='0' then if close_min<='1'then state <=qa; end if; else state<=qb; end if ; when qd=>device_open<='0'; device_close<='0'; if (sen_1 or sen_2)<='0'then state<=qc; else state<=qd; end if; when others=>state<=qa; end case; end process; end beh; 我在quartus2上编译成功,但是防真波形不符,原版程序是书上下的,因为原版程序在qusrtus2上编译有错,但是在MAX+plus上成功,我只学了quartus所以我做了一点改动,把19行成if clk'event and clk = '1' then,原版程序19行为wait until clk'event and clk = '1' 后编译成功,但是防真波形不符合逻辑,状态图,qc,qb,在不停的自转,问题在哪呢?Sen_1 和sen_2 为传感器信号,为高电 平时有人活动;Clock 为0.1s 时钟脉冲输 入;o p e n _ m a x 开门最大控制点,当 o p e n _ m a x 为高电平时,为开最大。 Close_min关门最小控制点,当close_min为 高电平时,为关最小。Device_open 为高电 平时,执行开门驱动。Device_close为高电 平时为,执行关门驱动。应用状态机设计, Q A 为关门停止状态,QB 为开门状态,QC 为关门状态,Q D 为开最大停止状态。
|