esp-cpp / espp

C++ components for ESP
https://esp-cpp.github.io/espp/
MIT License
31 stars 9 forks source link

BLDC Driver issue #97

Closed guo-max closed 1 year ago

guo-max commented 1 year ago

Answers checklist.

What is the expected behavior?

I am review the bldc_driver code by comparing to your code and found some issue.

bldc_driver.set_pwm(25,25,25); // for example I assume the A,B,C high pin should be 25% high, 75% low. But instead, the high pin now is 75% high, 25% low.

ESP_ERROR_CHECK(mcpwm_generator_set_actions_on_compare_event( gen_high, MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_UP, comp, MCPWM_GEN_ACTION_HIGH), MCPWM_GEN_COMPARE_EVENT_ACTION(MCPWM_TIMER_DIRECTION_DOWN, comp, MCPWM_GEN_ACTION_LOW), MCPWM_GEN_COMPARE_EVENT_ACTION_END())); } This function set gpio high at up direction and low at down direction. For a counter counting from 0 -> 100->0, if set to 25%, the gpio will set high at 24->25 and set low at 26->25, which will give high time from 25->100->25 which is 75% high.

What is the actual behavior?

When set pwm to 25%, the high side at a_high_gpio show be 25% high, 75% low.

Steps to reproduce.

  1. Step
  2. Step
  3. Step ...

Build or installation Logs.

No response

More Information.

I know it works with your FOC controller. If this is a issue, what will change in the FOC controller? All the highs lows are inverted, May only change the motor direction?

finger563 commented 1 year ago

@guo-max It definitely doesn't just change the motor direction - as an example, I've changed the GEN_ACTION for the code in question to invert it (so UP -> LOW and DOWN -> HIGH), and simply inverting the direction of the motor does not seem to fix it, but the motor stalls when driving output. I'll dig into it some more to see what the cause may be. another option is to simply invert the input provided (so that inputting 25 results in 75 output) but that seems like a kludge to me.

guo-max commented 1 year ago

@finger563 I found out that changing the GEN_ACTION does not change the performance of the FOC control if you do a re-calibration.

finger563 commented 1 year ago

You're correct - if you keep everything else the same (including the sensor_direction, then there is no discernable difference :) I'll push the fix 👍