Illegal hall state error

Hi ODrive community -

First time attempting to use an ODrive (V3.6, 56V), and unfortunately it hasn’t been easy. I’m trying to drive a geared hub motor - Bafang’s G311 (more stats) with 30:1 gearing and hall effect sensors. I’ve changed some of the parameters to suit this motor, and have had no problem running the full calibration sequence (the motor spins forward 1/30th of a turn and then stops). However, when the motor stops and I call dump_errors(odrv0), I receive just one error: ERROR_ENCODER_ILLEGAL_HALL_STATE.

Thereafter, the motor is unresponsive in CONTROL_MODE_CLOSED_LOOP_CONTROL. I am able to calibrate the motor as many times as I want, but never to put it into any other control mode, or do anything else.

I’ve seen the other posts on this forum relating to ERROR_ENCODER_ILLEGAL_HALL_STATE and checked for some common issues that may cause this problem. I first checked with a multimeter to see if any of the hall effect outputs are stuck high or low, but all (A,B,Z) reliably shift from low (~0.01 V) to high (~3.05 V) as the motor spins, and although I can’t really turn it one revolution, because of the gearing, I haven’t been able to find any point at all where either all 3 are high or all are low. Since this seems to be the only (or primary?) condition that results in this error, I’m really struggling to solve this so that the motor can be run. If anyone else has experienced this issue, or has any advice on how to get the board and motor working, it would be greatly appreciated!

Please can you check the value of encoder.hall_state - it should change value as you manually turn the motor. If it is stuck at zero then something is wrong.
You could even try the liveplotter. Edit tools/odrivetool and change this section

        # If you want to plot different values, change them here.
        # You can plot any number of values concurrently.
        cancellation_token = start_liveplotter(lambda: [
            my_odrive.axis0.encoder.hall_state
        ])

If you find that it is cycling between all six states correctly but only sometimes it jumps to an illegal state (0 or 7) then probably you have electromagnetic noise causing interference on the encoder wires.
You can try using a ferrite ring from the shop to reduce the noise emitted from the motor wires, and/or adding a 22nF capacitor to GND on each of the A,B,Z pins.

Towen, thanks for the help! However, it seems to change value fine. Because it’s a geared motor, it’s really hard to spin at a speed slow enough to accurately capture the order in which it passes through the steps, but I spun it manually for several minutes with the liveplotter going and saw only what’s shown in the screenshot above ^^, losts of 1-6 states but never a 0 or 7. (consistent with what I measured at the hall effect pins) Any ideas what could be causing this error when it never actually seems to go to an illegal hall state?

Hi,
Do you have the same behaviour on M0 and M1 ?

Kind regards,
Tim

Is it possible for you to run the same plot while you try to run the motor? e.g. send a command over UART or CAN to go to the calibration sequence?
Or set axis.config.startup_full_calibration_sequence = True and start the liveplotter immediately when you turn on the ODrive.

This suggests to me that you -are- having problems in calibration. The motor should move forwards and then backwards. If it moves forwards and stops, then the calibration has failed. Usually because of a CPR_POLEPAIRS_MISMATCH but in your case I strongly suspect that electromagnetic noise from the motor wires is interfering with the sensor wires, causing ILLEGAL_HALL_STATE whenever the phase PWM is enabled.

To prove this, you could try reducing the supply voltage. The amount of noise can go with the square of DC Bus voltage, so you might not have to reduce it by much to see a difference.

Please try the ferrite ring (common-mode choke) on the motor wires, and the capacitors on the sensor wires. That should be plenty enough to run at full voltage.

@timoldenb brought up an interesting point in another thread: Encoder ERROR_ILLEGAL_HALL_STATE on firmware version 5.2 - #2 by timoldenb

This could be a firmware issue and nothing to do with noise. There are some known bugs due to config compatibility between firmware versions. If you have recently upgraded from 0.5.1 to 0.5.2 without erasing your config, then apparently this can cause ILLEGAL_HALL_STATE errors.

Can you add encoder.shadow_count to your liveplotter?
If it stays at 0 while the Hall states change, then it’s a firmware bug.
Try backing up and erasing your config.

Very interesting - I seem to be having the symptoms of both problems at once! Running the liveplotter during the calibration sequence does show that the hall state somtimes jumps to 7 or 0 (which was never seen manually turning the motor), AND the encoder.shadow_count does remain continuously at 0 when the motor calibrates and the hall state changes. The odd thing though is that I built the config entirely after upgrading to 0.5.2, so that makes me think it may just be the EMI. Does this make sense?

Also, just for due diligence, tried re-installing 0.5.2 and making a new config file - same problem: mostly normal hall states during calibration but the occasional jump to 0 or 7. I’ve ordered the ferrite ring, and will set that up on the motor phase wires as soon as I get it. I’ll try that, as well as 3 22 nF resistors between the A, B, and Z hall inputs and the hall ground. Hopefully that works.

Yes it sounds like it is indeed just the EMI problem then. I’m sure those measures will fix it. :slight_smile:
it is weird about the shadow_count not updating though. What about pos_estimate?

1 Like

Im having a similar issue with illegal hall state (after the odrivetool dfu update), and ferrites didnt do the trick. Any other ideas you guys might have?