i have 2 NEMA 34 stepper motors and i want to control them different frequency/PWM at the same time. these are my example codes. In this code just one motor works. i do not know why 2 motors are not running. how can i fix the problem?

Code: Select all

```
import pigpio
pulse_1 = 21
dir_1 = 20
pulse_2 = 5
dir_2 = 17
pi = pigpio.pi()
pi.set_mode(pulse_1, pigpio.OUTPUT)
pi.set_mode(dir_1, pigpio.OUTPUT)
pi.set_mode(pulse_2, pigpio.OUTPUT)
pi.set_mode(dir_2, pigpio.OUTPUT)
class MOTOR_1:
def __init__(self, ramp):
self.generate_ramp(ramp)
def generate_ramp(self, ramp):
pi.wave_clear() #delete all waveforms
length = len(ramp)
wid = [-1] * length
for i in range(length):
frequency = ramp[i][0]
half_periods = int(500000 / frequency)
wf = []
wf.append(pigpio.pulse(1<< pulse_1, 0, half_periods))
wf.append(pigpio.pulse(0, 1<<pulse_1, half_periods))
pi.wave_add_generic(wf)
wid[i] = pi.wave_create()
chain = []
for i in range(length):
steps = ramp[i][1]
x = steps & 255
y = steps >> 8
chain += [255, 0, wid[i], 255, 1, x, y]
pi.wave_chain(chain)
class MOTOR_2:
def __init__(self,ramp):
self.generate_ramp(ramp)
def generate_ramp(self, ramp):
#pi.wave_clear() #delete all wave forms
length = len(ramp)
wid = [-1] * length
for i in range(length):
frequency = ramp[i][0]
half_periods = int(500000 / frequency)
wf = []
wf.append(pigpio.pulse(0, 1<<pulse_2, half_periods / 2))
wf.append(pigpio.pulse(1<< pulse_2, 0, half_periods / 2))
pi.wave_add_generic(wf)
wid[i] = pi.wave_create()
chain = []
for i in range(length):
steps = ramp[i][1]
x = steps & 255
y = steps >> 8
chain += [255, 0, wid[i], 255, 1, x, y]
pi.wave_chain(chain)
motor_1 = MOTOR_1([[1000, 2400],
[2500, 2400],
[5000, 2400],
[7500, 2400],
[9500, 2400],
[10000, 2400],
[9500, 2400],
[8000, 2400],
[6500, 2400],
[5000, 2400],
[4000, 2400],
[2000, 2400],
[1000, 2400]])
motor_2 = MOTOR_2([[1500, 9600],
[1700, 9600],
[2300, 9600],
[2500, 9600],
[2700, 9600],
[3000, 9600]])
```