DOC PREVIEW
U of U ECE 3720 - LECTURE NOTES
Pages 4

This preview shows page 1 out of 4 pages.

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

Unformatted text preview:

Slide 1'&$%ECE/CE 3720: Embedded System DesignChris J. MyersLecture 25: Fuzzy Logic ControlSlide 2'&$%Fuzzy Logic Control• Simpler than PID controllers and can be more robust.• Physical plant has real state variables.• DAS monitors them and creates estimated state variables.• Preprocessor calculates crisp inputs.• Fuzzification converts into input fuzzy membership sets.• The fuzzy rules calculate output fuzzy membership sets.• Defuzzification converts them into crsip outputs.• Postprocessor modifies them into more convenient format.• Actuator system affects physical plant based on outputs.1Slide 3'&$%Interface of a Motor Controlled with Fuzzy LogicSlide 4'&$%DAC, ADC Fuzzy Controller• Two control inputs:– S∗: desired motor speed, rpm– S0: current estimated motor speed, rpm• One control output:– N : digital value that we write to the DAC• To use 8-bit math, change units to 1000/256 = 3.9 rpm– T∗= (256 · S∗)/1000 : desired motor speed, 3.9 rpm– T0= (256 · S0)/1000 : current motor speed, 3.9 rpm• Two crisp inputs:– E = T∗− T0: error in motor speed, 3.9 rpm– D = T0(n) − T0(n − 1) : change in speed, 3.9 rpm2Slide 5'&$%Subtraction with Overflow/Underflow Checkingchar Subtract(unsigned char N, unsigned char M){/* returns N-M */unsigned int N16,M16;int Result16;N16=N; /* Promote N,M */M16=M;Result16=N16-M16; /* -255Result16+255 */if(Result16<-128) Result16 = -128;if(Result16>127) Result16 = 127;return(Result16);}Slide 6'&$%Crisp Inputsunsigned char Ts; /* Desired Speed */unsigned char T; /* Current Speed */unsigned char Told;/* Previous Speed */char D; /* Change in Speed */char E; /* Error in Speed */void CrispInput(void){E=Subtract(Ts,T);D=Subtract(T,Told);Told=T;} /* Set up Told for next time */3Slide 7'&$%Fuzzy Membership Sets• Input fuzzy membership sets:– Slow - True if motor is spinning too slow– OK - True if motor is spinning at proper speed– Fast - True if moter is spinning too fast– Up - True if moter speed is getting larger– Constant - True if motor speed is remaining the same– Down - True if motor speed is getting smaller• Output fuzzy membership sets:– Decrease - True if motor speed should be decreased– Same - True if motor speed should remain the same– Increase - True if motor speed should be increasedSlide 8'&$%Fuzzification4Slide 9'&$%Calculation of the Fuzzy Membership Variables#define TE 20unsigned char Fast, OK, Slow, Down, Constant, Up;#define TD 20unsigned char Increase,Same,Decrease;#define TN 20void InputMembership(void){if(E <= -TE) { /* E <= -TE */Fast=255; OK=0; Slow=0;} else if (E < 0) { /* -TE<E<0 */Fast=(255*(-E))/TE; OK=255-Fast; Slow=0;} else if (E < TE) { /* 0<E<TE */Fast=0; Slow=(255*E)/TE; OK=255-Slow;} else { /* +TE <= E */Fast=0; OK=0; Slow=255; }Slide 10'&$%Calculation of the Fuzzy Membership Var (cont)if(D <= -TD) { /* D<=-TD */Down=255; Constant=0; Up=0;} else if (D < 0) { /* -TD<D<0 */Down=(255*(-D))/TD; Constant=255-Down; Up=0;} else if (D < TD) { /* 0<D<TD */Down=0; Up=(255*D)/TD; Constant=255-Up;} else { /* +TD <= D */Down=0; Constant=0; Up=255;}}5Slide 11'&$%Fuzzy Logic RulesSlide 12'&$%Calculation of the Output Fuzzy Membershipunsigned char min(unsigned char u1,unsigned char u2){if(u1>u2) return(u2);else return(u1);}unsigned char max(unsigned char u1,unsigned char u2){if(u1<u2) return(u2);else return(u1);}void OutputMembership(void){Same=min(OK,Constant);Decrease=min(OK,Up)Decrease=max(Decrease,min(Fast,Constant));Decrease=max(Decrease,min(Fast,Up));Increase=min(OK,Down)Increase=max(Increase,min(Slow,Constant));Increase=max(Increase,min(Slow,Down));}6Slide 13'&$%DefuzzificationSlide 14'&$%Calculation of the Crisp Outputchar dN;void CrispOutput(void){dN=(TN*(Increase-Decrease)) /(Decrease+Same+Increase);}7Slide 15'&$%Main Program for Fuzzy Logic Controlunsigned int Time;#define rate 2000void Initialize(void){OPTION=0x80; /* Turn on A/D */PORTB=0;N=0; /* Initial Actuator */Told=0;Ts=128; } /* 500 rpm */#define CCF 0x80unsigned char Sample(unsigned char channel){ADCTL=channel; /* Start A/D */while((ADCTL&CCF)==0); /* Wait for CCF */return(ADR1);}Slide 16'&$%Main Program for Fuzzy Logic Control (cont)void Main(void){ int dT;Initialize(); /* Turn on A/D init globals */Time=TCNT+rate; /* First TCNT value */while(1){while((dT=Time-TCNT)>0){};Time=Time+rate; /* Next TCNT value */T=Sample(0); /* Sample A/D and set T */CrispInput(); /* Calculate E,D and new Told*/InputMembership();/*Fast,OK,Slow,Down,Cons,Up*/OutputMembership();/* Inc,Same,Dec */CrispOutput(); /* dN */N=max(0,min(N+dN,255));PORTB=N; /* Set Actuator


View Full Document

U of U ECE 3720 - LECTURE NOTES

Course: Ece 3720-
Pages: 4
Download LECTURE NOTES
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 NOTES 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 NOTES 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?