From d4e1c2cd04ed19552e9f488c3a3e3ccbfef89c21 Mon Sep 17 00:00:00 2001 From: nmscode <105442557+nmscode@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:48:28 -0500 Subject: [PATCH 1/2] Remove sqrt 2 multiplication and correct bemf calculation --- src/BLDCMotor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BLDCMotor.cpp b/src/BLDCMotor.cpp index 8dc2f5cd..16534199 100644 --- a/src/BLDCMotor.cpp +++ b/src/BLDCMotor.cpp @@ -46,7 +46,7 @@ BLDCMotor::BLDCMotor(int pp, float _R, float _KV, float _inductance) // 1/sqrt(2) - rms value KV_rating = NOT_SET; if (_isset(_KV)) - KV_rating = _KV*_SQRT2; + KV_rating = _KV; // save phase inductance phase_inductance = _inductance; @@ -396,7 +396,7 @@ void BLDCMotor::move(float new_target) { if(_isset(new_target)) target = new_target; // calculate the back-emf voltage if KV_rating available U_bemf = vel*(1/KV) - if (_isset(KV_rating)) voltage_bemf = shaft_velocity/KV_rating/_RPM_TO_RADS; + if (_isset(KV_rating)) voltage_bemf = shaft_velocity/(KV_rating*_SQRT3)/_RPM_TO_RADS; // estimate the motor current if phase reistance available and current_sense not available if(!current_sense && _isset(phase_resistance)) current.q = (voltage.q - voltage_bemf)/phase_resistance; From afdbd9dba8f4e31af71afa5e4c07b35a19f9b185 Mon Sep 17 00:00:00 2001 From: nmscode <105442557+nmscode@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:52:13 -0500 Subject: [PATCH 2/2] apply fix to stepper motor logic as well --- src/StepperMotor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StepperMotor.cpp b/src/StepperMotor.cpp index 7831f0bf..6cbe417a 100644 --- a/src/StepperMotor.cpp +++ b/src/StepperMotor.cpp @@ -16,7 +16,7 @@ StepperMotor::StepperMotor(int pp, float _R, float _KV, float _inductance) phase_resistance = _R; // save back emf constant KV = 1/K_bemf // usually used rms - KV_rating = _KV*_SQRT2; + KV_rating = _KV; // save phase inductance phase_inductance = _inductance; @@ -292,7 +292,7 @@ void StepperMotor::move(float new_target) { if(_isset(new_target) ) target = new_target; // calculate the back-emf voltage if KV_rating available U_bemf = vel*(1/KV) - if (_isset(KV_rating)) voltage_bemf = shaft_velocity/KV_rating/_RPM_TO_RADS; + if (_isset(KV_rating)) voltage_bemf = shaft_velocity/(KV_rating*_SQRT3)/_RPM_TO_RADS; // estimate the motor current if phase reistance available and current_sense not available if(!current_sense && _isset(phase_resistance)) current.q = (voltage.q - voltage_bemf)/phase_resistance;