CNC Axis VHDL

Discussion in 'C Programming' started by Brian Ramirez, Jun 20, 2016.

  1. Brian Ramirez

    Brian Ramirez

    Joined:
    Jun 20, 2016
    Messages:
    1
    Likes Received:
    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;
     
    Brian Ramirez, Jun 20, 2016
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    5,405
    walala
    Sep 18, 2003
  2. Joey Vendetta
    Replies:
    0
    Views:
    3,977
    Joey Vendetta
    Apr 1, 2004
  3. Stefan
    Replies:
    0
    Views:
    1,079
    Stefan
    May 6, 2004
  4. Heiner Kücker
    Replies:
    1
    Views:
    804
    Joona I Palaste
    Dec 4, 2004
  5. unkwb@web.de
    Replies:
    0
    Views:
    1,454
    unkwb@web.de
    Feb 23, 2005
  6. hocho888
    Replies:
    1
    Views:
    984
    iksrazal@terra.com.br
    Apr 29, 2005
  7. ed
    Replies:
    2
    Views:
    736
    Mike Schilling
    Dec 8, 2006
  8. afd
    Replies:
    1
    Views:
    11,116
    Colin Paul Gloster
    Mar 23, 2007
Loading...