我的目标是在我的FPGA(DE1-SOC)上实现一个超声波传感器(HC-SR04),这样我的LED的值就会随着障碍物的距离而变化。
我正在用VHDL编写QUARTUS II。我的问题是,当我上传到我的卡时,没有LED灯亮起。
我的代码如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity SENSOR is
port (
clk : in std_logic;
rst : in std_logic;
trig : out std_logic;
echo : in std_logic;
LEDR : out std_logic_vector(9 downto 0)
);
end entity SENSOR;
architecture rtl of SENSOR is
signal tick_us : std_logic;
signal tick_us_ctr : integer range 0 to 50;
signal trig_ctr : integer range 0 to 60_010;
signal echo_width_us : integer range 0 to 40_000;
signal out_range : std_logic :='0'; -- verifie depassement 40 ms de echo_width_us
begin
gen_tick_us : process(clk, rst)
begin
if rst = '1' then
tick_us_ctr <= 0;
tick_us <= '0';
elsif rising_edge(clk) then
if tick_us_ctr >= 50-1 then
tick_us <= '1';
tick_us_ctr <= 0;
else
tick_us <= '0';
tick_us_ctr <= tick_us_ctr + 1;
end if;
end if;
end process;
gen_trig : process(clk, rst)
begin
if rst = '1' then
trig <= '0';
trig_ctr <= 0;
elsif rising_edge(clk) and tick_us = '1' then -- every 1 us
if trig_ctr >= 60_010-1 then -- 60 ms + 10 us
trig <= '0';
trig_ctr <= 0;
elsif trig_ctr = 60_000-1 then -- 60 ms
trig <= '1';
trig_ctr <= trig_ctr + 1;
else
trig_ctr <= trig_ctr + 1;
end if;
end if;
end process;
measure_width : process(clk, rst)
begin
if rst = '1' then
echo_width_us <= 0;
LEDR <= (others => '0');
elsif rising_edge(clk) and tick_us = '1' then -- every 1 us
if echo = '1' then
if echo_width_us < 40_001 then
echo_width_us <= echo_width_us + 1;
else
out_range <= '1';
end if;
elsif echo = '0' and echo_width_us > 0 then
if out_range ='1' then
echo_width_us <= 0;
out_range <= '0';
LEDR <= (others => '0');
else
echo_width_us <= 0;
LEDR <= std_logic_vector(to_unsigned(echo_width_us / 58, 10));
--ledr <= (others => '0');
--ledr() >= '1';
end if;
end if;
end if;
end process;
end architecture;我知道这个方法是可行的,因为我在ModelSim上通过制作我的TestBench来测试它:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity SENSOR_TestBench is
end entity SENSOR_TestBench;
architecture rtl of SENSOR_TestBench is
signal clk_50 : std_logic;
signal rst : std_logic;
signal trig : std_logic;
signal echo : std_logic;
signal ledr : std_logic_vector(9 downto 0);
begin
uut : entity work.SENSOR
port map (
clk => clk_50,
rst => rst,
trig => trig,
echo => echo,
ledr => ledr
);
clk_rst : process
begin
rst <= '1';
clk_50 <= '0';
wait for 10 ns;
rst <= '0';
wait for 10 ns;
for i in 0 to 50 * 1000 * 1000 loop
clk_50 <= '1';
wait for 10 ns;
clk_50 <= '0';
wait for 10 ns;
end loop;
end process;
process
begin
echo <= '0';
wait for 100 ns;
wait until trig = '1';
wait for 10 us;
echo <= '1';
wait for 5 ms;
echo <= '0';
wait until trig = '1';
wait for 10 us;
echo <= '1';
wait for 10 ms;
echo <= '0';
wait until trig = '1';
wait for 10 us;
echo <= '1';
wait for 25 ms;
echo <= '0';
wait until trig = '1';
wait for 10 us;
echo <= '1';
wait for 50 ms;
echo <= '0';
end process;
end architecture;我也不认为这是PIN映射问题,我尊重卡片的用户手册:
我开始使用QUARTUS II,所以我想我可能忘记了上传我的卡中的代码的一个步骤:
我还测试了我的覆盆子上的超声波传感器,看看它是否有故障,但它工作得很好:
Test Ultrasonic sensor on Raspberry
我不知道该做什么,如果有人有一个想法,我会全盘接受。
感谢您的回答!
发布于 2020-10-27 04:11:40
如果你不确定你对Quartus做了什么。我建议你从一个简单的时钟分频器(即一个大的计数器)开始,并将MSB分配给输出led。一旦你看到led的切换,你就会知道你的实现步骤和你的编程步骤都是正确的。然后,您可以返回到特定的传感器模块。
https://stackoverflow.com/questions/64542015
复制相似问题