Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Fase Final
Fase Final
Facultad de Ingeniería
Escuela de Mecánica Eléctrica
Laboratorio de Electrónica
Proyecto de Electrónica 3
Segundo Semestre de 2019
Tutor: Inga. Magdalena Puente
Detector de Disparo
El proyecto final de laboratorio consiste en crear un dispositivo que sea capaz de detectar
la ubicación (ángulo y distancia) de un evento por medio de la detección del sonido que
genera dicho evento. El ángulo y dirección del evento tienen que ser mostrados mediante
indicadores físicos. Para poder detectar la dirección del evento se requiere colocar 1
micrófono por cada esquina de un cuadrado, siendo 4 micrófonos en total. Así será
posible detectar el origen del evento en los 360 grados del plano XY. Para detectar la
dirección de la que provino el sonido se necesitaran usar comparadores de voltaje (con
amplificadores operacionales suficientemente rápidos) sin necesidad de usar un ADC. El
Voltaje DC de referencia de los comparadores de voltaje tiene que ser generado por
medio de una señal de PWM generado por la FPGA.
INTRODUCCION
Este proyecto se tratará de un detector de disparo el cual constará de 5 micrófonos, una
matriz de leds para indicar un mensaje y un servomotor para indicar la dirección del disparo
OBJETIVOS
Modulo pwm
Modulo micrófonos
[1] https://eprints.ucm.es/26200/1/intro_VHDL.pdf
entity Proyecto_final is
Port ( Clk : in STD_LOGIC;
M1 : in STD_LOGIC;
M2 : in STD_LOGIC;
M3 : in STD_LOGIC;
M4 : in STD_LOGIC;
reset : in STD_LOGIC;
boton : IN std_logic_vector(3 downto 0); ---
entradas adc
Display_uni : OUT std_logic_vector(3 downto 0);
Display_dece : OUT std_logic_vector(3 downto 0);
Display_cent : OUT std_logic_vector(3 downto 0);
enable : OUT std_logic_vector(7 downto 0);
PWM_S1 : out STD_LOGIC;
PWM_S2 : out STD_LOGIC
);
end Proyecto_final;
end component;
component microfonos
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
M1 : in STD_LOGIC;
M2 : in STD_LOGIC;
M3 : in STD_LOGIC;
M4 : in STD_LOGIC;
adc : in STD_LOGIC_VECTOR(3 DOWNTO 0);
verde : out STD_LOGIC;
uni: out integer;
dece: out integer;
cente: out integer;
uni_cont: in integer;
dece_cont: in integer;
cente_cont: in integer;
angulo_out : out integer);
end component;
COMPONENT matriz
PORT(
Clk : IN std_logic;
reset : IN std_logic;
uni: in integer;
dece: in integer;
cente: in integer;
Display_uni : OUT std_logic_vector(3 downto 0);
Display_dece : OUT std_logic_vector(3 downto 0);
Display_cent : OUT std_logic_vector(3 downto 0);
enable : OUT std_logic_vector(7 downto 0)
);
END COMPONENT;
COMPONENT adc1
PORT(
clk : IN std_logic;
reset : IN std_logic;
boton : IN std_logic_vector(3 downto 0);
O : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
COMPONENT contador
PORT(
clk : IN std_logic;
reset : IN std_logic;
s : IN std_logic;
uni_cont : OUT integer;
dece_cont : OUT integer;
cente_cont : OUT integer
);
END COMPONENT;
---$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
signal angulo_union : integer;
signal uni_u : integer:=0;
signal dece_u : integer:=0;
signal cente_u : integer:=0;
signal uni_c : integer:=0;
signal dece_c : integer:=0;
signal cente_c : integer:=0;
signal adc_union: std_logic_vector(3 downto 0);
signal verde_s: std_logic;
-----------------------------------------------------------
begin
end Behavioral;
MODULO PWM
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity pwm is
angulo_in: in integer);
end pwm;
------------------------------------------------------
signal angulo: integer range 0 to 360; ----valor recibido del angulo donde se encuentra el sonido
signal cambio: integer range 0 to 180;----valor recibido del angulo donde se encuentra el sonido
---------------------------------------------------
begin
------------------------------------------------------------------
process(Clk)
begin
---#########################################################
if (rising_edge(Clk)) then
if (contador_p=valor_maximo-1) then
contador_p<=0;
else
contador_p<= contador_p+1;
end if;
if angulo = 0 then
cambio<=5;
cambio<=60;
cambio<=80;
cambio<=95;
cambio<=115;
cambio<=125;
cambio<=145;
cambio<=180;
end if;
--SERVO 1---
If (contador_p<Tiempo*cambio) then
PWM_S1<='1';
else
PWM_S1<='0';
end if;
--SERVO 2---
PWM_S2<='1';
else
PWM_S2<='0';
end if;
cambio<=60;
cambio<=80;
cambio<=95;
cambio<=115;
cambio<=125;
cambio<=145;
cambio<=165;
end if;
--SERVO 1---
PWM_S1<='1';
else
PWM_S1<='0';
end if;
--SERVO 2--
If (contador_p<Tiempo*cambio) then
PWM_S2<='1';
else
PWM_S2<='0';
end if;
end if;
end if;
end process;
end Behavioral;
MODULO MICROFONOS
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity microfonos is
reset : in STD_LOGIC;
M1 : in STD_LOGIC;
M2 : in STD_LOGIC;
M3 : in STD_LOGIC;
M4 : in STD_LOGIC;
uni_cont: in integer;
dece_cont: in integer;
cente_cont: in integer;
end microfonos;
----------------------------------------------------------------------------------------------
signal reg_1_0, reg_2_0, reg_1_1, reg_2_1, reg_1_2, reg_2_2, reg_1_3, reg_2_3: std_logic ;
--
------------------------------------------------------------------------------------------------
begin
Mic(0)<= pulso_boton0;
Mic(1)<= pulso_boton1;
Mic(2)<= pulso_boton2;
Mic(3)<= pulso_boton3;
--microfono 1
begin
end if;
end process;
begin
end if;
end process;
pulso_boton0 <= '1' when (reg_1_0 = '0' and reg_2_0 = '1') else '0';
-- microfono 2
begin
end if;
end process;
begin
end if;
end process;
pulso_boton1 <= '1' when (reg_1_1 = '0' and reg_2_1 = '1') else '0';
--microfono 3
begin
end if;
end process;
begin
end if;
end process;
pulso_boton2 <= '1' when (reg_1_2 = '0' and reg_2_2 = '1') else '0';
--microfono 4
begin
end if;
end process;
begin
end if;
end process;
pulso_boton3 <= '1' when (reg_1_3 = '0' and reg_2_3 = '1') else '0';
------------------------------------------------------------------------------------------------
process(clk)
begin
if (rising_edge(Clk)) then
valor_grados<=0;
tiempo <= 2;
else
Case Estado_sistema is
else
conteo <= 0;
end if;
else
end if;
when Estado_medida =>
else
conteo <= 0;
end if;
else
Case adc is
uni<=10;
dece<=5;
cente<=0;
uni<=10;
dece<=0;
cente<=1;
uni<=10;
dece<=5;
cente<=1;
uni<=10;
dece<=0;
cente<=2;
end case;
tiempo <= 3;
end if;
valor_grados<=0;
uni<=0;
dece<=0;
cente<=0;
case Mic is
tiempo <= 3;
uni<=0;
dece<=0;
cente<=0;
when "0011" =>
tiempo <= 3;
uni<=0;
dece<=9;
cente<=0;
valor_grados<=180;
tiempo <= 3;
uni<=0;
dece<=8;
cente<=1;
tiempo <= 3;
uni<=0;
dece<=7;
cente<=2;
------------------------------------------------
-------------------------------------------------
------------------------------------------------
-------------------------------------------------
end case;
---**********************************---------------
if (Mic="1010") then--angulo 45
valor_grados<=45;
tiempo <= 3;
uni<=5;
dece<=4;
cente<=0;
elsif(Mic="1000") then--M2
tiempo <= 3;
uni<=5;
dece<=4;
cente<=0;
elsif(Mic="0010") then--M2
tiempo <= 3;
uni<=0;
dece<=9;
cente<=0;
end if;
---*******************************************--------
valor_grados<=135;
tiempo <= 3;
uni<=5;
dece<=3;
cente<=1;
valor_grados<=135;
tiempo <= 3;
uni<=5;
dece<=3;
cente<=1;
valor_grados<=180;
tiempo <= 3;
uni<=0;
dece<=8;
cente<=1;
end if;
----**********************************************
valor_grados<=225;
tiempo <= 3;
uni<=5;
dece<=2;
cente<=2;
tiempo <= 3;
uni<=5;
dece<=2;
cente<=2;
valor_grados<=270;
tiempo <= 3;
uni<=0;
dece<=7;
cente<=2;
end if;
----**********************************************
valor_grados<=315;
tiempo <= 3;
uni<=5;
dece<=1;
cente<=3;
valor_grados<=315;
tiempo <= 3;
uni<=5;
dece<=1;
cente<=3;
valor_grados<=360;
verde <= '0';
tiempo <= 3;
uni<=0;
dece<=6;
cente<=3;
end if;
---**************************
end case;
end if;
end if;
end process;
------------------------------------------------------------------------------------------------
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity matriz is
Port (
Clk : in STD_LOGIC;
reset : in STD_LOGIC;
uni: in integer;
dece: in integer;
cente: in integer;
Display_uni : out
std_logic_vector (3 downto 0);
Display_dece : out
std_logic_vector (3 downto 0);
Display_cent : out
std_logic_vector (3 downto 0);
enable : out std_logic_vector (7
downto 0));
end matriz;
"1111", --1
"1111", --2
"1111", --3
"1111", --4
"1111", --5
"1111", --6
"1111", --7
"1111", --8
"1111", --9
"1111");--10
constant col2: memoria_uni:= ("1001", --0
"1001", --1
"1001", --2
"0000", --3
"0110", --4
"0000", --5
"1000", --6
"0000", --7
"1001", --8
"0000", --9
"0110");--10
constant col3: memoria_uni:= ("0110", --0
"0001", --1
"0110", --2
"1110", --3
"0110", --4
"0111", --5
"0111", --6
"0100", --7
"0110", --8
"0110", --9
"0000");--10
constant col4: memoria_uni:= ("0110", --0
"1001", --1
"1110", --2
"1000", --3
"0110", --4
"0001", --5
"0001", --6
"1100", --7
"1001", --8
"0000", --9
"0000");--10
"1001", --1
"1101", --2
"1110", --3
"0000", --4
"1100", --5
"0110", --6
"1100", --7
"0110", --8
"1110", --9
"0110");--10
constant col6: memoria_uni:= ("0110", --0
"1001", --1
"1011", --2
"0110", --3
"1110", --4
"1100", --5
"0110",--6
"1100", --7
"0110", --8
"1110", --9
"0110");--10
constant col7: memoria_uni:= ("1001", --0
"0000", --1
"0000", --2
"1001", --3
"1110", --4
"0001", --5
"1001",--6
"1100", --7
"1001", --8
"1110", --9
"0110");--10
constant col8: memoria_uni:= ("1111", --0
"1111", --1
"1111", --2
"1111", --3
"1111", --4
"1111", --5
"1111", --6
"1111", --7
"1111", --8
"1111", --9
"1111");--10
-------*****************************************************-------------------
constant col1_dece: memoria_dece:= ("1111", --0
"1111", --1
"1111", --2
"1111", --3
"1111", --4
"1111", --5
"1111", --6
"1111", --7
"1111", --8
"1111");--9
constant col2_dece: memoria_dece:= ("1001", --0
"1001", --1
"1001", --2
"0000", --3
"0110", --4
"0000", --5
"1000", --6
"0000", --7
"1001", --8
"0000");--9
constant col3_dece: memoria_dece:= ("0110", --0
"0001", --1
"0110", --2
"1110", --3
"0110", --4
"0111", --5
"0111", --6
"0100", --7
"0110", --8
"0110");--9
constant col4_dece: memoria_dece:= ("0110", --0
"1001", --1
"1110", --2
"1000", --3
"0110", --4
"0001", --5
"0001", --6
"1100", --7
"1001", --8
"0000");--9
"1001", --1
"1101", --2
"1110", --3
"0000", --4
"1100", --5
"0110", --6
"1100", --7
"0110", --8
"1110");--9
constant col6_dece: memoria_dece:= ("0110", --0
"1001", --1
"1011", --2
"0110", --3
"1110", --4
"1100", --5
"0110",--6
"1100", --7
"0110", --8
"1110");--9
constant col7_dece: memoria_dece:= ("1001", --0
"0000", --1
"0000", --2
"1001", --3
"1110", --4
"0001", --5
"1001",--6
"1100", --7
"1001", --8
"1110");--9
constant col8_dece: memoria_dece:= ("1111", --0
"1111", --1
"1111", --2
"1111", --3
"1111", --4
"1111", --5
"1111", --6
"1111", --7
"1111", --8
"1111");--9
----********************************************************----
constant col1_cent: memoria_cent:= ("1111", --0
"1111", --1
"1111", --2
"1111", --3
"1111", --4
"1111", --5
"1111", --6
"1111", --7
"1111", --8
"1111");--9
constant col2_cent: memoria_cent:= ("1001", --0
"1001", --1
"1001", --2
"0000", --3
"0110", --4
"0000", --5
"1000", --6
"0000", --7
"1001", --8
"0000");--9
constant col3_cent: memoria_cent:= ("0110", --0
"0001", --1
"0110", --2
"1110", --3
"0110", --4
"0111", --5
"0111", --6
"0100", --7
"0110", --8
"0110");--9
constant col4_cent: memoria_cent:= ("0110", --0
"1001", --1
"1110", --2
"1000", --3
"0110", --4
"0001", --5
"0001", --6
"1100", --7
"1001", --8
"0000");--9
"1001", --1
"1101", --2
"1110", --3
"0000", --4
"1100", --5
"0110", --6
"1100", --7
"0110", --8
"1110");--9
constant col6_cent: memoria_cent:= ("0110", --0
"1001", --1
"1011", --2
"0110", --3
"1110", --4
"1100", --5
"0110",--6
"1100", --7
"0110", --8
"1110");--9
constant col7_cent: memoria_cent:= ("1001", --0
"0000", --1
"0000", --2
"1001", --3
"1110", --4
"0001", --5
"1001",--6
"1100", --7
"1001", --8
"1110");--9
constant col8_cent: memoria_cent:= ("1111", --0
"1111", --1
"1111", --2
"1111", --3
"1111", --4
"1111", --5
"1111", --6
"1111", --7
"1111", --8
"1111");--9
begin
enable <= estado_enable;
process (Clk)
begin
if (rising_edge (Clk)) then
-- multiplexado
if(mux = 12000) then
mux <= 0;
if(estado_enable =
"00000001") then
estado_enable <=
"00000010";
Display_uni <= col2
(uni);
Display_dece <=
col2_dece (dece);
Display_cent <=
col2_cent (cente);
elsif(estado_enable =
"00000010") then
estado_enable <=
"00000100";
Display_uni <= col3
(uni);
Display_dece <=
col3_dece (dece);
Display_cent <=
col3_cent (cente);
elsif(estado_enable =
"00000100") then
estado_enable <=
"00001000";
Display_uni <= col4
(uni);
Display_dece <=
col4_dece (dece);
Display_cent <=
col4_cent (cente);
elsif(estado_enable =
"00001000") then
estado_enable <=
"00010000";
Display_uni <= col5
(uni);
Display_dece <=
col5_dece (dece);
Display_cent <=
col5_cent (cente);
elsif(estado_enable =
"00010000") then
estado_enable <=
"00100000";
Display_uni <= col6
(uni);
Display_dece <=
col6_dece (dece);
Display_cent <=
col6_cent (cente);
elsif(estado_enable =
"00100000") then
estado_enable <=
"01000000";
Display_uni <= col7
(uni);
Display_dece <=
col7_dece (dece);
Display_cent <=
col7_cent (cente);
elsif(estado_enable =
"01000000") then
estado_enable <=
"10000000";
Display_uni <= col8
(uni);
Display_dece <=
col8_dece (dece);
Display_cent <=
col8_cent (cente);
elsif(estado_enable =
"10000000") then
estado_enable <=
"00000001";
Display_uni <= col1
(uni);
Display_dece <=
col1_dece (dece);
Display_cent <=
col1_cent (cente);
else
estado_enable <=
"00000001";
end if;
else
mux <= mux + 1;
end if;
end if;
end process;
end Behavioral;
MODULO CONTADOR
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity contador is
Port(
--Señales de control; reset y señal de reloj.
clk: in std_logic;
reset: in std_logic;
--Push boton para el conteo.
s: in std_logic;
uni_cont: out integer;
dece_cont: out integer;
cente_cont: out integer
--Salidas para el control de los Display's.
);
end contador;
begin
uni_cont <= unidades;
dece_cont <= decenas;
cente_cont <= centenas;
Cont_up <= temporal;
process (clk, reset) begin
if(reset = '0')then
temporal <= '0';
contador <= 0;
elsif falling_edge(clk) then
if (s <= '0') then
if (contador = 5999)then
temporal <= not(temporal);
contador <= 0;
else
contador <= contador + 1;
end if;
end if;
end if;
end process;
process(clk, reset)
begin
conteo <= 0;
unidades <= 0;
decenas <= 0;
centenas <= 0;
elsif(rising_edge(clk)) then
else
conteo <= conteo + 1;
end if;
end if;
end process;
end Behavioral;