Skip to main content
Associate II
July 20, 2023
Solved

Step motor control and max torque

  • July 20, 2023
  • 8 replies
  • 6525 views

Hello. I am doing stepper motor step control. I am using the "HAL_TIM_PWM_PulseFinishedCallback" function for this operation. Is there a more functional usage method than this? I can't get the max torque of the motor. Can you help me? Motor Driver "TB6600" / Step Motor "Nema17"

Best answer by Johi

@AI_I 

I was experimenting with LL as an alternative for HAL and used your case a test case. The main loop calculates the frequency of the motor (limited as per the spec of the motor) and TIM2 pulses its callback. The callback pulses the 4 coils of the motor using a ULN2003 dalington based driver. If I find the time I will try to make a DMA version as well.

 

8 replies

Johi
Senior II
July 20, 2023

Possibly you have a TB6600 that has a TB67S109AFTG inside see link below for details.

https://www.makerguides.com/tb6600-stepper-motor-driver-arduino-tutorial/

AI_IAuthor
Associate II
July 20, 2023

I do not have a problem with stepper motor control and connections. I can't get the max torque of the motor. I think the reason for this is ARR and Prescaler values. What are these values ​​for Nema17, I couldn't find it in the documents, so I guess I miscalculated. Apart from this, I want to learn if a more useful stepper motor drive can be made than the "HAL_TIM_PWM_PulseFinishedCallback" function.

Johi
Senior II
July 21, 2023

Do you have the possibility to measure the signal you are sending to the TB6600 with a scope or similar?

You can even try to make a very slow pulse rate and send it to the TB (1 Hz) or less, then the motor should run very slowly, but the torque should be nominal (as this is a property of stepper motors, enough current == enough torque).

As for your question: I would start with a fixed frequency, so you do not need "HAL_TIM_PWM_PulseFinishedCallback" for this basic start.

As for the prescaler and the like, all depends on the clock configuration, how fast you want to run with the motor and what the load is, so there it is difficult, but if you start with 1 Hz at the output to the TB, for sure this should so something, and then you can gradually increase.

Note: There are RMxxxx reference manuals available for your MCU, these essential manuals are available at the ST site and explain in detail how the timers work.

As for the settings: try PWM Generation CHx where Counter period is n (example 1000) and then use 500 for the pulse so you get a symetrical PWM signal. You can even measure this with a multimeter or an LED.

AI_IAuthor
Associate II
July 21, 2023

Thanks for your answer. I was able to reach the level of using stepper motors by trying the calculation and making changes to it. The purpose of using the "HAL_TIM_PWM_PulseFinishedCallback" function is to control the step count of the motor. I control the number of motor steps with the counter parameter I created with this function. I'm still looking for a more efficient solution to this. The code I created is in the link below. It works fine, but is there a simpler way? I am open to new ideas.

Code = https://github.com/ilbeylia/Stm32_Step_Motor_lib 

Johi
Senior II
July 21, 2023

All depends on your definition of simple, and is related to the background you have. For sure 1 disadvantage of your strategy is 1 interrupt per pulse as the callback has to be called for each pulse. As the TB goes up to 40KHz this approach could get you in to trouble related to CPU load. But anyway, what kind of application are you building? Depending on this spec, different options are possible. If you want to go full force, there is DMA with al its advantages (and complexity) as explained in: STM application note AN2820 "Driving bipolar stepper motors
using a medium-density STM32F103xx microcontroller"

Johi
JohiBest answer
Senior II
July 21, 2023

@AI_I 

I was experimenting with LL as an alternative for HAL and used your case a test case. The main loop calculates the frequency of the motor (limited as per the spec of the motor) and TIM2 pulses its callback. The callback pulses the 4 coils of the motor using a ULN2003 dalington based driver. If I find the time I will try to make a DMA version as well.

 

AI_IAuthor
Associate II
July 21, 2023

@Johi  Thanks for your help.

Visitor II
January 28, 2025

hi brother, can you please share the code you used for the tb6600 ?

AI_IAuthor
Associate II
January 28, 2025

https://github.com/ilbeylia/StepperMotorLib.git 

Hey there! My GitHub profile has my library and a sample project. Here’s the link. If you run into any issues or have questions, don’t hesitate to reach out to me on GitHub—I’ll be happy to help!

Visitor II
January 28, 2025

thank you so much, i have a school project on controlling a stepper motor using a tb6600 with stm32, my stepper motor have 8 wires, do you have any idea how i can wire it ?

AI_IAuthor
Associate II
January 28, 2025

Example Connection:

Let’s consider connecting an 8-wire stepper motor to a TB6600 driver using the bipolar parallel wiring method. First, we need to identify the coils of the motor and then combine the appropriate wires for the parallel connection. Here’s how to do it step by step.

Step 1: Identify the Coils Using a Multimeter

First, we need to determine which wires belong to which coil. You can do this using a multimeter:
• Set your multimeter to resistance (ohms) mode.
• Measure the resistance between any two wires:
• If you get a low resistance reading, these two wires belong to the same coil.
• If you get infinite resistance, these two wires belong to different coils.

Example:
• Coil 1: Wire 1-2 and Wire 3-4
• Coil 2: Wire 5-6 and Wire 7-8

Each coil has two windings:
• Coil 1: (Winding 1: Wire 1-2, Winding 2: Wire 3-4)
• Coil 2: (Winding 1: Wire 5-6, Winding 2: Wire 7-8)

Step 2: Prepare the Parallel Connection

In a parallel connection, the two windings of the same coil are combined and connected to the driver.

Wiring Diagram:
• Coil 1:
 Combine Wire 1 and Wire 3, then connect them to A+.
•Combine Wire 2 and Wire 4, then connect them to A-.
• Coil 2:
Combine Wire 5 and Wire 7, then connect them to B+.
Combine Wire 6 and Wire 8, then connect them to B-.

Visitor II
January 29, 2025

thanks alot brother i appreciate it, in the end i went to university and changed that stepper motor because it got problems, now im using a 4 wires one.

AI_IAuthor
Associate II
April 22, 2025

Hello Community, I’ve updated my STM32 library for step motor control, making it more organized and user-friendly. I’ve also added a detailed README file to guide its usage. For torque optimization, you need to adjust settings based on the frequency values specified in the motor’s datasheet. By correctly calculating the ARR (Auto-Reload Register) and Prescaler values for the PWM signal in STM32, you can optimize the motor’s maximum torque and speed performance. My library makes it easy to configure these settings. The README includes usage examples and configuration details for your reference. Feel free to reach out if you have any questions—I’d be happy to help! Check out the library here: GitHub Repository