PID, tarea 3, procesadores
Dependencies: Debounced TextLCD mbed
main.cpp
- Committer:
- mandres7
- Date:
- 2013-12-04
- Revision:
- 1:80f82aa3d0ec
- Parent:
- 0:6ef000c1b903
File content as of revision 1:80f82aa3d0ec:
#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; // set point float j=0; // salida planta float ji=0; //variable proceso interno float spi=0; //variable proceso interno float h=0; // entrada planta float m=0; // Error float mv=0; float g=0; int sp=500; int kp=3; int ki=15; int kd=1; int main(){ //float Setpoint=0.6; i=sp/999; lcd.cls(); lcd.printf("Er:%.2f",m); lcd.locate(8,0); lcd.printf("Me:%.2f",j); lcd.locate(0,1); lcd.printf("Sp:%d",sp); lcd.locate(8,1); lcd.printf("Co:%.1f",h); wait(2); // while(1) { spi=sp*(3.3/999); //wait(0.3); i=sp/999; if(i<=1){ j=Ain; ji=j*3.3; m=(spi-ji); //n=m*100; ap=kp*m; ai=(ki*m)+ai; ad=kd*(m-mv); h=ap+ai+ad; if (h>999){ h=999; } if (h<0){ h=0; } g=(h/999); Aout=g; wait(0.22); lcd.cls(); lcd.printf("Er:%.2f",m); lcd.locate(8,0); lcd.printf("Me:%.2f",j); lcd.locate(0,1); lcd.printf("Sp:%d",sp); lcd.locate(8,1); lcd.printf("Co:%.1f",h); } mv=m; } //While }