入门同志编写的程序,简析其写法与表达错误!
LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY Manchester_encoder IS PORT(D:IN STD_LOGIC; Q:OUT STD_LOGIC; CLK:IN STD_LOGIC); END Manchester_encoder; ARCHITECTURE basic OF Manchester_encoder IS SIGNAL lastd : STD_LOGIC :='0'; BEGIN P1:PROCESS(CLK) BEGIN IF RISING_EDGE(CLK) THEN IF (D='0') THEN Q<='1'; lastd<='1'; ELSIF(D='1') THEN Q<='0'; lastd<='1'; ELSE Q<='X'; lastd<='X'; END IF; ELSIF FALLING_EDGE(CLK) THEN IF(lastd='0') THEN Q<='0'; ELSIF(lastd='1') THEN Q<='1'; ELSE Q<='X'; END IF; END IF; END PROCESS; END basic; 在Qutuas 上编译了一下,但是通不过,显示 Error (10818): Can't infer register for "Q" at Manchester_encoder.vhd(13) because it does not hold its value outside the clock edge
错误告警的意思:在时钟边沿外边Q值不能保持。
上面程序典型错误:没有把程序与D触发器对应,一个D触发器只能对应一个时钟沿判断!
上面程序修改:
LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY Manchester_encoder IS PORT(D:IN STD_LOGIC; Q:OUT STD_LOGIC; CLK:IN STD_LOGIC;
Clkin: IN STD_LOGIC); END Manchester_encoder; ARCHITECTURE basic OF Manchester_encoder IS SIGNAL lastd : STD_LOGIC :='0';
SIGNAL Clkin_Reg: STD_LOGIC; -------------- BEGIN P1:PROCESS(CLK) BEGIN IF RISING_EDGE(CLK) THEN
Clkin_Reg<=Clkin;
IF (Clkin_Reg='0') and (Clkin='1') THEN IF (D='0') THEN Q<='1'; lastd<='1'; ELSIF(D='1') THEN Q<='0'; lastd<='1'; ELSE Q<='X'; lastd<='X'; END IF; ELSIF (Clkin_Reg='1') and (Clkin='0') THEN
IF(lastd='0') THEN Q<='0'; ELSIF(lastd='1') THEN Q<='1'; ELSE Q<='X'; END IF; END IF; END PROCESS; END basic;
|