PID, tarea 3, procesadores
Dependencies: Debounced TextLCD mbed
Diff: main.cpp
- Revision:
- 0:6ef000c1b903
- Child:
- 1:80f82aa3d0ec
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Nov 10 20:31:02 2013 +0000 @@ -0,0 +1,76 @@ +#include "mbed.h" +#include "TextLCD.h" +#include "DebouncedIn.h" + + +TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7 +DigitalOut myled(LED1); +AnalogOut Aout(PTE30); +AnalogIn Ain(PTC2); +DebouncedIn up(PTE3); +DebouncedIn down(PTE4); +DebouncedIn Gain(PTE2); +int ap,n,ai,ad; + +float i=0.7; // set point +float j=0; // salida planta +float h=0; // entrada planta +float m=0; // Error +float mv=0; +float g=0; +float x=0; +int kp=3; +int ki=15; +int kd=1; + + +int main(){ + +//float Setpoint=0.6; + + while(1) { + + wait(0.3); + + if(i<0.999){ + + j=Ain; + m=(i-j); + //n=m*100; + ap=kp*m; + ai=(ki*m)+ai; + + if (ai>999){ + ai=998; + } + + ad=kd*(m-mv); + h=ap+ai+ad; + x=h/100; + g=(h*3.3/100); + + if (h<0){ + h=0; + } + + + + Aout=g; + wait(0.22); + + + lcd.cls(); + lcd.printf("Er:%.3f",m); + lcd.locate(8,0); + lcd.printf("Me:%.3f",j); + lcd.locate(0,1); + lcd.printf("Sp:%.2f",i); + lcd.locate(8,1); + lcd.printf("Co:%.3f",x); + } + + + mv=m; + } + +} \ No newline at end of file