Problem with buzzing servo

Dr Jekyll

New Member
Hi Guys

Still pretty new to Picaxe so please be gentle. Also, using a Mac which isn't ideal for a beginner.

I'm working on an animatronic project which uses the 08M2 via a project board to control a Hitec HS 81 servo. My project works via remote control and makes the servo move one way (very slowly) and then move the other way after a 5 second delay.

Everything works fine apart from a loud annoying buzzing coming from the servo on power up. I know it's not the load or linkage as the servo buzzes even when I remove the servo arm. I've got two of these servos, bought at different times and they both buzz so I don't think there's anything wrong with the servos. I've posted my programme below. Any help or guidance greatly appreciated.

Cheers!

Code:
Output C.4
Input C.3
Symbol z = W8

init:
Servo C.4,75 ; initialise servo

Main:

Pause 10

If PinC.3 = 0 Then Goto Main
  
'// Move Servo QUIETLY over a period of 2 seconds or so // 
For z = 75 to 225
   ServoPos C.4, z
   Pause 13
Next z
 
'// Wait 5 seconds 
Pause 5000 

'// Move Servo back the other way 
For z = 225 to 75 Step -1 
   ServoPos C.4, z
   Pause 13
Next z

'// Wait 5 Seconds
Pause 5000 

Goto Main
 

goom

Senior Member
Perhaps 75 is too low a value for that particular servo. It may be driving it to an end stop which is built-in to the output shaft. Try a value of 100 initially and see if it makes a difference.
 

Dr Jekyll

New Member
Perhaps 75 is too low a value for that particular servo. It may be driving it to an end stop which is built-in to the output shaft. Try a value of 100 initially and see if it makes a difference.
Hi there, thanks for the reply. Just given it a try but it makes no difference at all. Still buzzing loudly.
 

rq3

Senior Member
Hi there, thanks for the reply. Just given it a try but it makes no difference at all. Still buzzing loudly.
Just for grins, try this and let us know what happens. I've always had issues with the servo and servopos commands, and found recently that directly driving the pin timing made all of the problems go away. The 20 millisecond "gap" between pulses is (usually) not at all critical.

Code:
[color=Navy]#picaxe [/color][color=Black]08m2[/color]

[color=Blue]Output C.4
Input C.3
Symbol [/color][color=Purple]z [/color][color=DarkCyan]= [/color][color=Purple]W8[/color]

[color=Black]init:[/color]
[color=Blue]high C.4 [/color][color=Green]; initialise servo[/color]
[color=Blue]pauseus [/color][color=Navy]75[/color]
[color=Blue]low C.4
pause [/color][color=Navy]20[/color]

[color=Black]Main:[/color]
[color=Blue]Pause [/color][color=Navy]10[/color]
[color=Blue]If [/color][color=Purple]PinC.3 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]Then Goto [/color][color=Black]Main
  [/color]
[color=Green]'// Move Servo QUIETLY over a period of 2 seconds or so // [/color]
[color=Blue]For [/color][color=Purple]z [/color][color=DarkCyan]= [/color][color=Navy]75 [/color][color=Blue]to [/color][color=Navy]225
   [/color][color=Blue]high C.4
   pauseus [/color][color=Purple]z
   [/color][color=Blue]low C.4
   pause [/color][color=Navy]20[/color]
[color=Blue]Next [/color][color=Purple]z
 [/color]
[color=Green]'// Wait 5 seconds [/color]
[color=Blue]Pause [/color][color=Navy]5000 [/color]

[color=Green]'// Move Servo back the other way [/color]
[color=Blue]For [/color][color=Purple]z [/color][color=DarkCyan]= [/color][color=Navy]225 [/color][color=Blue]to [/color][color=Navy]75 [/color][color=Blue]Step [/color][color=DarkCyan]-[/color][color=Navy]1 
   [/color][color=Blue]high C.4
   pauseus [/color][color=Purple]z
   [/color][color=Blue]low C.4
   pause [/color][color=Navy]20[/color]
[color=Blue]Next [/color][color=Purple]z[/color]

[color=Green]'// Wait 5 Seconds[/color]
[color=Blue]Pause [/color][color=Navy]5000 [/color]

[color=Blue]Goto [/color][color=Black]Main[/color]
 

Dr Jekyll

New Member
Just for grins, try this and let us know what happens. I've always had issues with the servo and servopos commands, and found recently that directly driving the pin timing made all of the problems go away. The 20 millisecond "gap" between pulses is (usually) not at all critical.

Code:
[color=Navy]#picaxe [/color][color=Black]08m2[/color]

[color=Blue]Output C.4
Input C.3
Symbol [/color][color=Purple]z [/color][color=DarkCyan]= [/color][color=Purple]W8[/color]

[color=Black]init:[/color]
[color=Blue]high C.4 [/color][color=Green]; initialise servo[/color]
[color=Blue]pauseus [/color][color=Navy]75[/color]
[color=Blue]low C.4
pause [/color][color=Navy]20[/color]

