[英]How to take samples using fpga?
我想从FPGA spartan 3外部获取数字数据的样本。我最初希望每秒获取1000样本。 如何在VHDL编码中选择时钟频率?
谢谢。
不要使用计数器来产生低频时钟信号。
FPGA中的多个时钟频率会导致各种设计问题,其中一些属于“高级主题”,尽管可以(如有必要)解决所有这些问题,但了解如何使用单个快速时钟是非常重要的。既更简单又通常更好的做法(同步设计)。
相反,请使用FPGA板提供的任何快速时钟,并从中生成较低频率的定时信号,并且-至关重要的是-将它们用作时钟使能,而不是时钟信号。
DLL,DCM,PLL和其他时钟管理器确实有其用途,但即使它们的限制允许,生成1 kHz时钟信号通常也不是一个好方法。 这个应用程序只是在呼吁时钟启用...
另外,不要弄乱魔术数字,让VHDL编译器完成工作! 我已将时序要求打包在一起,因此您可以将它们与testbench以及需要使用它们的其他任何东西共享。
package timing is
-- Change the first two constants to match your system requirements...
constant Clock_Freq : real := 40.0E6;
constant Sample_Rate : real := 1000.0;
-- These are calculated from the above, so stay correct when you make changes
constant Divide : natural := natural(Clock_Freq / Sample_Rate);
-- sometimes you also need a period, e.g. in a testbench.
constant clock_period : time := 1 sec / Clock_Freq;
end package timing;
我们可以编写采样器,如下所示:(我将时钟使能分成了一个单独的过程,以阐明时钟使能的使用,但是可以将这两个过程轻松合并为一个,以进行进一步简化;“采样”信号将然后是不必要的)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
use work.timing.all;
entity sampler is
Port (
Clock : in std_logic;
Reset : in std_logic;
ADC_In : in signed(7 downto 0);
-- signed for audio, or unsigned, depending on your app
Sampled : out signed(7 downto 0);
);
end sampler;
architecture Behavioral of Sampler is
signal Sample : std_logic;
begin
Gen_Sample : process (Clock,Reset)
variable Count : natural;
begin
if reset = '1' then
Sample <= '0';
Count := 0;
elsif rising_edge(Clock) then
Sample <= '0';
Count := Count + 1;
if Count = Divide then
Sample <= '1';
Count := 0;
end if;
end if;
end process;
Sample_Data : process (Clock)
begin
if rising_edge(Clock) then
if Sample = '1' then
Sampled <= ADC_In;
end if;
end if;
end process;
end Behavioral;
基本时钟必须基于外部时钟,并且不能仅通过Spartan-3 FPGA中的内部资源生成。 如果需要,您可以使用Spartan-3 FPGA数字时钟管理器(DCM)资源来缩放外部时钟。 合成的VHDL代码本身无法生成时钟。
一旦有了一些较高频率(例如100 MHz)的基本时钟,就可以轻松地对其进行分频,以产生1 kHz的指示以用于外部输入的采样。
这取决于您可用的时钟频率。 如果您有20MHz的时钟源,则需要将其除以20000才能获得1KHz,您可以在VHDL中执行此操作,也可以使用DCM进行此操作。
这是一个有关如何从20MHz输入创建1kHz时钟的示例:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity clk20Hz is
Port (
clk_in : in STD_LOGIC;
reset : in STD_LOGIC;
clk_out: out STD_LOGIC
);
end clk200Hz;
architecture Behavioral of clk20Hz is
signal temporal: STD_LOGIC;
signal counter : integer range 0 to 10000 := 0;
begin
frequency_divider: process (reset, clk_in) begin
if (reset = '1') then
temporal <= '0';
counter <= 0;
elsif rising_edge(clk_in) then
if (counter = 10000) then
temporal <= NOT(temporal);
counter <= 0;
else
counter <= counter + 1;
end if;
end if;
end process;
clk_out <= temporal;
end Behavioral;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.