File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,21 @@ void BLDCMotor::setPhaseVoltage(double Uq, double angle_el){
169
169
Set voltage to the pwm pin
170
170
*/
171
171
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
173
187
analogWrite (pinPwm, U_pwm);
174
188
}
175
189
You can’t perform that action at this time.
0 commit comments