Hi i am trying to use MCPWM to move a nema 17 motor with esp32.

I am using a TB6560 stepper motor driver and it setup is limmiting current to 1.5A and i am using 1/8 Microsteps. Motors is classic one 1.8degrees per step and 200steps per revolution.

I am using the mcpwm_unit_0 and timer_0 and at mcpwm0A i am sending a 50% duty pulse and also i use the mcpwm0B to control direction with duty of 0 and 100. For a non esp32 discussion this means that i am using 2 pwms one for the direction where i am setting it always from 0% to 100% duty and a second for the steps which is always 50%

I have understood that in order to move the motor in several different speeds i have to use the set the frequency of the pwm, that it is initially set in the config_t

I have used several different frequencies in some of them >10000Hz the motor was not moving at all and in <1000 it was also not a good movement. From 2000 - 10000 the motor was moving good but not smoothly in every case. Also i have notices that motor's temperature increased, not too much but higher than it should normally work i think.

[*] how do i know which frequencies should be used for smoothed movement. The motor should be able to move slowly and fast ( i was thinking to control the frequency with a pid controller)? I assume that temperature issue is really an out of range frequency problem but what is the range , where it is defined and how to calculate it

Config settings:

void Nema::init(){


    mcpwm_config_t mcpwmConfig={
        .frequency = 2000,
        .cmpr_a = 0,
        .cmpr_b = 0,
        .duty_mode = MCPWM_DUTY_MODE_0,
        .counter_mode = MCPWM_UP_COUNTER


  • \$\begingroup\$ (1) I usually start with 1kHz and increase to 10kHz. 5kHz moves the motor smoothly. (2) You don't need any PID controller, which is for another purpose. (3) You might consider higher microstepping resolution for smooth movement. (4) Let me know you config setting. (5) Are you using this kind of cheap AliEx module with a huge heat sink? TB6560 3A Stepper Motor Driver Module - US$6. fr.aliexpress.com/item/… \$\endgroup\$
    – tlfong01
    Commented Feb 7, 2022 at 8:31
  • 1
    \$\begingroup\$ i have edited the post to add the code for the config. I will go with 1/16 then microsteps. Yes the module is this with the juge heat sink. Yes the component of esp32 is this what you send. About the temp is about the motor temp. It is not 80C i suppose it is around 35 cause it is touchable. What should i check in the documents that you have send to me. \$\endgroup\$
    – kyrpav
    Commented Feb 7, 2022 at 9:38
  • 1
    \$\begingroup\$ i want to attach a cable on the motor and measure the tension on it. So i was going to use a pid controller in order to achieve tension. I was going to control frequency somehow. \$\endgroup\$
    – kyrpav
    Commented Feb 7, 2022 at 9:40
  • 1
    \$\begingroup\$ start learning , newbie or not i am sorry but i can not go in that type of discussion it is really bad thing for anyone to think that he is helping starting with this type of phrases. It is better not to try to help at all cause this answer give nothing. For A4988 you still need one pin for pulse and one for direction so i do not see any change in the problem , i see the same questions apply with this driver which means that your attack was completely useless. \$\endgroup\$
    – kyrpav
    Commented Feb 7, 2022 at 17:38
  • 1
    \$\begingroup\$ If you know how to help please do so, if not you do not need to go in a newbie discussion to escape cause noone forced you to help. I am appreciating your comments at the beginning about how you control your system. Usually before i do a scale up on any machine i am trying the proof of concept. When i was talking about a cable i and tension i was really talking about this. A cable/rope will be attach and the motor will stretch the cable. Then with a tension module i will measure the tension of the rope. \$\endgroup\$
    – kyrpav
    Commented Feb 7, 2022 at 17:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.