DOC PREVIEW
U of U ECE 3720 - Lecture 24 - Microcomputer-Based Control Systems
Pages 7

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 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 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1'&$%ECE/CE 3720: Embedded System DesignChris J. MyersLecture 24: Microcomputer-Based Control SystemsSlide 2'&$%Introduction to Digital Control Systems• Learned about systems that collect information from theenvironment.• Now, we use this information to control the environment.• A control system is a collection of mechanical andelectrical devices connected to regulate a physical plant• Many embedded applications are control systems.• Control theory is a richly developed discipline covered byother courses, so we emphasize implementation issues.1Slide 3'&$%Block Diagram(See Figure 13.1)Slide 4'&$%Open-Loop Control Systems(See Figures 13.2 and 13.3)2Slide 5'&$%Traffic Light Control System(See Figures 13.2 and 13.3)Slide 6'&$%Traffic Light Controllerconst struct State {unsigned char Out; /* Output to Port B */unsigned short Time;/* Time in sec to wait */const struct State *Next;}; /* Next state */typedef const struct State StateType;#define NorthRed_EastGreen &fsm[0]#define NorthRed_EastYellow &fsm[1]#define NorthGreen_EastRed &fsm[2]#define NorthYellow_EastRed &fsm[3]StateType fsm[4]={{0x21, 180, NorthRed_EastYellow},{0x22, 15, NorthGreen_EastRed},{0x0C, 180, NorthYellow_EastRed},{0x14, 15, NorthRed_EastGreen}};3Slide 7'&$%Traffic Light Controller (cont)void main(void){ StatePtr *Pt; /* Current State */Pt=NorthRed_EastGreen; /* Initial State */DDRB=0xFF; /* Make Port B outputs */while(1){PORTB=Pt->Out; /* Perform output */Wait(Pt->Time);/* Time to wait in this state */Pt=Pt->Next; /* Move to next state */}};Slide 8'&$%Open-Loop Stepper Controller(See Figure 13.6)4Slide 9'&$%Circular List for Stepper Motorconst struct State {unsigned char Out; /* Output to Port B */const struct State *Next;}; /* Next state */typedef const struct State StateType;#define S6 &fsm[0]#define S5 &fsm[1]#define S9 &fsm[2]#define S10 &fsm[3]StateType fsm[4]={{0x06, S5},{0x05, S9},{0x09, S10},{0x0A, S6};StatePtr *Pt; /* Current State */unsigned short Speed;Slide 10'&$%Spin Stepper Motor at Constant Speed#define OC5 0x08#pragma interrupt_handler TOC5handler()void TOC5handler(void){PORTB=Pt->Out; // output for this statePt=Pt->Next; // Move to next stateTFLG1=OC5; // Ack OC5FTOC5=TOC5+Speed; }// Executed every stepvoid ritual(void) {asm(" sei"); // make atomicTMSK1|=OC5; // Arm output compare 5TFLG1=OC5; // Initially clear OC5FSpeed=10000; // initial speedPt=S6; // initial stateTOC5=TCNT+2000; // First one in 1 msasm(" cli"); }5Slide 11'&$%Bang-Bang Temperature Controller(See Figure 13.7 and 13.8)Slide 12'&$%Bang-Bang Temperature Controller(See Figure 13.9)6Slide 13'&$%Bang-Bang Temperature Control Softwareunsigned char Tlow,Thigh,T; int E; // units in Cvoid Actuator(unsigned char relay){PORTB=relay;} // turns power on/off#pragma interrupt_handler TOC5handler()void TO5handler(void){T=SE(A2D(channel)); // estimated TE=Tstar-T; // errorif(T<Tlow)Actuator(0); // too cold so offelse if (T>Thigh)Actuator(1); // too hot so on// leave as is if Tlow<T<ThighTOC5=TOC5+rate; // periodic rateTFLG1=0x08; } // ack OC5FSlide 14'&$%Position Control System Using Incremental Control(See Figures 13.10 and 13.11)7Slide 15'&$%Incremental Position Control Systemunsigned char Xstar,X; int E; // in mm#pragma interrupt_handler TOC5handler()void TO5handler(void){ int new;X=SE(A2D(channel)); // estimated (mm)E=Xstar-X; // error (mm)new=PORTB; // promote to 16 bitsif(E< -1) new--; // decreaseelse if (E>1) new++; // increase// leave as is if -1<E<1if(new<0) new=0; // underflowif(new>255) new=255; // overflowPORTB=new; // output to actuatorTOC5=TOC5+rate; // establish periodicTFLG1=0x08; } // ack OC5FSlide 16'&$%Block Diagram of a Linear Control System(See Figure 13.12)8Slide 17'&$%General Approach to a PID ControllerU (t) = KpE(t) + KIZt0E(τ )dτ + KDdE(t)dtU (n) = P (n) + I (n) + D(n)P (n) = KpE(n)I(n) = I(n − 1) + KI· E(n) · ∆tD(n) = KD·E(n) − E(n − 1)∆tLarge errorsD(n) = KD·12E(n) − E(n − 3)3∆t+12E(n − 1) − E(n − 2)∆tD(n) = KD·E(n) + 3E(n − 1) − 3E(n − 2) − E(n − 3)6∆tSlide 18'&$%Effect of Noise on Derivative Calculation(See Figure 13.13)9Slide 19'&$%Interface of a PID Velocity Controller(See Figure 13.14)Slide 20'&$%Velocity PID Controller10Slide 21'&$%Integral Controller with a PWM Actuator(See Figure 13.15 and Table 13.1)Slide 22'&$%Integral Position Control Softwareunsigned int Time; // Time in msecunsigned int X; // Est position in cmunsigned int Xstar; // Desired pos in cmunsigned int U; // Actuator duty cycleunsigned int Cnt; // once a secunsigned int Told; // used to meas period11Slide 23'&$%Integral Position Control Software (cont)#pragma interrupt_handler TOC5handler()void TOC5Handler(void){ int NewU;TFLG1=0x08; // Ack OC5FTOC5=TOC5+2000; // every 1 msTime++; // used to measure periodif((Cnt++)==1000){ Cnt=0; // every 1 sec// 0<X<100, 0<Xstar<100, 100<U<19900, so// Min when U=100,Xstar=0,X=100, min NewU = -900// Max when U=19900,Xstar=100,X=0, max NewU = 20900// so NewU will be a valid signed intNewU=U+10*(Xstar-X);if(NewU<100) NewU=100; // Constrainif(NewU>19900) NewU=19900;U=NewU; } }Slide 24'&$%PWM Actuator Control Software#pragma interrupt_handler TOC4handler()void TOC4Handler(void){TFLG1=OC4F; /* Ack */if (TCTL1&0x04) /* OL4 bit *//* OL4=1, High for the next U cycles */TOC4=TOC4+U;else/* OL4=0, Low for the next 20000-U cyc */TOC4=TOC4+20000-U;TCTL1^=0x04; } /* Toggle OL4 */12Slide 25'&$%Sensor Measurement Software// Time is incremented every 1 ms, by OC5// This handler is executed on rise#pragma interrupt_handler TIC1handler()void TIC1Handler(void){unsigned int p;TFLG1 = IC1F; // Ack IC1Fp = Time-Told; // period in msecX = p-10; // estimated position (cm)Told=Time;}Slide 26'&$%Initialization Softwarevoid ritual(void) {asm(" sei"); /* atomic */OC1M=0; OC1D=0;TCTL1=0x08; // Clear OC4TCTL2=0x10; // capture on rise of IC1TMSK1=OC5F+OC4F+IC1F; // ArmU=10000; // Initial U , half powerTime = 0; Told=0; Cnt=0;TFLG1=OC5F+OC4F+IC1F; // clear flagsTOC5=TCNT+2000; // First OC5 in 1 msTOC4=TCNT+100; // First OC4 in 50usasm(" cli");}13Slide 27'&$%Relative Timing of Interrupts(See Figure 13.16)Slide 28'&$%Empirical Method to Determine Parameters• Start with a proportional term (kp) which will generate asmooth motor speed but speed is not correct.• Try different kpvalues till response time is acceptable.• Response time is time from change in X∗till a newconstant speed is achieved.• Next, add kIterm to improve steady state accuracywithout adversely affecting


View Full Document

U of U ECE 3720 - Lecture 24 - Microcomputer-Based Control Systems

Course: Ece 3720-
Pages: 7
Download Lecture 24 - Microcomputer-Based Control Systems
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 Lecture 24 - Microcomputer-Based Control Systems 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 Lecture 24 - Microcomputer-Based Control Systems 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?