[color=Black]Main:[/color]
[color=Blue]Pause [/color][color=Navy]10[/color]
[color=Blue]If [/color][color=Purple]PinC.3 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]Then Goto [/color][color=Black]Main
  [/color]
[color=Green]'// Move Servo QUIETLY over a period of 2 seconds or so // [/color]
[color=Blue]For [/color][color=Purple]z [/color][color=DarkCyan]= [/color][color=Navy]75 [/color][color=Blue]to [/color][color=Navy]225
   [/color][color=Blue]high C.4
   pauseus [/color][color=Purple]z
   [/color][color=Blue]low C.4
   pause [/color][color=Navy]20[/color]
[color=Blue]Next [/color][color=Purple]z
 [/color]
[color=Green]'// Wait 5 seconds [/color]
[color=Blue]Pause [/color][color=Navy]5000 [/color]

[color=Green]'// Move Servo back the other way [/color]
[color=Blue]For [/color][color=Purple]z [/color][color=DarkCyan]= [/color][color=Navy]225 [/color][color=Blue]to [/color][color=Navy]75 [/color][color=Blue]Step [/color][color=DarkCyan]-[/color][color=Navy]1 
   [/color][color=Blue]high C.4
   pauseus [/color][color=Purple]z
   [/color][color=Blue]low C.4
   pause [/color][color=Navy]20[/color]
[color=Blue]Next [/color][color=Purple]z[/color]

[color=Green]'// Wait 5 Seconds[/color]
[color=Blue]Pause [/color][color=Navy]5000 [/color]

[color=Blue]Goto [/color][color=Black]Main[/color]
Hi rq3, thanks for the input, really appreciate it.

Just tried it and the buzzing from the servo has completely gone. However, the servo travel appears limited - it's probably only going from 75 to 150 at most which is a bit odd. Any other thoughts?

Cheers.
 

rq3

Senior Member
Hi rq3, thanks for the input, really appreciate it.

Just tried it and the buzzing from the servo has completely gone. However, the servo travel appears limited - it's probably only going from 75 to 150 at most which is a bit odd. Any other thoughts?

