- Joined
- Jun 19, 2016
- Messages
- 1
- Reaction score
- 0
I want to know if this code has any problem, i want to build a cnc axis with VHDL but i dont know if this code is a loop because i can simulate 1s, help me pos
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_unsigned.all;
entity MotorX is
port( ABCDX: out std_logic_vector(3 downto 0):=(others => '0');
ABCDY: out std_logic_vector(3 downto 0):=(others => '0');
clk: in std_logic);
end MotorX;
architecture go of MotorX is
begin
process(clk)
variable dist : std_logic_vector(23 downto 0):= x"000000";
variable counter : std_logic_vector(31 downto 0):= x"00000000";
variable x1 : std_logic_vector(2 downto 0):="000";
variable x2 : std_logic_vector(2 downto 0):="000";
variable y1 : std_logic_vector(2 downto 0):="000";
variable y2 : std_logic_vector(2 downto 0):="000";
variable enable : std_logic:='0';
begin
if rising_edge (clk) and enable = '0' then
if dist < x"D48" then --da 3400 PULSOS en direccion (+X) aprox 24 cm si el eje tiene un radio de 0.5
case x1 is
when "000" => ABCDX <= "1000";
when "001" => ABCDX <= "1100";
when "010" => ABCDX <= "0100";
when "011" => ABCDX <= "0110";
when "100" => ABCDX <= "0010";
when "101" => ABCDX <= "0011";
when "110" => ABCDX <= "0001";
when others => ABCDX <= "1001";
end case;
x1 := x1 + 1 ;
dist := dist + 1 ;
enable := '1';
x2 := "000";
y1 := "000";
y2 := "000";
counter := x"00000000";
elsif dist >= x"D47" and dist < x"D50" then --8 pulsos en direccion (+Y) del lado derecho
case y1 is
when "000" => ABCDY <= "1000";
when "001" => ABCDY <= "1100";
when "010" => ABCDY <= "0100";
when "011" => ABCDY <= "0110";
when "100" => ABCDY <= "0010";
when "101" => ABCDY <= "0011";
when "110" => ABCDY <= "0001";
when others => ABCDY <= "1001";
end case;
y1 := y1 + 1 ;
dist := dist + 1 ;
enable := '1';
x1 := "000";
x2 := "000";
y2 := "000";
counter := x"00000000";
elsif dist >= x"D4F" and dist < x"1A98" then --da 3400 PULSOS en direccion (-X) aprox 24 cm si el eje tiene un radio de 0.5
case x2 is
when "000" => ABCDX <= "1001";
when "001" => ABCDX <= "0001";
when "010" => ABCDX <= "0011";
when "011" => ABCDX <= "0010";
when "100" => ABCDX <= "0110";
when "101" => ABCDX <= "0100";
when "110" => ABCDX <= "1100";
when others => ABCDX <= "1000";
end case;
x2 := x2 + 1 ;
dist := dist + 1 ;
enable := '1';
x1 := "000";
y1 := "000";
y2 := "000";
counter := x"00000000";
elsif dist >= x"1A97" and dist < x"1AA0" then --8 pulsos en direccion (+Y) del lado izquierdo
case y2 is
when "000" => ABCDY <= "1000";
when "001" => ABCDY <= "1100";
when "010" => ABCDY <= "0100";
when "011" => ABCDY <= "0110";
when "100" => ABCDY <= "0010";
when "101" => ABCDY <= "0011";
when "110" => ABCDY <= "0001";
when others => ABCDY <= "1001";
end case;
y2 := y2 + 1 ;
dist := dist + 1 ;
enable := '1';
x1 := "000";
x2 := "000";
y1 := "000";
counter := x"00000000";
end if;
if dist = x"1A9F" then --fin del ciclo y reinicio para que se haga un bucle infinito
dist := x"000000";
x1 := "000";
x2 := "000";
y1 := "000";
y2 := "000";
counter := x"00000000";
enable := '1';
end if;
end if;
if enable = '1' then --contador para que establecer timepo entre pulso y manejar la rapidez de giro
counter := counter + 1 ;
if counter = x"1E8480" then
enable := '0';
counter := x"00000000";
end if;
end if;
end process;
end go;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_unsigned.all;
entity MotorX is
port( ABCDX: out std_logic_vector(3 downto 0):=(others => '0');
ABCDY: out std_logic_vector(3 downto 0):=(others => '0');
clk: in std_logic);
end MotorX;
architecture go of MotorX is
begin
process(clk)
variable dist : std_logic_vector(23 downto 0):= x"000000";
variable counter : std_logic_vector(31 downto 0):= x"00000000";
variable x1 : std_logic_vector(2 downto 0):="000";
variable x2 : std_logic_vector(2 downto 0):="000";
variable y1 : std_logic_vector(2 downto 0):="000";
variable y2 : std_logic_vector(2 downto 0):="000";
variable enable : std_logic:='0';
begin
if rising_edge (clk) and enable = '0' then
if dist < x"D48" then --da 3400 PULSOS en direccion (+X) aprox 24 cm si el eje tiene un radio de 0.5
case x1 is
when "000" => ABCDX <= "1000";
when "001" => ABCDX <= "1100";
when "010" => ABCDX <= "0100";
when "011" => ABCDX <= "0110";
when "100" => ABCDX <= "0010";
when "101" => ABCDX <= "0011";
when "110" => ABCDX <= "0001";
when others => ABCDX <= "1001";
end case;
x1 := x1 + 1 ;
dist := dist + 1 ;
enable := '1';
x2 := "000";
y1 := "000";
y2 := "000";
counter := x"00000000";
elsif dist >= x"D47" and dist < x"D50" then --8 pulsos en direccion (+Y) del lado derecho
case y1 is
when "000" => ABCDY <= "1000";
when "001" => ABCDY <= "1100";
when "010" => ABCDY <= "0100";
when "011" => ABCDY <= "0110";
when "100" => ABCDY <= "0010";
when "101" => ABCDY <= "0011";
when "110" => ABCDY <= "0001";
when others => ABCDY <= "1001";
end case;
y1 := y1 + 1 ;
dist := dist + 1 ;
enable := '1';
x1 := "000";
x2 := "000";
y2 := "000";
counter := x"00000000";
elsif dist >= x"D4F" and dist < x"1A98" then --da 3400 PULSOS en direccion (-X) aprox 24 cm si el eje tiene un radio de 0.5
case x2 is
when "000" => ABCDX <= "1001";
when "001" => ABCDX <= "0001";
when "010" => ABCDX <= "0011";
when "011" => ABCDX <= "0010";
when "100" => ABCDX <= "0110";
when "101" => ABCDX <= "0100";
when "110" => ABCDX <= "1100";
when others => ABCDX <= "1000";
end case;
x2 := x2 + 1 ;
dist := dist + 1 ;
enable := '1';
x1 := "000";
y1 := "000";
y2 := "000";
counter := x"00000000";
elsif dist >= x"1A97" and dist < x"1AA0" then --8 pulsos en direccion (+Y) del lado izquierdo
case y2 is
when "000" => ABCDY <= "1000";
when "001" => ABCDY <= "1100";
when "010" => ABCDY <= "0100";
when "011" => ABCDY <= "0110";
when "100" => ABCDY <= "0010";
when "101" => ABCDY <= "0011";
when "110" => ABCDY <= "0001";
when others => ABCDY <= "1001";
end case;
y2 := y2 + 1 ;
dist := dist + 1 ;
enable := '1';
x1 := "000";
x2 := "000";
y1 := "000";
counter := x"00000000";
end if;
if dist = x"1A9F" then --fin del ciclo y reinicio para que se haga un bucle infinito
dist := x"000000";
x1 := "000";
x2 := "000";
y1 := "000";
y2 := "000";
counter := x"00000000";
enable := '1';
end if;
end if;
if enable = '1' then --contador para que establecer timepo entre pulso y manejar la rapidez de giro
counter := counter + 1 ;
if counter = x"1E8480" then
enable := '0';
counter := x"00000000";
end if;
end if;
end process;
end go;