Skip to content

Commit 54ae8d4

Browse files
committed
Added support for L6234 driver
1 parent 19fe56b commit 54ae8d4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

MotorFOCExample/BLDCmotor.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,21 @@ void BLDCMotor::setPhaseVoltage(double Uq, double angle_el){
169169
Set voltage to the pwm pin
170170
*/
171171
void BLDCMotor::setPwm(int pinPwm, float U){
172-
int U_pwm = U <= U_MAX ? 255.0*U/U_MAX : 255;
172+
// sets the voltage [0,12V(U_MAX)] to pwm [0,255]
173+
// - U_MAX you can set in header file - default 12V
174+
// - support for HMBGC controller
175+
// int U_pwm = 255.0*U/U_MAX;
176+
177+
// sets the voltage [-U_MAX,U_MAX] to pwm [0,255]
178+
// - U_MAX you can set in header file - default 12V
179+
// - support for L6234 driver
180+
int U_pwm = (U + U_MAX)/(2*U_MAX)*255;
181+
182+
// limit the values between 0 and 255;
183+
U_pwm = U_pwm < 0 ? 0 : U_pwm;
184+
U_pwm = U_pwm > 255 ? 255 : U_pwm;
185+
186+
// write hardware pwm
173187
analogWrite(pinPwm, U_pwm);
174188
}
175189

0 commit comments

Comments
 (0)