Problem with going from openloop to closed using hall sensors

I have tried the openloop examples for my setup (ESP32S2 mini, driver boards & motor) and that works fine, although there is a ‘hiccup’ every second or so.

I then added the hall sensor code and using the torque mode tried to get the motor to run, but to no avail.

What works.

  1. motor.initFOC() produced an offset angle of 5.24 and direction.
  2. The hall effect example code works … it produces an incrementing number for CW and decrementing number for CCW. Velocity number is there when you accelerate the shaft (by hand).

So it “looks” like my hall effect is working and the direction of the hall’s agrees with the direction of my motor, it just won’t turn, just sits and vibrates when I give it any voltage (in torque mode).

This from the monitoring looks suspicious:

MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp: 0.11
MOT: Zero elec. angle: 5.24
MOT: No current sense.
MOT: Ready.
Motor ready.

I am using a PP= 11, as the PP estimation example code returned 11 (12 sometimes) both 11 and 12 have the same issue.

It could be a hardware issue, as not knowing the motor internal hall’s I have just supplied them with 3v3 and used internal CPU pull-ups to the same voltage. The internal pull-ups may be in insufficient, or the supply is insufficient.

Anything I can try to narrow this down, much appreciated.

The pp check cannot work with hall sensors, you can ignore it.
Are you sure the hall states match with the phases?

I think so. WHat is the best procedure to check.?

If you do a sensor only test and slowly rotate through 360 (2 pi radians), you’d expect a nice smooth angle from 0 to 6.2. if it does this without jumping about then i’d say hall states are fine.

If that ‘passes’ i’d next look for phantom interrupts caused by combination of motor noise and weak/no pull-ups on the halls.

To see if you have phantom interrupts you can occasionally (e.g once a second) print
sensor.total_interrupts, you might expect 11 * 6 interrupts per revolution if there are no phantom interrupts but you might see 1000s if there is noise and weak pullups. A strong pullup for halls can be 750ohm to 2kohm. A weak pullup is 5k to 20k.

Thanks will try that :slight_smile: By the way which sensor test example?
I am made my pull-ups 2k2 now …

I tried the hall sensor test from the examples and I get smooth sensor operation, but 360deg gives only 2.38

Actually not so smooth, the number does not increment for every step felt on the motor shaft, what does that mean?

I expect you’ve already seen the hall sensor test - if you set PP to 11 and then manually turn 360 angle should be smooth and finish at 6.2 (2 pi). If the PP is wrong it might end higher or lower than 6.2 radians.

Often the phantom interrupts occur only when motor is spinning (and those sharp PWM spikes start causing mischief).

Please see comment above

Looks like it is only a 4-pole motor, I get 6.2 radians with that setting … :slight_smile:

Now rotates in closed mode, but sounds like a tractor :rofl: Something is still off …

Sometimes noisy motor can be due to pwm speed being set too low. The human ear can hear up to about 16Khz so it might be worth checking the frequency is 20K+.

Are you using arduino ide or platformio - it is possible that the esp32 specific code isn’t being picked up and you’ve fallen back on the generic code.

I am using platformIO and the freq is 20K, and it’s not just noisy, it’s shaking the motor quite violently

I understand from other threads, that hall deices don’t work well especially with small no of poles. I guess not enough pulses for simpleFOC to work well …
@Owen_Williams Could you comment on this, have you had any experience with 4-pole motors in combo with hall feedback?

In the meantime I have ordered an AS5600 …

I too had problems with closed loop on a 4-pole motor using Hall Sensors. Not enough position data to run the PWM smoothly. Even with very low load.

Much better with a capacitive encoder, but the encode itself was too noisy during operation. I am ow looking at magnetic encoders, like the Orvis.

My plan is to run 2 STM32s, one for SimpleFOC and the magnetic encoder to modulate the PWM. The second STM32 will take input from the motor’s Hall Senors to measure and display current speed. The intent is to set up serial communication from the speed monitoring microcontroller, so that I can easily adjust the speed with manual controls, switch between open and closed loop, etc.

A couple of things to try:

  1. increase motor.motion_downsample to 10, 20, etc
  2. Increasing tf of velocity PID to higher value e.g as 0.05 to 0.2.
    The thinking in both cases is to smooth out the velocity. Somewhat un-intuitively measuring sensor angle too often can result in poorer velocity measurements (downsampling can help here) particularly with Halls which have relatively poor precision. The angle might read like this 0, 0, 0, 0.16, 016, 016, 0.32, 0.32, 0.32, 0.32 but with a bit of downsampling this might look like 0, 0.16, 0.32. The latter will give better velocity estimates.

Great, thanks, will try that (1) … I am running torque closed loop at the moment, wanted to get that running smooth before introducing PID loops with velocity control …

Did not help unfortunately … I think I will wait for my AS5600 before doing any more work …

Hi @Owen_Williams ,
Trying to setup my new AS5600, but struggling to get it to run. I get the following from the motor.init()

MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp: 6.07
MOT: Zero elec. angle: 4.26
MOT: No current sense.
MOT: Ready.
Motor ready.

… and the motor just vibrates … currently I have my pole pairs set to 4

But it’s not consistant. If I start the motor again, I get:

MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: fail - estimated pp: 54.61
MOT: Zero elec. angle: 1.87
MOT: No current sense.
MOT: Ready.
Motor ready.

Is there any method you can share to checkout the operation of the AS5600 before running up the motor. Thanks

I have a build that just outputs sensor.getAngle() and sensor.getVelocity() every second, but when I turn the shaft, I get inconsistant results i.e it may increment up for awhile, but then it suddenly goes down even in the same direction, and visa-versa turning the shaft the other way.

Even not turning the shaft I get this:

1.09    0.00
1.09    0.00
1.09    -0.00
5.33    4.23
5.19    -0.14
5.19    0.00
5.19    0.00
0.82    -4.37
1.09    0.27
1.09    0.00
1.09    0.00
1.09    0.00
1.09    0.00
0.82    -0.27
-0.41   -1.23
-1.09   -0.68
-1.09   0.00
-1.09   0.00
-1.09   0.00
-1.09   0.00

My sensor setup is:

MagneticSensorAS5600 sensor;

Wire.begin(33, 32, (uint32_t)400000);

Hmm, it seems the issue was the DIR pin, it must have been floating as when I shorted it to Vcc (3v3) the sensor readings became stable.

However, I am still having issues with not getting correct starting, but it maybe my powersupply not having enough power to get correct calibration movements.

It is only a 3amp supply. If I change the motor.voltage_sensor_align =3 to get 3amps (I have 1 ohm windings) then the sensor calib does not see movement. If I raise the value, then my power supply sags … I can’t win.

I might have to bite-the-bullet and try on batteries. :melting_face:

EDIT: I did try the PP estimation program, but it gives this:

Pole pairs (PP) estimator

Estimated PP : 4096
PP = Electrical angle / Encoder angle 
1080.00/0.26 = 4095.99

PP number very high, possible error.

 Motor ready.