Está en la página 1de 9

Universidad Nacional Autónoma de México

Facultad de Ingeniería

Diseño digital VLSI

Práctica 4: Diseño del control de


servomotores

Sánchez Cano Alan

Grupo: 3

1
Contenido
Parte básica. ........................................................................................................................................................................ 3
Código del divisor: ......................................................................................................................................................... 3
Código de PWM: ............................................................................................................................................................ 3
Código de Servomotor: ................................................................................................................................................... 4
Parte complementaria. ........................................................................................................................................................ 6
Primera actividad complementaria: ................................................................................................................................ 6
Código de Divisor:.......................................................................................................................................................... 6
Código de PWM: ............................................................................................................................................................ 6
Código de Servomotor: ................................................................................................................................................... 7
Conclusión. ......................................................................................................................................................................... 9

2
Parte básica.
Al principio se nos muestran tres códigos que corresponden al servomotor, PWM y el ya
visto divisor. Los dos últimos códigos se implementan en el código del servomotor
portándolos. En el divisor observamos el tiempo de respuesta, en este caso a N le damos el
valor de 11 que en tiempo es 81.9 us, se utiliza este número porque al multiplicarlo por 28 se
tiene aproximadamente 20 ms.

En el servomotor se controlan 4 elementos, dos de ellos se utilizan para poner al inicio o al


final la punta del servomotor (en nuestro caso los switches), los otros dos mueven paso a
paso, dependiendo de qué tanto se deje mantenido, la punta del servomotor de fin a inicio o
viceversa (en nuestro caso los push botton). En este código también se le hizo la modificación
en cuanto a las variables INC y DEC ya que en las tarjetas DE10 Lite se tenía que dejar
presionado los dos para ver su funcionamiento, por ello se tuvieron que negar.

Los códigos son los siguientes:

Código del divisor:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Divisor is
Port (clk : in std_logic;
div_clk : out std_logic);
end Divisor;

architecture Behavioral of Divisor is


begin
process(clk)
constant N:integer := 11;
variable cuenta: std_logic_vector (27 downto 0) := X"0000000";
begin
if rising_edge(clk) then
cuenta := cuenta + 1;
end if;
div_clk <= cuenta(N);
end process;
end Behavioral;

Código de PWM:
3
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity PWM is
Port ( Reloj : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (7 downto 0);
S : out STD_LOGIC);
end PWM;

architecture Behavioral of PWM is


begin
process (Reloj)
variable Cuenta : integer range 0 to 255 := 0;
begin
if Reloj='1' and Reloj'event then
Cuenta := (Cuenta +1 ) mod 256;
if Cuenta < D then
S <= '1';
else
S <= '0';
end if;
end if;
end process;
end Behavioral;

Código de Servomotor:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Servomotor is
Port ( clk : in STD_LOGIC;
Pini : in STD_LOGIC;
Pfin : in STD_LOGIC;
Inc : in STD_LOGIC;
Dec : in STD_LOGIC;
control: out STD_LOGIC);
end Servomotor;

4
architecture Behavioral of Servomotor is
component divisor is
Port ( clk : in STD_LOGIC;
div_clk : out STD_LOGIC);
end component;
component PWM is
Port ( Reloj : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (7 downto 0);
S : out STD_LOGIC);
end component;
signal reloj : STD_LOGIC;
signal ancho : STD_LOGIC_VECTOR (7 downto 0) := X"0F";
begin
U1: divisor port map (clk, reloj);
U2: PWM port map (reloj, ancho, control);

process (reloj, Pini, Pfin, Inc, Dec)


variable valor : STD_LOGIC_VECTOR (7 downto 0) := X"0F";
variable cuenta: integer range 0 to 1023 := 0;
begin
if reloj='1' and reloj'event then
if cuenta>0 then
cuenta := cuenta - 1;
else
if Pini='1' then
valor:= X"0D";
elsif Pfin = '1' then
valor := X"18";
elsif Inc='0' and valor<X"18" then
valor := valor + 1;
elsif Dec='0' and valor>X"0D" then
valor := valor - 1;
end if;
cuenta := 1023;
ancho <= valor;
end if;
end if;
end process;
end Behavioral;

5
Parte complementaria.

Primera actividad complementaria:

En este primer caso se nos pide la modificación de 8 a 16 bits. Para ello se tuvo que calcular
el contador pasa de ser de 28 a 216 = 65536, la N que se utiliza en el divisor también va
asociado a ello y el valor es 3 ya que 0.320 us por 65536 son aproximadamente 20 ms. Donde
también hubo cambios fue en el control que tiene la parte de “Servomotor” para el 5% se
obtuvo, en hexadecimal, X”0CC5” y para el 10% X”199A”.

