PIC Motor Control with EEPROM and Interactive Menu Example

From Mech
Jump to navigationJump to search

Introduction

This project is based on the PIC Motor Control and Serial Port Example project, but includes an interactive interface for manipulating the controller variables. This project was originally written to control a 10,000 rpm motor with a 100 count/revolution encoder with a 4x QEI, so has a higher sampling rate and different controller gains than the previous project. To accommodate the higher sampling rate, this PIC uses a 40Mhz external oscillator.

This program implements a closed-loop feedback velocity controller for a motor with a quadrature encoder on its shaft. Use HyperTerminal on a PC to control the motor. In HyperTerminal, select a baud rate of 115200 bps and use ANSI emulation. The motor controller will stream the velocity of the motor (in encoder counts per period) to the window. The PWM values in this program were calculated manually to optimize the code and performance.

After programming, press 'p' to stop the motor and access the menu, then press '9' to initialize the variables to their default values. If changes do not take effect, try powering down the PIC and turning it back on. Variable values are stored in the EEPROM and are non-volatile. Floating point numbers must be entered in the floating point format, e.g. 3.00 instead of 3. Because the PIC's C library has no float-string conversion, floating point numbers will be displayed in the raw hexadecimal IEEE 754 format.