Minimum number of PWM pulses to set servo angle - Page 1
Forum section: electronics / beginners

author: NightMoth
author_rank: Contributor
timestamp: June 03, 2025, 12:59:59 pm
content: Hello allIt seems I lack the terminology to formulate correct question to find an answer on internet.Does anybody know how many pwm pulses must receive a servo motor in order to "understand" which angle it need set to?In other words: what is minimum number of peaks in pwm pulse train to control servo motor?Is it possible somehow determinate from servo datasheet for this hobbyst servohttps://akizukidenshi.com/goodsaffix/SG90_a.pdf?Or is there any rule of thumb like "minimum 10 pulses" or "minimum 3 pulses" ?I want to know it in order to determinate how often one can send commands to servo motor to change its orientation angle.

author: NightMoth
author_rank: Contributor
timestamp: June 03, 2025, 01:22:25 pm
content: But there is link to motor datasheet in my original postJust in case posting it againhttps://akizukidenshi.com/goodsaffix/SG90_a.pdf(Duty cycle 0.5...2.4ms, PWM frequency 50Hz)

author: brucehoult
author_rank: Super Contributor
timestamp: June 03, 2025, 05:03:22 pm
content: According to generic servo specs from analogue days you are supposed to send the pulses continuously at nominally 50 Hz, so the kind of cheating answer would be the time the servo takes to go from the current position to the new one divided by 0.02s, but in practice modern servos with digital control electronics inside them often only need one pulse.

author: Nominal Animal
author_rank: Super Contributor
timestamp: June 03, 2025, 05:30:52 pm
content: Quote from: NightMoth on June 03, 2025, 12:59:59 pmYou can vary the duty cycle of each individual pulse. SG90 are very standard micro servo used by hobbyists including Arduino folks –– I've got a couple of dozen of those, otherwise identical-looking but with a "DIY More" label instead of "Tower Pro".The servo has a potentiometer in a voltage divider configuration on the output axle, so that the orientation of the axle corresponds to a wiper voltage that is a specific fraction of the supply voltage. The tiny PCB takes the incoming pulses, chops up a corresponding pulse from the supply voltage, filters it into a comparison voltage (so that short pulse corresponds to smaller fraction and long pulse a larger fraction of the supply voltage), and depending on the difference, drives the DC motor, thus changing the orientation.You cannot trust these ultra-cheap micro servos (like SG90) to "remember" their target at all; I don't think they have proper digital control electronics, just an optimized analog integrator-comparator cost-optimized IC. That's why I suggest keeping close to the "standard" 50 Hz PWM as well. You do need to provide them a steady sequence of pulses, with the duration of each pulse corresponding to the desired orientation or a future position of the servo. Thus, do not think of controlling them with individual pulses at all, but with PWM, Pulse-Width Modulated signal.The linked-to SG90 is limited to 0.12 seconds per 60 degree turn, with a range of about 180 degrees. That means that it takes 180/60×0.12 seconds = 0.36 seconds to go from end to end. At 50 Hz pulse rate, each pulse takes 0.02 seconds, so there are 18 pulses in that sweep. Thus, the maximum rate of change between pulses for this servo at 50 Hz PWM is 100%/18 pulses = 5.56% per pulse. Anything faster, and the servo won't be able to keep up.If you have more servos than PWM outputs, you can use a PWM IC like for exampleNXP PCA9685, which allows you to set the exact PWM frequency (about 50 Hz will do), and the individual pulse duty cycle at 12 bit precision, separately for each channel for up to 16 channels (16 servos). The pulse interval is then 1000ms/50 = 20ms, but the effective duty cycle only 0.5ms to 2.5ms, i.e. only 10% of the full dynamic range, so the approximate resolution is on the order of half a degree; it is unlikely the SG90 servos arethatprecise, so I consider that sufficient and good enough. Then, you can send the position updates (via I²C) as often as you want –– at the standard 400 kHz I²C bit rate, about 40 bit times per channel, you can update each channel a couple of hundred times a second, several times in each interval between pulses. Or you can use a timer interrupt to grab your array of 16 servo positions 50 to 100 times a second, then send them as one bulk update; then your code just sets the values in the array as often as it finds useful.

author: jpanhalt
author_rank: Super Contributor
timestamp: June 03, 2025, 05:31:01 pm
content: Presumably the TS is referring to hobby servos.The ones I dealt with, both analog and older digital, did not have a capture and hold feature for the signal. With analog servos, that fact could be used to control speed. Slower frame gave slower movement (within limits). I have less experience with modern digital servos; however, without a continuing signal, some simply go limp or to neutral. Engines will have a failsafe.I crossed checked with Google and put this question to Google:Do hobby servos have capture and hold in case the signal stops?Here's Google's response:QuoteServo City link:https://www.servocity.com/servo-faqsI also asked whether Hitec servos hold position when signal is lost. Here's the Google response:Quote