Código de Divisor:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Divisor is
Port (clk : in std_logic;
div_clk : out std_logic);
end Divisor;

architecture Behavioral of Divisor is


begin
process(clk)
constant N:integer := 3; -- N : Valor que define el indice del divisor
--13 -> 65536(328x10-6) = 21.5 ms
variable cuenta: std_logic_vector (27 downto 0) := X"0000000";
begin
if rising_edge(clk) then
cuenta := cuenta + 1;
end if;
div_clk <= cuenta(N);
end process;
end Behavioral;

Código de PWM:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

6
--Trabaja a partir de un contador de 16 bits (2^16 = 65536 valores)
entity PWM is
Port ( Reloj : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (15 downto 0);
S : out STD_LOGIC);
end PWM;

architecture Behavioral of PWM is


begin
process (Reloj)
variable Cuenta : integer range 0 to 65535 := 0;
begin
if Reloj='1' and Reloj'event then
Cuenta := (Cuenta +1 ) mod 65535;
if Cuenta < D then
S <= '1';
else
S <= '0';
end if;
end if;
end process;
end Behavioral;

Código de Servomotor:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Servomotor is
Port ( clk : in STD_LOGIC;
Pini : in STD_LOGIC;
Pfin : in STD_LOGIC;
Inc : in STD_LOGIC;
Dec : in STD_LOGIC;
control: out STD_LOGIC);
end Servomotor;

architecture Behavioral of Servomotor is


component divisor is
Port ( clk : in STD_LOGIC;
div_clk : out STD_LOGIC);
7
end component;

component PWM is
Port ( Reloj : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (15 downto
0);
S : out STD_LOGIC);
end component;
signal reloj : STD_LOGIC;
signal ancho : STD_LOGIC_VECTOR (15 downto 0) := X"000F";
begin
U1: divisor port map (clk, reloj);
U2: PWM port map (reloj, ancho, control);

process (reloj, Pini, Pfin, Inc, Dec)


variable valor : STD_LOGIC_VECTOR (15 downto 0) := X"0CC5";
variable cuenta: integer range 0 to 1023 := 0;
begin
if reloj='1' and reloj'event then
if cuenta>0 then
cuenta := cuenta - 1;
else
if Pini='1' then
valor:= X"0CC5";
elsif Pfin = '1' then
valor := X"199A";
elsif Inc='0' and valor<X"199A" then
valor := valor + 1;
elsif Dec='0' and valor>X"0CC5" then
valor := valor - 1;
end if;

cuenta := 1023;
ancho <= valor;
end if;
end if;
end process;
end Behavioral;

8
Conclusión.

Es la primera vez que utilizo algo de manera externa a la tarjeta DE10 Lite y también la
primera vez que hago funcionar un motor con las señales mandadas desde la tarjeta, fue una
práctica en la que se recordó el uso, la obtención y la implementación del tiempo, el ancho en
el cual está en 1 durante el ciclo de trabajo, etc. Recordó el uso de la división de frecuencia,
pero esta vez para hacer funcionar el servomotor. Al ser la primera vez utilizándolo con estos
dispositivos externos se me dificultó la obtención de las actividades complementarias.

También podría gustarte

  • Práctica1 VLSI
    Práctica1 VLSI
    Documento11 páginas
    Práctica1 VLSI
    Maximiliano Quiñones Reyes
    Aún no hay calificaciones
  • Tema02 Ejercicio 01 Ms
    Tema02 Ejercicio 01 Ms
    Documento5 páginas
    Tema02 Ejercicio 01 Ms
    Maximiliano Quiñones Reyes
    Aún no hay calificaciones
  • Tema 05
    Tema 05
    Documento24 páginas
    Tema 05
    Maximiliano Quiñones Reyes
    Aún no hay calificaciones
  • Tema 01
    Tema 01
    Documento19 páginas
    Tema 01
    Maximiliano Quiñones Reyes
    Aún no hay calificaciones
  • Tema 02
    Tema 02
    Documento33 páginas
    Tema 02
    Maximiliano Quiñones Reyes
    Aún no hay calificaciones
  • Tema 04
    Tema 04
    Documento45 páginas
    Tema 04
    Maximiliano Quiñones Reyes
    Aún no hay calificaciones
  • Tema 03
    Tema 03
    Documento31 páginas
    Tema 03
    Maximiliano Quiñones Reyes
    Aún no hay calificaciones