我正在尝试在 VHDL 中实现 JK 触发器,这是我的代码:
library ieee;
use ieee.std_logic_1164.all;
entity jk_flip_flop is
port(
J, K : in std_logic;
clk : in std_logic;
Q, Q_bar : out std_logic
);
end jk_flip_flop;
architecture behavioral of jk_flip_flop is
begin
process(J, K, clk)
variable temp: std_logic;
begin
if (clk'event and clk='1') then
temp:='1' when(J='1' AND K='0') else
'0' when(J='0' AND K='1') else
NOT temp when(J='1' AND K='1') else
temp when(J='0' AND K='0');
Q <= temp;
Q_bar <= NOT temp;
end if;
end process;
end behavioral;
我从中得到的错误是:
Error (10500): VHDL syntax error at jk_flip_flop.vhd(18) near text "when"; expecting ";"
Error (10500): VHDL syntax error at jk_flip_flop.vhd(18) near text "else"; expecting ":=", or "<="
Error (10500): VHDL syntax error at jk_flip_flop.vhd(19) near text "else"; expecting ":=", or "<="
Error (10500): VHDL syntax error at jk_flip_flop.vhd(20) near text "else"; expecting ":=", or "<="
Error (10500): VHDL syntax error at jk_flip_flop.vhd(21) near text ";"; expecting ":=", or "<="
这里到底有什么问题?我是否不允许在进程中使用 when-else 或者 when-else 语句的语法在这里错误?
我也很困惑是否需要通过J
并K
进入process
上面,或者如果我只通过就足够了clk
,因为如果在时钟脉冲的上升沿产生新的输出就足够了。