【发布时间】:2020-06-30 10:28:08
【问题描述】:
我正在尝试在 Altera DE10nano 开发板上实现我的 FPGA 和 HPS 之间的通信。要编辑 vhdl,我使用 Quartus Prime 软件。
虽然通信正常工作(因为我可以从 fpga 获取一些数据到 hps),但我有一个问题是创建一个适当的状态机,它可以使用不同的时钟向 FIFO 添加一个新值(在本例中为 12500Hz)比 50MHz 的基本时钟。其他时钟(100kHz 和 12500Hz)在不同的 vhdl 模块中生成。
一般的想法是在 12.5kHz 时钟的每个周期写入一个样本。每个周期我都有一个增加的计数器以及来自上游 FFT 的一些数据。
我在 HPS 中使用一个简单的 C 代码来读取我的 fifo 并将读取的值保存到 .csv 文件中。
现在,问题是:当我使用我的电路板加载我的设计时,我没有得到正确的样本编号。我在 .csv 文件中获得随机值(来自“counter_sample”),而状态机的模拟(使用 ModelSim)正在做我想要它做的事情。 此外,当我使用 100kHz 时钟触发该过程时,该设计确实工作得很好,但有人告诉我这是不好的做法,因为时钟不是由 pll 生成的。这也让我认为使用的 C 代码不是问题。
我得到的随机值不是连续的,而是彼此相隔 200-300 个计数器值。
我不是 vhdl 编程方面的老手(您可能知道),但我会在下面复制我的状态机。我很高兴听到您的意见,如果需要,我会提供更多信息。
fft_sop 和 fft_eop 信号是来自上游 fft 的 start- 和 endofpacket 信号。
谢谢!
process(Clk_50MHz, in_reset)
begin
if (in_reset = '1') then
f2h_state <= f2h_idle;
counter_sample <=0;
counter_wait <=0;
out_fifo_write <='0';
out_fifo_writedata <= (others => '0');
fft_sop_old <= '0';
fft_eop_old <= '0';
Clk_12500Hz_alt<='0';
elsif(rising_edge(Clk_50MHz)) then
fft_sop_old <= in_fft_sop;
fft_eop_old <= in_fft_eop;
Clk_12500Hz_old <= Clk_12500Hz;
case f2h_state is
when f2h_idle =>
if ((Clk_12500Hz = '1') and (Clk_12500Hz_old = '0')) then
counter_wait <= counter_wait + 1;
if counter_wait = 8190 then
f2h_state <= f2h_wait_start;
else
f2h_state <= f2h_idle;
end if;
else
f2h_state <= f2h_idle;
end if;
when f2h_wait_start =>
out_fifo_write <= '0';
if ((in_fft_sop = '1') and (fft_sop_old = '0')) then
out_fifo_write <= '1';
out_fifo_writedata(10 downto 0) <= conv_std_logic_vector(1, 11);
counter_sample <= 2;
out_fifo_writedata(22 downto 11) <= in_fft_real(11 downto 0);
out_fifo_writedata(34 downto 23) <= in_fft_imag(11 downto 0);
out_fifo_writedata(63 downto 35) <= (others => '0');
f2h_state <= f2h_writesample;
end if;
when f2h_writesample =>
if ((Clk_12500Hz = '1') and (Clk_12500Hz_old = '0')) then
out_fifo_write <= '1';
counter_sample <= counter_sample + 1;
out_fifo_writedata(10 downto 0) <= conv_std_logic_vector(counter_sample, 11);
out_fifo_writedata(22 downto 11) <= in_fft_real(11 downto 0);
out_fifo_writedata(34 downto 23) <= in_fft_imag(11 downto 0);
out_fifo_writedata(63 downto 35) <= (others => '0');
if in_fft_eop = '1' then
f2h_state <= f2h_wait_start;
end if;
f2h_state <= f2h_writesample;
else
out_fifo_write <= '0';
end if;
end case;
end if;
end process;
【问题讨论】: