# Servo motor control...

Discussion in 'Microcontrollers' started by koolguy, Sep 26, 2013.

Joined:
Mar 28, 2011
Messages:
9,148
Likes:
907
Location:
Rochdale UK
ONLINE
See.... I don't understand.... What do you mean....

If you are trying to delay by 1Us then with a while(x--) ( this is test and decrement a word variable ). then its not possible in C..... I have shown that it takes 10 cycles in the while statement... That's too much time... If I pass 1000, ie 1mS, it would delay FAR too long... Why don't you just use the inbuilt delay functions, or write youur own in assembly.. I can't explain any further..

If you are asking why I'm using 1500 in the routine.... 1500uS is 1.5mS... CENTER POSITION... Look at Mr T's diagram...

2. ### koolguyActive Member

Joined:
Aug 24, 2010
Messages:
2,196
Likes:
9
i was saying you are diving by 1500 why not 1000 or 2000..

Code (text):
A 20Mhz clock gives a .2nS clock cycle
10 * 2nS = 5uS
1500 / 5 = 300 ... dividing by 5 gives 300 iterations.

Joined:
Mar 28, 2011
Messages:
9,148
Likes:
907
Location:
Rochdale UK
ONLINE
The delay routine divides ANY number thrown at it... I use 1500 because its the one I'm using in the code.

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### jpanhaltWell-Known MemberMost Helpful Member

Joined:
Jun 21, 2006
Messages:
5,887
Likes:
500
Location:
Cleveland, OH, USA
ONLINE

I think there was confusion about Ritesh's servo and that was resolved yesterday with Ian. The proximity of your comment to Ian's made it appear that you were also promoting 1.9 KHz for "modern" hobby servos. I think it is obvious why that won't work with the universally used data format for such servos. But, being always open to new things, I asked for your examples. That matter, I believe, is now closed.

Regular analog servos do work above 50 Hz as mentioned. I have some "modern," 2-uS-deadband, digital servos* that I will test when I get time (8 uS is the more common deadband). Although servos can be made to operate with a faster repeat rate, there is little advantage in doing so. One such advantage is being able to use the PIC built-in PWM generator, particularly if you do not need very fine control. It is also said that the refresh rate, especially slower rates, affects the speed with which the servo reaches its assigned position. But, there are much better and more precise ways to control servo speed.

Although digital servos are newer and have some advantages over analog servos, I think it is a mistake to assume they are "better" and will eclipse analog servos. One of the disadvantages of digital servos is their high idle current. Where weight may be a premium, such as some sailplanes, analog servos have an advantage. Another, probably lesser matter is noise. Digital servos tend to hunt and make more noise when idling.

John

*Like this one: http://www.servocity.com/html/hs-7985mg_servo.html

6. ### misterTWell-Known MemberMost Helpful Member

Joined:
Apr 19, 2010
Messages:
2,697
Likes:
368
Location:
Finland
Yes, I went along with Ians suggestion because I've heard that some servos can operate at surprisingly high rate (well, obviously 1.9Khz is way too high for analog servo), and because it is easy to test, and because too high update rate does not break the servo so it is safe to test. I have never tested the limits though. Too bad Ritesh struggles to get any proper (known) signal form out of the PIC.

7. ### koolguyActive Member

Joined:
Aug 24, 2010
Messages:
2,196
Likes:
9
Yes it will divide why 1500 is used at default, b'coz to set servo at center...?

Joined:
Mar 28, 2011
Messages:
9,148
Likes:
907
Location:
Rochdale UK
ONLINE
The servo I'm using here I'm throwing 1520 at it and the servo sits at +0.81 degrees Close enough...

9. ### JimBSuper ModeratorMost Helpful Member

Joined:
Sep 11, 2004
Messages:
6,324
Likes:
585
Location:
ONLINE
At the risk of derailing this thread even more, India became independant from Britain in 1947, Malaya became independant in 1957 (I think).
What have you guys been doing in the past 50/60 years?

As a product of the old "British System" of education as practiced in the UK in the 1950s and 1960s, it worked reasonably well for me, and many others.

JimB

• Like x 1
10. ### koolguyActive Member

Joined:
Aug 24, 2010
Messages:
2,196
Likes:
9
I have seen that at the place of ADC i was using manually 0, 512, 1024 it was to total 90* and when i use this code is work for 180* perfect..

while(1){
number=number*3;
RC2=1;
DelayUs(number+ 700);
RC2=0;
__delay_ms(10);
}

11. ### Brian GriffinMember

Joined:
May 23, 2013
Messages:
49
Likes:
8
Location:
Kuala Lumpur
Yeah, that. But, ugh, I can't feel like explaining about that past 50/60 years. It worked pretty good in the UK but not the rest of those former colonies.

Not to derail the topic, can't the OP use an oscilloscope? Perhaps spend a 15-20 minutes in a lab to borrow an oscilloscope? Back when I don't have them, I used the lab first.

12. ### Vizier87Active Member

Joined:
May 12, 2009
Messages:
1,495
Likes:
12
Location:
Johor Bahru, Malaysia
Yes you're right. 1957. Anyway I think with Ritesh it's quite a lot about his phrasing the questions. MisterT, I understand your feelings. Perhaps you should PM EM and let him decide on how the discretion on approving members here goes.

I hope I'm not an annoyance to ETO, since I'm an Asian (Chinese). I have contributed in small areas i.e sensors and I learnt LOADS from here. I literally finished my projects just through asking around in this forum. However, it is very rare to see fellow Malaysians post here though, since most of the students don't really do much projects at the first place.

Cheers.
Vizier87

13. ### ghostman11Well-Known Member

Joined:
Nov 22, 2009
Messages:
1,192
Likes:
99
Location:
Scotland
i am with LG on this one, i have read this thread from start to finish and like many others towards the end more and more detailed info gets thrown in often out of frustration in trying to make a OP understand something. if Ritesh had got it straightaway (wich he could of as all the info was there that he needed) then Mr T wouldnt have have posted the pic of servo theory, that is just one example in this thread alone. also both pommie and LG posted a link to a great bit of working code for pic 18 chips.
now what no one gets to see is the people who are stuck and not members here who do the whole google first approach and end up on this thread, BINGO bags and bags of info on servo's this thread like many others is getting a little like an informal wikipedia article except easier to follow.
i understand the frustration but i am also aware of the value a thread like this will have in the future for people you will never see or hear of or know about, but ultimately will get a project up and running without asking anyone a single question simply because of the level of detail that gets posted simply because one OP just does not read properly or dosnt get it and is really wanting it done for him. but that same OP is actually building a thread that will help countless others you will never know about.

i dont have the patience some of you guy's have i would have given up long long ago but i am greatly pleased you continue beyond where most give n as you are doing a service to many others so a big thank you on there behalf

regards
Jason

• Like x 2
14. ### koolguyActive Member

Joined:
Aug 24, 2010
Messages:
2,196
Likes:
9
Why on load the servo motor vibrate??

Joined:
Mar 28, 2011
Messages:
9,148
Likes:
907
Location:
Rochdale UK
ONLINE
Your loading it too much.... They are powerful little devices but they have limits... If they can't get to the position they are asked to... they will start to jerk and vibrate...

16. ### koolguyActive Member

Joined:
Aug 24, 2010
Messages:
2,196
Likes:
9
I had made very litle load for robotic gripper made from little length and wt plastic sheet below it rating operating at 6v 1Am power smps

17. ### Little GhostmanWell-Known MemberMost Helpful Member

Joined:
Jan 7, 2011
Messages:
3,702
Likes:
426
Location:
SCOTLAND
maybe when the gripper is closed your asking the servo to grip past the point its fully closed, does the current draw go up when it closes and jerks?
BTW i dont know much just guessing :d

Joined:
Mar 28, 2011
Messages:
9,148
Likes:
907
Location:
Rochdale UK
ONLINE
Its a good guess.... If the motor is at the extreme it can hunt a little.... I think this is a quality thing... Good quality servo's will still hunt but the movement will be less...

19. ### jpanhaltWell-Known MemberMost Helpful Member

Joined:
Jun 21, 2006
Messages:
5,887
Likes:
500
Location:
Cleveland, OH, USA
ONLINE
"Vibrate"? I have a fair bit of experience with the class of servo being used. When stalled by too much load or by the internal rotation stops, I would describe their behavior as buzzing (OK, very low level vibrate). There is negligible movement of the splined output shaft -- not what I would call hunting.

Ritesh, can you describe in more detail the behavior? Maybe post a video?

One potential source of gross vibration/hunting might be the power supply. These little servos can draw quite a bit of current when stalled. Have you checked the power supply with your oscilloscope during this?

John

Joined:
Mar 28, 2011
Messages:
9,148
Likes:
907
Location:
Rochdale UK
ONLINE
Ha..Ha..Ha.. Seriously.... Sorry Ritesh I don't mean to be harsh.... But Helping you is better than Corrie sometimes....

21. ### koolguyActive Member

Joined:
Aug 24, 2010
Messages:
2,196
Likes:
9
Here is the video............