ME 333 Lab 4

From Mech
Jump to navigationJump to search

In this lab, we are going to use the PIC32 microcontroller to control the motor's position with a proportional feedback controller. A block diagram of the overview of this lab is shown below.



The PIC32 is going to generate a square wave reference signal (ref) that will cause the motor to alternate between two positions. This reference signal could be changed to any arbitrary signal such as a sinusoid or a triangle wave, but for this lab we are going to stick with a square wave. The period and amplitude of the square wave will be analog inputs to the PIC32.

The quadrature encoder attached to your motor creates two signals similar to those shown below. These signals will be sent to a encoder/decoder chip (LS7083) that converts the signals into up and down counts to be sent to the PIC32. The up and down counts will be read by the PIC32 and converted into a position for the motor (output). This algorithm will be explained in further detail in the encoder section.

The position error is the difference between the reference signal and the output. The error will be sent to a controller, in this case a proportional controller and converted into an input signal (u). This is shown in the equation below:

The input signal is then converted into a PWM to cause the motor to move and produce a new output.

So how do we do this?

First, we are going to write the code in which we will learn about the following programming topics:

  • Timers
  • Interrupts
  • PWM

After programming the PIC32, you will construct the circuit for this motor controller. This circuit will include the following hardware pieces:

  • H-bridge
  • Motor with Encoder
  • Encoder/Decoder Chip

After the circuit has been created, we will test the feedback control with different proportional gains (Kp).


Programming

This section details the code required for Feedback Control of Motor Position with the PIC32.

Overview: write something here

Create a new project folder and call it MotorPositionController. - Put HardwareProfile.h, HardwareProfile_NU32.h, and procdefs.ld. These are the same as in HelloWorld. The can be downloaded here - Create a new MPLAB project using the normal procedure - Make a new file in MPLAB and save as "MotorPositionController.c" without the quotes. This will be our main c file.

- Copy and paste the following lines of code that will serve as our template for the code.

/* 
	Motor Position Control
	Lab 4
*/

/** INCLUDES ***************************************************/
#include "HardwareProfile.h"

/** Constants **************************************************/

#define TRUE 		1
#define FALSE		0

/** Function Declarations **************************************/


/** Global Variables *******************************************/

/** Main Function **********************************************/

int main(void)
{
	int	pbClk;
		
	// Configure the proper PB frequency and the number of wait states
	pbClk = SYSTEMConfigPerformance(SYS_FREQ);
		
	// Allow vector interrupts
	INTEnableSystemMultiVectoredInt();
	
	mInitAllLEDs();
	
	while(1)
	{
		
	}

} //end main


/** Interrupt Handlers *****************************************/

/** Other Functions ********************************************/

Circuit

Feedback Control