0
\$\begingroup\$

am using two A4988 drivers to control two NEMA 17 stepper motors with 1.8 degree full step resolution on Rpi 2b. I am using them as wheels. The motors are initially given ramp signal using PGPIO wave_chain function and then a steady PWM signal using the SET_PWM function in PGPIO library.

The ramp and pwm are defined each wheel and are called together but the problem is the wheels turn one after the other and not synchronously.

pWhich wheel turns first depends on which wheels function is executed first. Please help me to resolve the issue

\$\endgroup\$
0
\$\begingroup\$

The problem is that a Raspberry runs a kernel (linux) and you do not have direct access to the IO nor have full CPU process.

This results to a undefined, variable random delay to your IO access and is not easy to solve on a Raspberry.

If your raspberry has several CPU Core, you can reserve one core to a specific task, so you won't have kernel task switch over and you can then control your timings. You probably also would need some kernel level drivers to access the IO directly from your separate core, if that is possible. All this is not an easy feat.

The easier method would be to control your PWM with an Arduino, and connect the arduino to the raspberry through SPI/I2C, this approach will be much simpler and you will be able to accurately control and synchronize your PWM and the motor.

Here a link for motor drive system with arduino.

\$\endgroup\$
  • \$\begingroup\$ is ramping possible with an Arduino? will mutliprocessing on Rpi be of any help?Thank you for the reply. \$\endgroup\$ – AK46 Jan 2 at 11:14
  • \$\begingroup\$ Yes, you just need to write the appropriate code. There are probably plenty of example and probably existing full project for controlling motion motors synchronously. \$\endgroup\$ – Damien Jan 2 at 11:17
  • \$\begingroup\$ @AK46 check the link on my edit. \$\endgroup\$ – Damien Jan 2 at 11:18
  • \$\begingroup\$ Another option would be to write the motor control subsystem as kernel driver. \$\endgroup\$ – Jeroen3 Jan 2 at 14:11
  • \$\begingroup\$ It's mentioned on the answer \$\endgroup\$ – Damien Jan 2 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.