Close

Avoiding motor runaway

A project log for Brushed DC Servo Drive

Low cost PID servo drive for small CNC machinery

ottoragamottoragam 02/26/2016 at 08:230 Comments

The other thing I wanted to address is the detection of a faulty encoder, in particular, I want to be able to handle the loss of the quadrature signal and an incorrect A/B channel wiring.
First, motor runaway caused by an inverted encoder channel signal is controlled via programming a following error check. When the driver tries to rotate the motor in one direction, the encoder will output a poulse train that corresponds to rotation in the othe direction, thus incrementing the error magnitude until it surpasses the following error value, and when this happens the driver stops the motor.
This test also gives the driver the ability to signal when the motor is lagging too much and avoid ruining a CNC job.

A encoder signal loss also causes motor runaway. We could analyze the following cases:

  1. Lost encoder signal and STEP input present. In this case, the error will grow each time a STEP pulse is present, until the following error value is reached, and an alarm is raised/motor is stopped.
  2. Lost encoder signal and no STEP input present. This case happens when the motor still needs to move an amount of "steps" that is below the following error value. The two conditions I'm using to determine if this case occurs are: comparing the current encoder state to an inmediate previous one to see if the signal changed, and checking if the STEP input is firing. The tricky thing with this heuristic is that not changing encoder signal + no STEP input conditions happen also in normal operation, when the motor has reached the desired position and is waiting for the next move.

Becasuse of that, I can't just make the driver signal a fault when those conditions are met. One could think on cheking the PID output value too, to see if the motor is commanded to be moved when the encoder state is not changing, by looking at the duty cycle value, but that's not really a reliable option because of the value that we compare the duty cycle against may not be easy to determine, as it varies with the PID calibration, motor cogging, etc.
I decided to just zero the duty cycle if the two conditions I mentioned are met for a certain number of times (to filter false positives). This way, I avoid motor runaway, but I also allow the servo drive to further receive STEP signals in case everything was functioning correctly.
The driver must perform the aforementioned tests continuously to be able to stop the motor at any time if something occurs to the encoder.

In the following video I start the motor and apply pulses to the STEP and DIR inputs. The algorithm discerns between a finished move status and a disconnected encoder status, and stops the motor when the encoder gets disconnected (and lights the LED).


I'll upload the updated code to the project's repo. I also need to program something to detect when only one of the encoder channels is lost.

Discussions