prakash_kadri
Member level 2
Hi,
With some research I found the below VHDL code for RC servo motor. I am using "ax309-xilinx-spartan-6" board.
If i want to increase the speed of servo to reach the desired position, what is the more efficient way to do it?
1) Is it by doing faster increment of signal divrel ?
2) However, i don't see considerable increase in the speed if i do method 1). I checked my servo using servo tester board and it is capable of rotating at a faster rate. But I could not achieve the same in the code.
3) or there is any other approach?
With some research I found the below VHDL code for RC servo motor. I am using "ax309-xilinx-spartan-6" board.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.STD_LOGIC_unsigned.ALL; entity SPI_Servo is Port ( BTN : in STD_LOGIC_VECTOR (3 downto 0); SERVO : out STD_LOGIC; CLK50M : in STD_LOGIC); end SPI_Servo; architecture Behave of SPI_Servo is signal divrel : integer range 0 to 1500 := 1; signal div1us : integer range 0 to 49 := 0; signal div1ms : integer range 0 to 999 := 0; signal div10ms : integer range 0 to 9 := 0; signal us1 : std_logic; signal ms1 : std_logic; signal ms10 : std_logic; signal servocnt: integer range 0 to 20000 := 0; -- = 20ms signal servoloc : std_logic; begin -- generate a bunch of clock enable process begin wait until rising_edge(CLK50M); us1 <= '0'; ms1 <= '0'; ms10 <= '0'; if(div1us<49) then div1us <= div1us+1; else div1us <= 0; us1 <= '1'; if(div1ms<999) then div1ms <= div1ms+1; else div1ms <= 0; ms1 <= '1'; if(div1ms<9) then div10ms <= div10ms+1; else div10ms <= 0; ms10 <= '1'; end if; end if; end if; end process; -- every microsecond process begin wait until rising_edge(CLK50M); if (us1='1') then if (servocnt<19999) then servocnt<=servocnt+1; else servocnt<=0; end if; end if; if (servocnt=0) then servoloc <= '1'; end if; if (servocnt=700+divrel) then servoloc <= '0'; end if; end process; -- handle buttons each 10ms process begin wait until rising_edge(CLK50M); if(ms10='1') then if(BTN(0)='0' and divrel<500) then divrel <= divrel+1; end if; if(BTN(1)='0' and divrel<1000) then divrel <= divrel+1; end if; if(BTN(2)='0' and divrel<1500) then divrel <= divrel+1; end if; if(BTN(3)='0' and divrel>100) then divrel <= divrel-1; end if; end if; end process; SERVO <= servoloc; end Behave;
If i want to increase the speed of servo to reach the desired position, what is the more efficient way to do it?
1) Is it by doing faster increment of signal divrel ?
2) However, i don't see considerable increase in the speed if i do method 1). I checked my servo using servo tester board and it is capable of rotating at a faster rate. But I could not achieve the same in the code.
3) or there is any other approach?