我正在用VHDL语言为CPLD设计一个简单的脉冲发生器。我有一系列简单的if语句,这些语句应该根据连接到模块的总线的输入状态来执行某些任务。
entity pulse_gen is
Port ( CLK : in STD_LOGIC;
pulse_sel_in : in STD_LOGIC_VECTOR (2 downto 0);
pulse_r : in STD_LOGIC;
pulse_s : inout STD_LOGIC);
end pulse_gen;
architecture Behavioral of pulse_gen is
signal pulse_sel: std_logic_vector (2 downto 0);
signal pulse_count: integer;
signal pulse_length: integer range 0 to 100;
signal pulse_a: std_logic;
begin
pulse_sel <= pulse_sel_in;
pulse: process(CLK) is
begin
if(pulse_sel > "000" and pulse_a = '0') then
pulse_s <= '1';
pulse_a <= '1';
end if;
if(pulse_a = '1' and pulse_count < pulse_length) then
pulse_count <= pulse_count + 1;
end if;
if(pulse_a = '1' and pulse_count = pulse_length) then
pulse_s <= '0';
pulse_a <= '0';
pulse_count <= 0;
end if;
end process;
set_max: process(CLK) is
begin
if (CLK'event) then
case pulse_sel is
when "001" => pulse_length <= 1;
when "010" => pulse_length <= 10;
when "011" => pulse_length <= 100;
when others => null;
end case;
end if;
end process;
end Behavioral;当在iSim中运行这个模块时,强制_pulse_s_总线除了1000以外的任何东西都应该触发脉冲进程中的第一个if语句,而这正是它所做的。然而,在仿真中,_pulse_a_信号从未被设置为逻辑高。现在我花了几个小时用不同的方式编写这个模块,但我完全不知道为什么不会发生这种情况。我对VHDL比较陌生,所以我想知道是否存在某种语法或过程错误,而我只是完全忽略了这些错误。有什么想法吗?
发布于 2013-10-14 12:10:50
@Philippe是对的。定义信号时,需要将pulse_a赋值为0或1。加上这个: signal pulse_a: std_logic := '0';它就能工作了。
你说你强迫它在iSim低。你猜怎么着?当你强迫它低的时候,它就保持低!这样你的代码就不能改变了!
编辑:您还应该将pulse_count分配给一些初始值。
发布于 2013-10-14 10:01:04
信号的初始值是'U‘。没有一个条件等于'1‘或等于'0’是有效的,因此没有分配新的值。
https://stackoverflow.com/questions/19356331
复制相似问题