Hall Sensor problem

Hello Everyone,

I found a strange problem during testing the BLDC motors having in build hall sensor. My setup is a 52 W bldc motor having 4 pp, motor driver DRV8302, and ESP 32 microcontroller.

In a torque control mode when I give a target voltage of 3-4 Volts the output from the hall sensor is ok as shown below :

but if any other target voltage value is given this is the noise introduced or it seems that it skips interrupting i.e not detecting hall sensor value:

I have already introduced the pull-up resistors and by changing the resistor value the result remains the same. Can anyone advise me on how I can solve this issue?

" In the figure, the red is the value from the sensor. get velocity() while blue is the filtered one "


Might be related to this Motor stops due to direction change - voltages NaN · Issue #192 · simplefoc/Arduino-FOC · GitHub

The title is missleading - it’s an issue with hall sensors randomly readings abnormal values

Thanks for your reply, but in my case the motor doesn’t stop while changing direction it’s just that hall sensor is skipping the interrupt.

You are right - you are hitting the following case - I don’t know why.

float HallSensor::getVelocity(){
  if (pulse_diff == 0 || ((long)(_micros() - pulse_timestamp) > pulse_diff) ) { // last velocity isn't accurate if too old
    return 0;
  } else {

If anyone else finds a similar problem. I solved it by multiplying the pulse_diff by 2.
Change this line in the Hall sensor. cpp file

if (pulse_diff == 0 || ((long)(_micros() - pulse_timestamp) > pulse_diff * 2 ) )

now hall sensor data doesn’t drop to zero during motion.


1 Like

Hi @MoidKhan , and @Aleksandar_Markovic,
Have you tried this to see what is going on ?

To put inside HallSensor.h section private:
// velocity calculation variables
        float angle_prev=0.0f; //!< angle in previous velocity calculation step
        long velocity_calc_timestamp=0; //!< last velocity calculation timestamp

To put inside HallSensor.cpp :

// get current angular velocity (rad/s)
float HallSensor::getVelocity(){
    float Ts;
    // calculate sample time
    unsigned long now_us = _micros();
    if(now_us > velocity_calc_timestamp)
      Ts = (now_us - velocity_calc_timestamp)*1e-6;
      Ts = ((0xFFFFFFFF - velocity_calc_timestamp) + now_us)*1e-6;
    // current angle
    float angle_c = getAngle();
    // velocity calculation
    float vel = (angle_c - angle_prev)/Ts;
    // save variables for future pass
    angle_prev = angle_c;
    velocity_calc_timestamp = now_us;
    return vel;

No, I haven’t tried this.