Jump to content
ELFORUM - Forumul electronistilor

HC-SR04 with FPGA


Recommended Posts

Salut,

 

Din cand in cand ma mai joc cu diferiti senzori si ii interfatez cu FPGA. Ma folosesc de NEXYS 4 DDR ca placa de dezolvoltare pe care o configurez folosindu-ma de compilatorul VIVADO si limbajul VHDL.

In mare parte ma folosesc de exemple gasite pe net pe care le modific pentru nevoile mele (in cazul de fata partea de afisare pe 7 segmente), dar am scris partea de achizitie a senzorului HC-SR04 => senzor de proximitate bazat pe ultrasunete.

Mai jos este modul pe care l-am scris pentru configurarea FPGA sa imi faca achizitia si prelucrarea pulsului de la sensor.

library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;use IEEE.NUMERIC_STD.ALL;entity HCSR04 is    Port ( clk : in STD_LOGIC;           rst : in STD_LOGIC;           ECHO : in STD_LOGIC;           led:  out STD_LOGIC;           data_to_print: out STD_LOGIC_VECTOR(11 downto 0);           TRIG : out STD_LOGIC);end HCSR04;architecture Behavioral of HCSR04 issignal echo_time: integer:=0;begin       process(clk)    variable counter1,counter2: integer :=0;    variable flag: std_logic := '1';    begin     if (rising_edge(clk) AND rst = '0')then         counter1 := counter1+1;            if (counter1 = 0) then            TRIG<= '1';            elsif(counter1 = 10000) then  --100us (10ns clk period)            TRIG<= '0';            flag:= '1';            elsif(counter1 = 30000000) then --300ms (10ns clk period)            counter1 := 0;            TRIG<= '1';            end if;           if (ECHO = '1') then  --if echo signal from sensor available            counter2:=counter2+1;           elsif (ECHO = '0' AND flag = '1') then            echo_time<= counter2;            counter2:=0;            flag:='0';             end if;              if (echo_time < 58000 ) then              led <= '1';              else               led<= '0';            end if;                            data_to_print <= STD_LOGIC_VECTOR(to_unsigned(echo_time/5800,12)); --converting distance in  cm  end if;          end process;end Behavioral;

Sunt sigur ca mai e loc de imbunatatit, dar pe moment functioneaza bine.

 

In fotografie apare si o placa de dezvoltare Arduino pe care o folosesc doar sa alimentez senzorul cu 5V, de asemeni am folosit si un level translator de la 3.3V la 5V. (senzorul lucreaza doar cu 5V)

Posted Image

 

 

Iar in urmatorul link aveti tot proiectul in VIVADO.

 

https://www.dropbox.com/s/aun0ffz8zb8n42t/Range%20finder.rar?dl=0

 

Sper ca mai sunt pasionati de FPGA-uri pe forum.

 

Bafta,

Vlad

 

 

Edited by Vlad Mihai
Link to comment
  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines