Skip to content

HallSensor.cpp volatile access bug #244 #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/sensors/HallSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ float HallSensor::getMechanicalAngle() {
function using mixed time and frequency measurement technique
*/
float HallSensor::getVelocity(){
if (pulse_diff == 0 || ((long)(_micros() - pulse_timestamp) > pulse_diff) ) { // last velocity isn't accurate if too old
long last_pulse_diff = pulse_diff;
if (last_pulse_diff == 0 || ((long)(_micros() - pulse_timestamp) > last_pulse_diff) ) { // last velocity isn't accurate if too old
return 0;
} else {
float vel = direction * (_2PI / (float)cpr) / (pulse_diff / 1000000.0f);
float vel = direction * (_2PI / (float)cpr) / (last_pulse_diff / 1000000.0f);
// quick fix https://github.com/simplefoc/Arduino-FOC/issues/192
if(vel < -velocity_max || vel > velocity_max) vel = 0.0f; //if velocity is out of range then make it zero
return vel;
Expand Down