Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Speed of RC Servo VHDL code

Status
Not open for further replies.

prakash_kadri

Member level 2
Joined
Apr 11, 2013
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bangalore
Activity points
1,721
Hi,

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?
 

Is it by doing faster increment of signal divrel ?
Yes, divrel is the servo set point. Every thing else in the code should be kept.
 

Yes, divrel is the servo set point. Every thing else in the code should be kept.

1) What should be the max increment we can give to divrel? How we decide that, by trial and error?

2)If I modify the program as below, it is supposed to reach the desired position with the maximum speed?.

Code:
 process begin
wait until rising_edge(CLK50M);
if(ms10='1') then

if BTN(0)='0' then divrel <= 500; end if;
if BTN(1)='0' then divrel <= 1000; end if;
if BTN(2)='0' then divrel <= 1500; end if;
if BTN(3)='0' then divrel <= 100; end if;


end if;
end process;
 

It's possible to change the RC servo setpoint immediately from left to right stop. Question is if the connected hardware likes it. Also the servo lifetime might be affected.

Standard pulse width range for servos is 500 to 2500 µs, it's not fully used in the example. Digital servos may be interpreting out of range pulse widths as disable command, check the documentation of your servo.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top