simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
2.03k stars 521 forks source link

Add ESP32 Phasestate with sw-deadtime #305

Closed mcells closed 1 year ago

mcells commented 1 year ago

Adds Phasestate for the MCPWM driver. I had to use software deadtime for this, so I added a define to (optionally) switch back to hardware-dt, should the need arise for some reason. The 6pwm functionality works nicely and the waveforms of the 3pwm output still seem to do what they should.

There is still one thing I am not quite sure about. IIrc, at least one of the existing sw-dt implementations turns the high/low phases completely on/off, when the requested dutycycle is 100 or 0 percent (instead of 100 - deadtime or 0 + deadtime). However I can´t find that anymore, so I left this out here too.

runger1101001 commented 1 year ago

Thanks a lot for this. I am wondering if we should still include it in this release or the next one?

Regarding the turning on/off completely, you are right we are not consistent here. For example, I think the ATMega MCU drivers internally use analogWrite to set the PWM (which does this check for 0/100%) when not in 6-PWM mode, and they account for the 0/100% case explicitly in 6-PWM too.

runger1101001 commented 1 year ago

Ok, my feeling is that we could merge it in this release, but we set SIMPLEFOC_ESP32_HW_DEADTIME to true by default. If people want to use the new feature, they can change the build flag...

That keeps the same behaviour as so far in this release, because my concern is that it would otherwise change the behaviour for all users, I'd like to test it a bit more first before we do that.

What do you think?

mcells commented 1 year ago

That sounds like a good compromise. Although I am pretty certain that there are no bugs, it indeed seems a bit rushed to immediately release everything to main.

Regarding changed behaviour, the only difference is the added functionality and the 'issue' from above. And I just remembered that the hw-dt too turns off/on the phases completely, because it does deadtime insertion by delaying the switching.

runger1101001 commented 1 year ago

Thank you very much for this!! merging it now :-)