Hi all,
I've been working on setting up a simple motor control system, using a BLDC with an AMT102 encoder and a Teensy 4.1 (600 MHz clock speed). The encoder is set to 100 PPR, with the motor's RPM below the max RPM for this encoder resolution (there's a 5:1 reduction gearhead on the motor, hence the low PPR setting). I'm using ~5.6k resistors to condition the 5V output signal for 3.3V tolerant inputs.
I've noticed that, when just using the A/B channels, that I'm getting a fair bit of overshoot when using bang-bang and PID control, probably due to motor inertia, so I've added in the index pulse so that I can periodically correct the motor position to avoid accumulating position error. I'm using the twisted pair shielded cable that CUI makes to reduce noise from the motor.
To test the performance, I've got a small program that uses a rising edge pin change interrupt on the encoder's index pin to toggle a GPIO pin (and increment a counter), so that I can check if pulses are being missed/if there is too much noise. On the scope everything looks usable, but I noticed that occasionally the number of counts recorded is slightly too large. On the scope I can see that, sometimes, the digital output quickly toggles twice for a single rising edge. There doesn't seem to be an obvious cause, and it doesn't seem to be reliably repeatable.
I don't think motor noise is causing issues, as I can't see noise on the scope that could be responsible. I'm considering adding short debouncing to the index pulses, but want to see if there may be some other culprit first.
Does anyone have any thoughts?
Code snippet and scope plots below; encoder index pulses are in yellow, digital IO pin being toggled is in green. Please excuse the scope noise levels, the scope I'm using is fairly old and has had a hard life!
Index pulses + GPIO toggle. Note the apparently missed pulse in the centre. False GPIO toggle shown below.
I've been working on setting up a simple motor control system, using a BLDC with an AMT102 encoder and a Teensy 4.1 (600 MHz clock speed). The encoder is set to 100 PPR, with the motor's RPM below the max RPM for this encoder resolution (there's a 5:1 reduction gearhead on the motor, hence the low PPR setting). I'm using ~5.6k resistors to condition the 5V output signal for 3.3V tolerant inputs.
I've noticed that, when just using the A/B channels, that I'm getting a fair bit of overshoot when using bang-bang and PID control, probably due to motor inertia, so I've added in the index pulse so that I can periodically correct the motor position to avoid accumulating position error. I'm using the twisted pair shielded cable that CUI makes to reduce noise from the motor.
To test the performance, I've got a small program that uses a rising edge pin change interrupt on the encoder's index pin to toggle a GPIO pin (and increment a counter), so that I can check if pulses are being missed/if there is too much noise. On the scope everything looks usable, but I noticed that occasionally the number of counts recorded is slightly too large. On the scope I can see that, sometimes, the digital output quickly toggles twice for a single rising edge. There doesn't seem to be an obvious cause, and it doesn't seem to be reliably repeatable.
I don't think motor noise is causing issues, as I can't see noise on the scope that could be responsible. I'm considering adding short debouncing to the index pulses, but want to see if there may be some other culprit first.
Does anyone have any thoughts?
Code snippet and scope plots below; encoder index pulses are in yellow, digital IO pin being toggled is in green. Please excuse the scope noise levels, the scope I'm using is fairly old and has had a hard life!
C:
volatile int32_t idx_counts = 0;
void PC_INDEX_ISR(void) {
++idx_counts;
digitalToggleFast(7);
}
void setup() {
// IO + motor control setup...
// Setup PC interrupt for index pulses
attachInterrupt(digitalPinToInterrupt(channelX), PC_INDEX_ISR, RISING);
// Drive motor at a fixed speed for a known distance, then stop...
}
Index pulses + GPIO toggle. Note the apparently missed pulse in the centre. False GPIO toggle shown below.
Last edited: