Skip to content

Commit 0275a32

Browse files
Merge pull request #250 from runger1101001/dev
HallSensor.cpp volatile access bug #244
2 parents 1628692 + 659a268 commit 0275a32

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/sensors/HallSensor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ float HallSensor::getMechanicalAngle() {
113113
function using mixed time and frequency measurement technique
114114
*/
115115
float 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;

0 commit comments

Comments
 (0)