405 Documentation  9.0
Lab08: Motor and Encoder Drivers

Motor and Encoder Drivers Development

The goal of this lab was to develop drivers for the DRV8847 motor driver chip and attached 16-bit encoder. The final results are motorDriver.py and encoderDriver.py.

This lab was done in collaboration with Jacob Everest (https://mediocre-code.bitbucket.io/)

(Source: https://bitbucket.org/dhmorse/mechatronics_shared/src/master/Lab08/)

Encoder

The timer used for the encoder has a 0xff period and prescaler of 8. At these settings the encoder resolution is 256 counts per rotation. Positive rotation is defined to be counter clockwise and negative is clockwise. Once reaching a count of 255 the encoder loops back to 0 and continues. Similarly, rolling through 0 clockwise will loop to 255 and proceded to decreasing values.

Motor Driver and Base

The DC motors of the pivoting platform can be enabled/disabed by setting their respective nSleep pins. In addition to an nSleep pin, the motors have an nFault pin. This function pin is triggered when the current passing through the motor driver is too high. To better understand the nFault bit a USB logic analyzer was used to measure the signal from the nFault pin. The following image is a screenshot of the results.

nFault Pin Testing

Because of the hysteresis, the motor cannot rely on the nFault bit stopping motor operation. An external interrupt is therefore required to trigger a stop condition that can only be overwritten manually. This improves overload safety for the motors as well as improved operator safety. While develping the program we had an issue with the nFault bit triggering on motor start-up. The current code works around the issue with an additional check and set condition. Additionally, because the nFault pin cannot be set up for each motor individually, a MotorBase object is required. This object requires two Motor objects and handles setting the nFault pin, and handling the resulting ISR.

Author
Hunter Morse
Date
Winter 2021