下面这串代码如何改才不会报错“process variable r_cnt: std_logic_vector(9 downto 0):="00000000000000000000" ; begin wait until rising_edge(i_ADC_clk); if i_rst = '1' then r_cnt <= "00000000000000000000"; else r_cnt <= r_cnt + 1; end if; wait until rising_edge(i_ADC_clk); case r_cnt is when 20000 => i_ADC <= "0000001010"; when 400000 => i_ADC <= "0101010111"; when 1500000 => i_ADC <= "0110110100"; when 1950000 => i_ADC <= "1000010111"; when 2000000 => i_ADC <= "1010000000"; when 4000000 => i_ADC <= "0111000111"; when 6000000 => i_ADC <= "0010000010"; when 8000000 => i_ADC <= "1100011000"; when 10000000 => i_ADC <= "0011111000"; when others => null; end case; end process;”
时间: 2024-02-14 11:18:32 浏览: 144
这段代码中使用了一个变量 r_cnt,需要将其改为信号类型,因为在 VHDL 中只有信号才能在不同的过程之间传递数据。同时,需要注意在时序逻辑中,对信号的赋值必须在时钟上升沿时进行。修改后的代码如下:
```
process
variable r_cnt : natural := 0;
begin
wait until rising_edge(i_ADC_clk);
if i_rst = '1' then
r_cnt := 0;
else
r_cnt := r_cnt + 1;
end if;
wait until rising_edge(i_ADC_clk);
case r_cnt is
when 20000 =>
i_ADC <= "0000001010";
when 400000 =>
i_ADC <= "0101010111";
when 1500000 =>
i_ADC <= "0110110100";
when 1950000 =>
i_ADC <= "1000010111";
when 2000000 =>
i_ADC <= "1010000000";
when 4000000 =>
i_ADC <= "0111000111";
when 6000000 =>
i_ADC <= "0010000010";
when 8000000 =>
i_ADC <= "1100011000";
when 10000000 =>
i_ADC <= "0011111000";
when others =>
i_ADC <= (others => '0');
end case;
end process;
```
修改后,r_cnt 变成了一个自然数类型的变量,并且在 process 中使用了一个等待语句等待 ADC 时钟上升沿。在 case 语句中,当 r_cnt 的值匹配到某个特定的值时,给 i_ADC 赋以相应的值。注意在 case 的 others 分支中,需要对 i_ADC 进行赋值,否则会产生 X 值。
阅读全文