File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -113,10 +113,11 @@ float HallSensor::getMechanicalAngle() {
113113 function using mixed time and frequency measurement technique
114114*/
115115float HallSensor::getVelocity (){
116- if (pulse_diff == 0 || ((long )(_micros () - pulse_timestamp) > pulse_diff) ) { // last velocity isn't accurate if too old
116+ long last_pulse_diff = pulse_diff;
117+ if (last_pulse_diff == 0 || ((long )(_micros () - pulse_timestamp) > last_pulse_diff) ) { // last velocity isn't accurate if too old
117118 return 0 ;
118119 } else {
119- float vel = direction * (_2PI / (float )cpr) / (pulse_diff / 1000000 .0f );
120+ float vel = direction * (_2PI / (float )cpr) / (last_pulse_diff / 1000000 .0f );
120121 // quick fix https://github.com/simplefoc/Arduino-FOC/issues/192
121122 if (vel < -velocity_max || vel > velocity_max) vel = 0 .0f ; // if velocity is out of range then make it zero
122123 return vel;
You can’t perform that action at this time.
0 commit comments