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?
Thanks so much in advance!
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 of error: https://www.youtube.com/watch?v=KtLGCtxPLPw
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.')
```