PID, tarea 3, procesadores

Dependencies:   Debounced TextLCD mbed

Committer:
mandres7
Date:
Sun Nov 10 20:31:02 2013 +0000
Revision:
0:6ef000c1b903
Child:
1:80f82aa3d0ec
PID

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mandres7 0:6ef000c1b903 1 #include "mbed.h"
mandres7 0:6ef000c1b903 2 #include "TextLCD.h"
mandres7 0:6ef000c1b903 3 #include "DebouncedIn.h"
mandres7 0:6ef000c1b903 4
mandres7 0:6ef000c1b903 5
mandres7 0:6ef000c1b903 6 TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7
mandres7 0:6ef000c1b903 7 DigitalOut myled(LED1);
mandres7 0:6ef000c1b903 8 AnalogOut Aout(PTE30);
mandres7 0:6ef000c1b903 9 AnalogIn Ain(PTC2);
mandres7 0:6ef000c1b903 10 DebouncedIn up(PTE3);
mandres7 0:6ef000c1b903 11 DebouncedIn down(PTE4);
mandres7 0:6ef000c1b903 12 DebouncedIn Gain(PTE2);
mandres7 0:6ef000c1b903 13 int ap,n,ai,ad;
mandres7 0:6ef000c1b903 14
mandres7 0:6ef000c1b903 15 float i=0.7; // set point
mandres7 0:6ef000c1b903 16 float j=0; // salida planta
mandres7 0:6ef000c1b903 17 float h=0; // entrada planta
mandres7 0:6ef000c1b903 18 float m=0; // Error
mandres7 0:6ef000c1b903 19 float mv=0;
mandres7 0:6ef000c1b903 20 float g=0;
mandres7 0:6ef000c1b903 21 float x=0;
mandres7 0:6ef000c1b903 22 int kp=3;
mandres7 0:6ef000c1b903 23 int ki=15;
mandres7 0:6ef000c1b903 24 int kd=1;
mandres7 0:6ef000c1b903 25
mandres7 0:6ef000c1b903 26
mandres7 0:6ef000c1b903 27 int main(){
mandres7 0:6ef000c1b903 28
mandres7 0:6ef000c1b903 29 //float Setpoint=0.6;
mandres7 0:6ef000c1b903 30
mandres7 0:6ef000c1b903 31 while(1) {
mandres7 0:6ef000c1b903 32
mandres7 0:6ef000c1b903 33 wait(0.3);
mandres7 0:6ef000c1b903 34
mandres7 0:6ef000c1b903 35 if(i<0.999){
mandres7 0:6ef000c1b903 36
mandres7 0:6ef000c1b903 37 j=Ain;
mandres7 0:6ef000c1b903 38 m=(i-j);
mandres7 0:6ef000c1b903 39 //n=m*100;
mandres7 0:6ef000c1b903 40 ap=kp*m;
mandres7 0:6ef000c1b903 41 ai=(ki*m)+ai;
mandres7 0:6ef000c1b903 42
mandres7 0:6ef000c1b903 43 if (ai>999){
mandres7 0:6ef000c1b903 44 ai=998;
mandres7 0:6ef000c1b903 45 }
mandres7 0:6ef000c1b903 46
mandres7 0:6ef000c1b903 47 ad=kd*(m-mv);
mandres7 0:6ef000c1b903 48 h=ap+ai+ad;
mandres7 0:6ef000c1b903 49 x=h/100;
mandres7 0:6ef000c1b903 50 g=(h*3.3/100);
mandres7 0:6ef000c1b903 51
mandres7 0:6ef000c1b903 52 if (h<0){
mandres7 0:6ef000c1b903 53 h=0;
mandres7 0:6ef000c1b903 54 }
mandres7 0:6ef000c1b903 55
mandres7 0:6ef000c1b903 56
mandres7 0:6ef000c1b903 57
mandres7 0:6ef000c1b903 58 Aout=g;
mandres7 0:6ef000c1b903 59 wait(0.22);
mandres7 0:6ef000c1b903 60
mandres7 0:6ef000c1b903 61
mandres7 0:6ef000c1b903 62 lcd.cls();
mandres7 0:6ef000c1b903 63 lcd.printf("Er:%.3f",m);
mandres7 0:6ef000c1b903 64 lcd.locate(8,0);
mandres7 0:6ef000c1b903 65 lcd.printf("Me:%.3f",j);
mandres7 0:6ef000c1b903 66 lcd.locate(0,1);
mandres7 0:6ef000c1b903 67 lcd.printf("Sp:%.2f",i);
mandres7 0:6ef000c1b903 68 lcd.locate(8,1);
mandres7 0:6ef000c1b903 69 lcd.printf("Co:%.3f",x);
mandres7 0:6ef000c1b903 70 }
mandres7 0:6ef000c1b903 71
mandres7 0:6ef000c1b903 72
mandres7 0:6ef000c1b903 73 mv=m;
mandres7 0:6ef000c1b903 74 }
mandres7 0:6ef000c1b903 75
mandres7 0:6ef000c1b903 76 }