VHDL超声波传感器(HC-SR04) [英] vhdl-ultrasonic sensor(hc-sr04)

查看:217
本文介绍了VHDL超声波传感器(HC-SR04)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目.在我的项目中,我正在创建一辆汽车,使汽车旁边的物体与汽车本身之间保持一定的距离.但是,编码对我来说很头疼.我创建了3个不同的项目,在我看来所有这些项目都还不错.但是他们都没有实践.然后,我创建了此代码(最容易理解的代码-完全没有组件).

I have a project. In my project, I am creating a car that keeps the distance between anything next to the car and the car itself. But, coding is a headache for me. I created 3 different project, and all of them seemed to me okay. Yet none of them worked in practice. Then, I created this code(the most basic one to understand-- no component at all).

传感器需要10 us脉冲,并等待100ms的新脉冲.当我发送触发信号时,传感器会响应并发送超声波.当它等待接收回波时,传感器发送5v信号,我找到了该信号的持续时间.根据这个持续时间,我将信号(马达)更改为10,01或11.从理论上讲,它是有效的,但实际上它是无效的.

The sensor need 10 us pulse and waits for new pulse for 100ms. When I send the trigger signal, sensor responses and sends a ultrasonic wave. While it waits to recieve the echo back, the sensor sends 5v signal and and I find the duration of this signal. According to thisduration, I change the signal(motor) to 10,01 or to 11. In theory, ıt works but in preactice it does not work.

这是代码.

begin
  process(clk)
    variable c1,c2: integer:=0;
    variable y :std_logic:='1';
  begin
    if rising_edge(clk) then

        if(c1=0) then
            trig<='1';
        elsif(c1=500) then--100us
            trig<='0';
            y:='1';
        elsif(c1=5000000) then-- 100 ms
            c1:=0;
            trig<='1';
        end if;
        c1:=c1+1;

        if(echo = '1') then
            c2:=c2+1;
        elsif(echo = '0' and y='1' ) then-- I change the y to not get echo_time =0;
            echo_time<= c2;
            c2:=0;
            y:='0';
        end if;

        if(echo_time < 100000) then--20 cm
            motor<="10";
        elsif(echo_time > 150000)then--30 cm
            motor<="01";
        else-- between  
            motor<="11";
        end if;
    end if; 
end process ;

`

我无法解决我的问题.对我来说,一切似乎都很好.我创建了一个仿真和虚构信号.在PC上,它可以工作,但在现实生活中却不行.

I could not solve my problem. Everything seems fine to me. I created a simulation and imaginary signal. On pc, it works, but in the real life it doesn't.

Pleeaaassssee帮助我.

Pleeaaassssee help me.

问题已解决,代码正在运行.我给传感器提供3.3V作为Vcc,然后我意识到应该给5v.有效.谢谢大家.

Problem solved, code is working. I was giving 3.3V to sensor as Vcc, then I realized that I should give 5v. It worked. Thank you for everyone.

推荐答案

问题已解决,代码正在运行.我给传感器提供3.3V作为Vcc,然后我意识到应该给5v.有效.谢谢大家.

Problem solved, code is working. I was giving 3.3V to sensor as Vcc, then I realized that I should give 5v. It worked. Thank you for everyone.

这篇关于VHDL超声波传感器(HC-SR04)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