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_gpio_init(MCPWM_UNIT_0,MCPWM0A,GPIO_NUM_25);
mcpwm_gpio_init(MCPWM_UNIT_0,MCPWM0B,GPIO_NUM_26);
mcpwm_config_t mcpwmConfig={
.frequency = 2000,
.cmpr_a = 0,
.cmpr_b = 0,
.duty_mode = MCPWM_DUTY_MODE_0,
.counter_mode = MCPWM_UP_COUNTER
};
mcpwm_init(MCPWM_UNIT_0,MCPWM_TIMER_0,&mcpwmConfig);
}