# Stepper motor failing - caused by PWM or else?

As suggested over at my original question at raspberrypi.stackexchange.com, I'm also posting my issue here, you'll find it verbatim at the bottom of this question.

Because this is an electrical engineering site, however, I'm happy to formulate a question which is a bit more specific on the electrical engineering part:

Based on the problem that I describe, is it indeed likely that the
issue is caused by a timing issue (i.e. look for a solution in how I address the
stepper motor, i.e. software solution), or do you think there's some
sort of electrical/mechanical issue or stepper motor characteristic I'm not aware of?

EDIT 1: Update based on comments so far: The chopper is a 16cm diameter, 1mm thick aluminum plate with 5 holes in it. Assuming a massive disk for ease of calculating, the disk has a volume of 20 cm^3 and a mass of 54 gram. The moment of inertia should be 0.5MR^2 = 0.50.0540.08^2 = 0.0001728 kg.m2. Converting to oz.inch^2 yields ~9.4 oz.inch^2, which I grant appears to be 2-3 times the the motor torque based on its spec sheet. (I didn't select the hardware for this prototype... :) ) What surprises me is that even 10x slower acceleration (getting to full speed over the course of 32 seconds) ALSO fails regularly, typically around 2000PPS or 10000PPS based on a few quick tries. The fact that it does work sometimes (though rarely) surprises me, too.

From what I understand so far, it might be that the motor is underpowered. Any explanations why it will work fine sometimes, and will even fail at very slow accelerations sometimes as well?

## Original post below

Summary:
Raspberry Pi controls an EasyDriver and stepper motor, but results are inconsistent and the system fails regularly. Can't figure out why.

Long text:
Hi all,

I have a small setup where a stepper motor is supposed to drive a chopper wheel to modulate a signal. Counting steps is not a requirement since the motor comes with an encoder, but a stable speed is a requirement. I'm using the pigpio library (more specifically, the hardware_PWM function) to set the RPM on pin (12) on the Raspberry. Since setting it to full speed instantaneously does not make the stepper motor move at all, I've coded a small ramp-up in speed. The testing script I use has it ramp up to 32000 ppm (20 Hz / 1200 RPM), stay there for a few seconds and then ramp down again.

I've been having a regular issue where at any point during ramp-up, stable running or ramp-down (although usually ramp-up) the motor appears to lose its 'grip' on the rotating shaft and the chopper. From that moment on, the chopper will slow down to 0RPM, but the motor will continue to try and accelerate (ramp-up) or keep speed (stable RPM), causing a whine/buzz different from regular operation. I currently think it must be some sort of timing issue, as in my limited understanding a stepper motor can be compared to a swing in that you'd need to "push" at the right moment, or it'll do nothing or actually slow down. Is it possible that at some random point a timing mismatch between the pulse train and the "ideal push timings" occurs, causing this issue to happen? Surprisingly, others with similar setups and near-identical codes report no issues.

I realize this is probably a mix of Raspberry Pi, hardware and pigpio, but I hope this rings a bell with someone who can help me out, it'd be much appreciated!

Some specs, in case they help:
Motor: NEMA08-17-01D-AMT112S (https://www.cuidevices.com/product/resource/nema08-amt112s.pdf)
Power supply: LPV-150-24 (Repurposed LED-driver, https://www.meanwell-web.com/nl-nl/ac-dc-single-output-led-driver-constant-voltage-c-lpv--150--24)
Driver: EasyDriver ROB-12779 (https://www.sparkfun.com/products/12779)
Testing code: https://pastebin.com/tKS0jvDA (There's a typo in line 7 which is not in the actual code ;) )
Demo notes: In the first cycle, it fails during spin-up, you can hear the frequency increasing but the shaft slows down. In the second attempt, it gets up to speed as it should, and then fails while slowing down, at which point the tune you hear is caused by the mass of the chopper effectively driving an unpowered motor :)

EDIT 29/04: Added code listing to post as requested:

import datetime
import time
import pigpio
import numpy as np
import Rpi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(6, GPIO.OUT)
GPIO.output(6,0)    #Enable motor
pi = pigpio.pi()

freq_startup_diff = 100
freq_startup_wait = 0.01
motor_freq = 32000
startup_range = np.arange(0,motor_freq+1,freq_startup_diff)
print('Motor starting')
for freq in startup_range:
pi.hardware_PWM(int(12),int(freq),int(1e6*0.5))
print("Frequency equals {}".format(freq))
time.sleep(freq_startup_wait)

print('Motor started.')

time.sleep(3)
print('Motor stopping.')
stop_range = np.flip(startup_range)
for freq in stop_range:
pi.hardware_PWM(int(12),int(freq),int(1e6*0.5))
print("Frequency equals {}".format(freq))
time.sleep(freq_startup_wait)

GPIO.output(6,1)    # Disable motor
print('Motor stopped.')
$$$$
`
• I sounds like you are accelerating too fast for your physical load. Please describe your chopper wheel, do you know its moment of inertia? Or, if you tell us the weight and size we can estimate it. Apr 29, 2021 at 20:15
• It's a 16cm diameter, 1mm thick aluminum plate, with 5 holes of roughly 3x3cm. That should be roughly 55 grams (not considering the holes).
– SvB
Apr 29, 2021 at 20:23
• @SvB This is huge inertia. Yet a small unbalance could cause the motor to loose steps, you have combined a tiny motor with a large flywheel. This is the main problem. Apr 29, 2021 at 20:48
• Looking a bit more at the numbers, I'd have to agree with you. However, I've had 2 successful runs just now, accelerating to full speed in 6.4 seconds (changing speed every 0.1 second), after which 2 more failed and a 5th succeeded again. At the same time, I haven't had a single successful run while accelerating over 32 seconds (changing speed every 0.01s). I just can't wrap my head around why this much easier scenario would fail more often. (In addition, I know of similar prototypes where this problem doesn't seem to exist.) Not saying I don't believe you, I'm just surprised/confused :)
– SvB
Apr 29, 2021 at 21:01
• To what is the current limiter of the driver board set? Only 10 ms for "settling" for a new frequency sounds rough given the fact that pigpio wont "match" the stepping patterns which can lead by chance to a "step pulse at the wrong time" situation. Apr 29, 2021 at 21:14

Either your stepper motor doesn't deliver enough torque to follow such ramp or the current is too small for this motor. Remedy: increase acc/dec ramp and check the the output current setting of the driver board.

$$T=J\alpha$$

The required torque to accelerate the mass of inertia at specified angle acceleration. If the required acceleration is too high, then the stepper motor falls out of synchronicity and misses steps.

Another aspect is the torque VS. speed characteristics

Sanyo Denki

At higher speeds the torque drops. The knee point depends on motor voltage constant and power supply voltage.

EDIT:

The motor/load combination acts like a torsional pendulum. The combination of rotor and load inertia with a shaft forms an oscillating system. When you spin the motor with any imbalance of the flywheel you actually excite the system, once the resonance is reached this ripple torque can't be sustained by your motor.

$$\dfrac{d\Omega}{dt}=\alpha$$

If you change the velocity setpoint in steps, that theoretically means an unlimited acceleration. You should update the PWM as fast as possible with tiny amounts:

$$\lim_{\Delta T\rightarrow 0}\dfrac{\Delta\Omega}{\Delta T}=\dfrac{d\Omega}{dt}=\alpha_{const}$$

See the method of creating a continuously changing PWM : how to generate smooth frequency ramp

• Will update post with info, too much for a comment.
– SvB
Apr 29, 2021 at 20:38
• The PWM method to generate a smooth frequency ramp is actually exactly what I've been trying. I hit some barriers however because ramping up to 32000PPS over the course of a few seconds requires a lot of pulses, more than I could fit into a single wave or even a chain of waves. Still trying to figure out whether I hit the limitation of that method, or whether I'm lacking the right skills :)
– SvB
Apr 30, 2021 at 11:42