Cheers.
Yes indeed. The pauseus commands are units of 10 microseconds each. You can play with those to sniff out what the range of the servo is (carefully, since you don't want to jam the servo up against its internal limits). The "standard" servo pulsewidths (which is being set with the "pauseus" commands) are 150 +/- 75 microseconds, but varies widely between manufacturers of the servos.

The pause 20 commands are just to insert the "standard" 20 millisecond delay between servo pulses. Different servos will tolerate a large range of this delay, but it's usually not at all critical. Worth some playing, though.

A neat feature of this technique is that if you can insert a "setfreq m32" into the top of your code, your picaxe will run 8 times faster, so the pauseus commands become 1.25 microseconds instead of 10 microseconds. You'll have to multiply each pauseus (and pause) by 8 to compensate, but it gives you much finer control of the servo position. Usually beyond the mechanical ability of the servo's internal feedback system to resolve.

In any case, for my applications, I've found that all this completely eliminates the hunting, buzzing, and complaining from the servo, while giving much finer control of position.
 

Dr Jekyll

New Member
Yes indeed. The pauseus commands are units of 10 microseconds each. You can play with those to sniff out what the range of the servo is (carefully, since you don't want to jam the servo up against its internal limits). The "standard" servo pulsewidths (which is being set with the "pauseus" commands) are 150 +/- 75 microseconds, but varies widely between manufacturers of the servos.

The pause 20 commands are just to insert the "standard" 20 millisecond delay between servo pulses. Different servos will tolerate a large range of this delay, but it's usually not at all critical. Worth some playing, though.

A neat feature of this technique is that if you can insert a "setfreq m32" into the top of your code, your picaxe will run 8 times faster, so the pauseus commands become 1.25 microseconds instead of 10 microseconds. You'll have to multiply each pauseus (and pause) by 8 to compensate, but it gives you much finer control of the servo position. Usually beyond the mechanical ability of the servo's internal feedback system to resolve.

In any case, for my applications, I've found that all this completely eliminates the hunting, buzzing, and complaining from the servo, while giving much finer control of position.
Thanks for this. Must admit it's getting a bit beyond my knowledge - how do I go about sniffing out the servo range, presumably I just experiment with the 75 to 225 commands to find more range?

Cheers!
 

rq3

Senior Member
Thanks for this. Must admit it's getting a bit beyond my knowledge - how do I go about sniffing out the servo range, presumably I just experiment with the 75 to 225 commands to find more range?

Cheers!
Exactly. I have seen servos that need as low as 30 and as high as 420. But sneak up on the numbers so you don't jam the servo against its stops.
 

erco

Senior Member
I find 75-225 very conservative for most servos, far from driving them from lock to lock. Some of mine go from ~25 to ~250. Each one is different and yes, you want to sneak up on the mechanical limits with careful experimentation & testing. Many servos buzz even if they are not driven to their limits, FYI. When in doubt, wiggle the servo horn and see if the buzzing stops.
 

Dr Jekyll

New Member
I find 75-225 very conservative for most servos, far from driving them from lock to lock. Some of mine go from ~25 to ~250. Each one is different and yes, you want to sneak up on the mechanical limits with careful experimentation & testing. Many servos buzz even if they are not driven to their limits, FYI. When in doubt, wiggle the servo horn and see if the buzzing stops.
Been playing around with this and currently it's set to 10 - 200 which I find a bit odd. There doesn't appear to be any further room at the top end but I'm still finding room at the low end which leaves me wondering it it will go lower than 10. Minus figures?
 

inglewoodpete

Senior Member
Remember that you are now creating pulses by executing a series of commands in a loop. The pulse timing (mark and/or space) may not be ideal for what the servo is expecting. The overall cycle time (mark + space) for each pulse should be 20mS. The execution time (time taken for each command to be read/unpacked/executed) for each command will affect the length of the pulse. This is most noticeable when using the PauseuS command. It may be better to replace the High/PauseuS/Low sequence with a PulsOut command for a more accurate and linear output.
 
Last edited:

Dr Jekyll

New Member
Remember that you are now creating pulses by executing a series of commands in a loop. The pulse timing (mark and/or space) may not be ideal for what the servo is expecting. The overall cycle time (mark + space) for each pulse should be 20mS. The execution time (time taken for each command to be read/unpacked/executed) for each command will affect the length of the pulse. This is most noticeable when using the PauseuS command. It may be better to replace the High/PauseuS/Low sequence with a PulsOut command for a more accurate and linear output.
Hi Inglewoodpete, thanks for the input. May be a stupid question but do I literally just replace the PauseuS commands with PulsOut commands and try the numbers again starting from 75 - 225?

Any help greatly appreciated.
 

hippy

Technical Support
Staff member
do I literally just replace the PauseuS commands with PulsOut commands and try the numbers again starting from 75 - 225?
That's almost correct. This -

Code:
For z = 75 to 225
   high C.4
   pauseus z
   low C.4
   pause 20
Next z
becomes -

Code:
low C.4
For z = 75 to 225
   pulsout C.4, z
   pause 20
Next z
 

AllyCat

Senior Member
Hi,

The (interpreter) timing "overhead" between the High and Low edges and of a "PAUSEUS 0" (zero) is quite close to 1 ms in total (@ a 4MHz clock). So I would expect the "PAUSEUS Z" in the first format to be roughly equivalent to a "PULSOUT ... (Z + 100)" [pseudocode, not a legitimate PICaxe command] in the second. Which should also overcome the concern about the possible need for a "negative" delay.

Cheers, Alan.
 

Dr Jekyll

New Member
That's almost correct. This -

Code:
For z = 75 to 225
   high C.4
   pauseus z
   low C.4
   pause 20
Next z
becomes -

Code:
low C.4
For z = 75 to 225
   pulsout C.4, z
   pause 20
Next z
Hi Hippy, just given that a try and I came close but no cigar. The servo moves to one end fast, then moves slowly back. The 5 second delay before it's supposed to move back automatically doesn't seem to work at all. Any hep greatly appreciated. Here's my current code:

Code:
Output C.4
Input C.3
Symbol z = W8

init:
high C.4 ; initialise servo
pauseus 75
low C.4
pause 20

Main:
Pause 10
If PinC.3 = 0 Then Goto Main
  
'// Move Servo QUIETLY over a period of 2 seconds or so // 
low C.4
For z = 75 to 225
   pulsout C.4, z
   pause 20
Next z
 
'// Wait 5 seconds 
Pause 500

'// Move Servo the other way // 
low C.4
For z = 225 to 75
   pulsout C.4, z
   pause 20
Next z
 
'// Wait 5 seconds 
Pause 500

Goto Main
 

AllyCat

Senior Member
Hi,

Stepping from 75 to 225 with a 20 ms loop period should actually take just over 3 seconds. Note that STEP +1 is the assumed default.

Then, the PAUSE 500 will delay for only 0.5 second. For 5 seconds use a PAUSE 5000 or a WAIT 5.

However, the major omission is a STEP -1 in the second loop, otherwise the loop condition is immediately met and the loop terminates at a value of 226.

Therefore, changing the second loop to FOR z = 225 TO 75 STEP -1 should fix the problem. ;)

Cheers, Alan.
 
Last edited:

Dr Jekyll

New Member
Hi,

Stepping from 75 to 225 with a 20 ms loop period should actually take just over 3 seconds. Note that STEP +1 is the assumed default.

Then, the PAUSE 500 will delay for only 0.5 second. For 5 seconds use a PAUSE 5000 or a WAIT 5.

However, the major omission is a STEP -1 in the second loop, otherwise the loop condition is immediately met and the loop terminates at a value of 226.

Therefore, changing the second loop to FOR z = 225 TO 75 STEP -1 should fix the problem. ;)

Cheers, Alan.
Thanks Alan, appreciate your input. I'll give that a try now. I wasn't ignoring your earlier reply BTW - I just didn't understand it. I'm a total beginner with Picaxe.

Cheers
Nick
 
Top