DOC PREVIEW
GVSU EGR 345 - Lab 3 - A Feedback Controller

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

6.0.1 Lab 3 - A Feedback Controller6.0.1.1 - Purpose6.0.1.2 - Background/Theory6.0.1.3 - Prelab6.0.1.4 - Equipment6.0.1.5 - Experimentalegr345 lab guide - 6.16.0.1 Lab 3 - A Feedback Controller6.0.1.1 - PurposeTo use the Atmega32 microcontroller for velocity feedback control of a motor.6.0.1.2 - Background/TheoryA basic feedback control system is shown in Figure 6.1. In this system the atmega32 will output a control voltage as a PWM signal. When the output is 0V, the tran-sistor will be off, and act like an open switch. However, when the output is 5V, it will turn the transistor on, and allow current to flow to the motor. (Note: There will be a voltage drop across the transistor, in this case approximately 0.8V.) The motor shaft is connected to a tachometer to measure the motor speed. (Note: In this lab we will use another motor as the tachometer.) The tachometer will produce a voltage proportional to the motor speed.Figure 6.1 Atmega32 based velocity feedback controllerAtmega 32PWM outGNDPA0COMtachometermotorV+V-shaft couplerTIP 120/122boardVCVSVtVPPD7analog inωWhere,VCEffective PWM output voltage=VSEffective motor voltage=VPPower supply voltage (3.8V)=VtTachometer voltage=ω Angular velociy of motor/tachometer=CC++(common)egr345 lab guide - 6.2To complete the control system, a program is required. The program reads the motor speed input, Ct, from the analog voltage, Vt, and use it to adjust the out-put, Cc, to adjust the voltage, Vs, to control the motor speed. Normally a user may supply a setpoint, Cd. This setpoint indicates the desired speed. In this pro-gram care is required to ensure that the Cc value remains in the range from 0 to 255 because of the limitation of the PWM functions.Figure 6.2 The complete feedback loopThe PWM output to the motor is a square wave with a variable duty cycle. Equa-tion (1) below shows how to convert the PWM value to an effective output volt-age. It is worth noting that part of the voltage from the power supply is lost across the transistor, thus reducing the effective voltage to the motor.+-PmotorA/DWhere,CdDesired tach. speed - input via keyboard (0-1023)=CtActual tach. speed read via A/D (unsigned char, 0-1023)=CeCdCt– System error (int)==CcPCeControl value to output via PWM (unsigned char, 0-255)==P The controller gain (int)=CtCdωCcVtCeTIP120Tach.PWMexternalhardwareATMega 32C Program (interrupt driven)VSVCegr345 lab guide - 6.3To implement this controller we need a better program structure than was used before. This is shown in the following program listing. The IO_update() func-tion will be called many times per second by an interrupt subroutine. The CLK_setup function initializes the interrupt routines in the processor so that the ’SIGNAL(SIG_OVERFLOW1)’function will be called once evey 10ms. This in turn will call the IO_update() function. The main program sets up the various input out-put devices and then begins a loop where it deals with keyboard IO. Notice that the subroutines to update the inputs and outputs do not appear in the main pro-gram loop. It communicates with those routines by changing the value of the global variable ’count’.VSVPVCE–()CCCMAX--------------⎝⎠⎛⎞=VSThe effective voltage delivered to the motor=Where,VPThe power supply voltage (use 3.8V)=VCEThe voltage across the transistor when on (use 0.8V)=CMAXThe maximum count in the counter (255)=CCThe variable counter value (0-255)=(1)egr345 lab guide - 6.4#include <avr/io.h>#include <avr/signal.h>#include <avr/interrupt.h>#include "sio.c"// -------------- IO Stuff --------------------int count = 0; // a count value to be output on port Bvoid IO_setup(){DDRB = 0xFF; // all of port B is outputs}void IO_update(){// This routine will run once per interrupt for updatesPORTB = count;// put feedback control stuff here}// -------------- Clock/interrupt stuff ---------------------#define CLK_ms 10// set the updates for every 10msunsigned int CNT_timer1; // the delay timevolatile unsigned int CLK_ticks = 0; // the current number of msvolatile unsigned int CLK_seconds = 0; // the current number of secondsSIGNAL(SIG_OVERFLOW1){ // The interrupt calls this functionCLK_ticks += CLK_ms;if(CLK_ticks >= 1000){ // The number of interrupts between output changesCLK_ticks = CLK_ticks - 1000;CLK_seconds++;IO_update();}TCNT1 = CNT_timer1;}void CLK_setup(){ // Start the interrupt service routineTCCR1A = (0<<COM1A1) | (0<<COM1A0)| (0<<COM1B1) | (0<<COM1B0)| (0<<WGM11) | (0<<WGM10) | (0<<FOC1A) | (0<<FOC1B); // disable PWM and Compare Output ModesTCCR1B = (0<<WGM12) | (0<<WGM13)| (0<<ICNC1) | (0<<ICES1)| (1<<CS12) | (0<<CS11) | (1<<CS10); // set to clk/1024CNT_timer1 = 0xFFFF - CLK_ms * 8; // 8 = 1ms, 160 = 10ms TCNT1 = CNT_timer1; // start at the right point//SFIOR &= PSR10; // reset the scaling bit// use CLK/1024 prescale valueTIFR&=~(1<<TOV1); // set to use overflow interruptsTIMSK = (1<< TOIE1 );// enable TCNT1 overflowsei(); // enable interrupts flag}egr345 lab guide - 6.5One major challenge when constructing a system is debugging. The flowchart in Figure 6.3 shows the tradition approach to debugging. Figure 6.3 The Traditional Debugging ApproachWhile this debugging approach is easy to understand it takes much longer to solve problems and can become very frustrating. The debugging approach shown in Figure 6.4 is much more mature. Although it involves a few more steps, it will // -------------- The main program loop ------------------int main(){int c;sio_init();IO_setup();CLK_setup();for(;;){while((c = input()) == -1){} // wait for a keypressif(c == '+'){ // increment the output on port Bif(++count > 255) count = 255;outln("counter incremented");} else if(c == '-'){if(--count < 0) count = 0;outln("counter decremented");} else if(c == 'p'){outint(count);} else if(c == 'h'){outln("HELP: +, -, p, q");} else if(c == 'q'){break;}}sio_cleanup();return 1;}Start testingChangeSomethingDoes itwork?Stop testingegr345 lab guide - 6.6often take substantially less time. The essence of this method is that the pro-gram is not changed until the source of the problem in known. Common meth-ods are to use print statements, or other debugging tools to see what the program is doing.Figure 6.4 Enlightened Debugging ApproachStart testingDoes theprogram workcorrectly?Consider the sourceor nature of the problemSelect a possible causeor location in the programCheck to see if it isworking as expectedStop testingHas theproblem beenfound?Fix the problemegr345 lab guide -


View Full Document

GVSU EGR 345 - Lab 3 - A Feedback Controller

Documents in this Course
Y Axis

Y Axis

2 pages

Load more
Download Lab 3 - A Feedback Controller
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab 3 - A Feedback Controller and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab 3 - A Feedback Controller 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?