author: pcprogrammer
author_rank: Super Contributor
timestamp: June 03, 2025, 05:46:50 pm
content: As soon as these hobby servos loose the PWM input they will either stop at the current position or fall back to center position. To avoid this from happening it is also needed to cut the power, but this only works when there is no force on the arm.I have used this feature in my, now demolished, heating system to control the air valves of a big wood burner. The servo arm was balanced with a counter weight to keep it at its current position when the power was cut. It worked with both analog and digital based servos I tried.But when there is a force working on the arm, the pulses have to keep coming to make sure it stays at the intended position. The 20ms (50Hz) repeat time is a relic from the old FM transmitter days. New digital servos can receive them at a higher pace to decrease reaction time.

author: CaptDon
author_rank: Super Contributor
timestamp: June 03, 2025, 06:01:31 pm
content: It looks like the servo can move 60 degrees in .12 seconds so it seems like the answer would depend on how far you want to move the arm. As another poster stated you probably need a continuous stream of pulses to keep the servo alive. I am not sure how it reacts when receiving. Can it hold its last commanded position with no pulses? Given some of the stated data it can move 60 degrees in .12 seconds and during that .12 second time period only 6 'new position' pulses could be sent. It does look like it wants a continuous pulse stream however. It appears to be capable of moving 1 degree in .002 seconds but the 'update' only occurs at the 20 millisecond pulse repetition rate. This kind of looks like a digital replacement of sorts for the old 'spring reset' linear servos used on model airplanes. The minimum pulse width would be full CCW and maximum pulse width would be full CW. With no pulses the servo returned to full CCW although yours probably holds the last commanded position. The specs don't exactly specify if a new position could be assigned with just one pulse.

author: Benta
author_rank: Super Contributor
timestamp: June 03, 2025, 06:27:15 pm
content: Those small servos use circuits equivalent to NE544 (Signetics/Philips) and M51660 (Mitsubishi), They are laid out for continuous pulse input, and it's hard to say how they behave with no signal. They certainly have no memory, so position holding force will disappear.

author: NightMoth
author_rank: Contributor
timestamp: June 11, 2025, 08:37:44 am
content: Hello, thank you all for answers!Excuse me for late reply, I got busy last week.For the history: I made real experiment with my servo.Here is actual servo behavior (tested with scope):- Actual T_pwm = 20.9mS (50Hz/20mS recommended in datasheet)- Duty cycle = 0.326mS - 0 degrees (0.5ms in datasheet)- Duty cycle = 2.365mS - 180 degrees (2.4ms in datasheet)Then I was forcing the servo motor continuously make 5...10 degrees steps with different idle times between changing its angle.And I found that servo motor moves smoothly when idle time > 42mS.It corresponds to minimum two PWM pulses received by servo between changes.So answer for my particular servo motor is:minimal quantity of PWM pulses is TWO!

author: spostma
author_rank: Regular Contributor
timestamp: June 11, 2025, 04:23:03 pm
content: The easiest solution could be the use of a 74HC4017 decade counter chip that was present in every classic RC receiver,which allows you to connect 9 servos to Q1.. Q9.The only thing you need to do is generate 9 pulses with a 1-2ms varying interval, followed by a reset pulse every 20 msecsto generate 9 PWM outputs with 1-2ms pulse width and 20ms period. Most microcontrollers can generate these pulses easily.

author: brucehoult
author_rank: Super Contributor
timestamp: June 11, 2025, 10:55:31 pm
content: Quote from: spostma on June 11, 2025, 04:23:03 pmI'm not sure what's "easy" about that, other than needing only 2 MCU pins.As I see, you get "one-hot" outputs, with each clock pulse turning off the current output and turning on the next one. So for N servo outputs you need software intervention to sent N+1 pulses at precise intervals, different every time, and the servo pulses are staggered.It would be just as easy to use a 595 shift register with an SPI output sending an N bit packet at each of the transition times -- more transitions on the wire but no harder on the software side.But, even the lowly 10c CH32V003 (well, ok, the 15c 16 pin package) can do 10 PWM channels, 6 on one timer and 4 on the other. It will tie up N GPIO pins on the MCU, but software only has to intervene when the position of a servo changes.The 74HC4017 seems to be around 50c in qty 100, several times higher than the CH32V003 MCU. If you wanted a chip with 74HC4017 functionality it would be cheaper to program an extra CH32V003 to emulate one! Certainly if all you need is µs timing accuracy not ns.