Example: Multi- Stepper Motor Control using minimal resources for PSoC3, PSoC4, PSoC5 and PSoC6

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

This post is for a multi- stepper motor control (up to 8 in this example) using minimum PSoC resources.   This allows for reasonable control of the PWM pulses for stepper motors across virtually all PSoC MCUs with fewer HW resources.

The architecture to accomplish this is that there is one PWM in continuous run mode with the pulse ratio required for the stepper motors.   The application turns on individual motors by defining which motor and how many pulses.  The PWM generates an ISR to count down the pulses loaded until '0'.   When the count is '0', the motor is turned off.

The example

  • Turns on certain motors for specific counts. 
  • It waits for all motors to stop.
  • Waits for 10ms
  • Turns on other motors for specific counts.
  • It waits for all motors to stop.
  • Waits for 10ms
  • Repeat this pattern ...

I've uploaded 4 projects for the PSoC3, PSoC4, PSoC5 and PSoC6 MCUs.   These projects were targeted for popular Infineon kits and eval boards but can be easily modified to run on most HW.

The stepper motor pulse ratio is adjustable and the ON count is assigned by an API call.

This example is designed to quickly (all 4 versions took 6 hours to create and debug) create stepper motor pulses to multiple stepper motors independently.  However, I do not have certain safety functions such as emergency stops that may be required for some systems.   This project is a starting point for your applications such as a CNC machine or a 3D printer.   It's now up to YOU!!!

I support 8 stepper motor outputs because that is what would fit in one PSoC control register.   You can extend to to more ports with more sophisticated coding.

Update: 2/7/2022

These projects require PSoCs with some UDB resources.  PSoCs without UDBs but have SmartIOs should be able to support a similar architecture.

Anyone interested in converting this project to SmartIOs?

Update: 2/10/2022

No code changes.   Just updated the name of the projects to reflect the 8 channel Stepper Motor.

Update: 2/11/2022

Added an additional project 8_StepperMotor_SW_PSoC63.cyprj.Archive01 which compiles and runs on the CY8CPROTO-063-BLE eval board.

 

Len
"Engineering is an Art. The Art of Compromise."
6 Replies
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

Thanks Len. Take a look at grblHAL.
It supports the G81 drilling cycle and has a driver for PSoC5 (with minor tweaks).
I used PSoC5+Candle in my CNC machine.
What is grblHAL?
PSoC5 driver

Evgeny

Evgeny,

 

Thanks.  I don't have a need for stepper motor drivers.   I was aiding another forum user in his need.   His project intrigued me and so I developed the base project for multi-stepper motor control and shared it with the community for future use and study.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
AC
Level 1
Level 1
5 replies posted 5 sign-ins 5 likes given

Hi Len,

Thanks for the tremendous help! I was able to use your project on my PSoC 4 device to get the stepper motors running at different counts and at different times.

One issue I ran into was assigning the correct Ports/Pin numbers to each stepper motor, since my stepper motors are wired directly inside a custom PCB board into non-adjacent pins. I was able to get 3 out of 4 stepper motors working with a simple change: deselecting 'Contiguous' in the Mapping tab of the PWM_out Pins component.

The ports that my stepper motors use are P1[6], P1[3], P2[4], and P4[1], respectively (on the 042-BLE PSoC chip). The first 3 ports worked fine, but the 4th one gave me these errors:

Pin Error: (Function Net_2197.q cannot be reached from this pin).

'PWM_out(3)' cannot be placed at P4[1]. P4 cannot be used for routed connections.

Is there a workaround to use this port (Port = P4[1], Pin = 6) or do I have to change the stepper motor hardware to another available port?

 

Thanks,

AC

0 Likes

AC,

My project to allow for 8 stepper motor controls REQUIRED all the pins be on the same Control Rgister.  This is to  simplify the coding.  They can generally be assigned to any pins that allow UDB routing.

I can get P1[3], P1[6] and P2[4] to route just like you did.

However, 4[1] for some reason is unroutable.   I can't' see why.   Infineon will have to weigh in on this.

If Infineon can't find a way, you'll have to use a different pin number.

I found this in the PSoC 4200 BLE Architecture Technical Reference Manual (TRM)

Len_CONSULTRON_0-1644755822206.png

This explains why the Application Build phase complains.

I recommend changing to pin assignment for this stepper motor.

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

AC,

Although I recommend changing the port/pin assignment from P4.1 to something with a lower number port, I've changed the PSoC4200 version of my previous upload to use your port/pin assignments including P4.1

To do this I added another PWM component just for port 4.1  (I changed the code to account for this change too.)

Attached here is the upload.

Len
"Engineering is an Art. The Art of Compromise."

Len,

The program works perfectly! Thank you for all your help!

 

With gratitude,

AC

0 Likes