Mechatronics - DC Motor Control

2015-02-01 00:00:00 +0000

Overview

Completed in the Mechatronics course was becoming familiar with the PIC32, writing C code for programming the PIC32, and uploading code to the PIC32. The course ended in a project in which we created a library of functions to control a bar’s position on the end of a motor. Ultimately, the bar’s angular position tracked a reference signal by using a PID controller.

DC Motor Control Project

Control of the DC motor occurred through MATLAB, in which serial communication sent commands to the PIC32 to directly control the DC motor. Hardware used was quadrature decoder and counter chip, current sensor, H-bridge, as well as resistors and capacitors. We built up a library of functions before having a bar attached to the end of the motor follow a reference trajectory. These functions were:

  1. Read current sensor (ticks)
  2. Read current sensor (mA)
  3. Read encoder (ticks)
  4. Read encoder (degree)
  5. Reset encoder
  6. Set PWM
  7. Set current gains
  8. Get current gains
  9. Set position gains
  10. Get position gains
  11. Tune current loop
  12. Set recording samples
  13. Go to angle
  14. Get state
  15. Load cubic trajectory
  16. Load step trajectory
  17. Execute trajectory
  18. Quit

Once functions 1-14 were working, we wrote code for two control loops: current control loop (5 kHz) and position control loop (200 Hz). The PI current controller makes the current sensor reading match a reference signal by adjusting the PWM signal and motor direction. The PID position control loop determines the error between the reference position and encoder angle, setting a desired current to follow for the current control loop. Tuning of both control loops was required.

The results of following three different reference trajectories are shown below: 1) square trajectory, 2) 90 degree sine curve, 3) 180 degree sine curve

square_trajectory 90_degree_trajectory 180_degree_trajectory

Mechatronics Project