![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Teclado para control PID
Dependencies: Debounced FPointer TextLCD11 keypad mbed
main.cpp
- Committer:
- mandres7
- Date:
- 2013-12-04
- Revision:
- 1:f578cd888e48
- Parent:
- 0:17aecb7bba09
- Child:
- 2:da30c4b60cf4
File content as of revision 1:f578cd888e48:
#include "mbed.h" #include "keypad.h" #include "TextLCD.h" TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7 AnalogIn Ain(PTC2); AnalogOut Aout(PTE30); int C4=0x0C; int C1=0x0E; int p=0; int c=0; int y=0; 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; float ap,ai,ad; int sp=0; int kp=0; int ki=0; int kd=0; // Define your own keypad values char Keytable[] = { '1', '2', '3', '*', '4', '5', '6', '0', '7', '8', '9', '#', 'A', 'B', 'C', 'D' }; int Teclado[] = { 1, 4, 7, 13, 2, 5, 8, 0, 3, 6, 9, 14, 10,11,12, 15 }; uint32_t cbAfterInput(uint32_t key) { if (Keytable[key]=='A') { Teclado[key]=0; ++c; } if(Keytable[key]=='B') { Teclado[key]=0; sp=0; kp=0; ki=0; kd=0; } if(Keytable[key]=='D'){ Teclado[key]=0; p=1; } //////////// if (c==0){ sp=sp+Teclado[key]; } if (c==1) { kp=kp+Teclado[key]; } if (c==2) { ki=ki+Teclado[key]; } if (c==3) { kd=kd+Teclado[key]; } //////////// return 0; }//fin unit32_t int main() { Keypad keypad(PTA2,PTD4,PTD3,PTD1,PTD2,PTD0,PTD5,PTA13); keypad.CallAfterInput(&cbAfterInput); keypad.Start(); lcd.cls(); lcd.printf("Sp: %d",sp); lcd.locate(8,0); lcd.printf("Kp: %d",kp); lcd.locate(0,1); lcd.printf("Ki: %d",ki); lcd.locate(8,1); lcd.printf("Kd: %d",kd); lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD lcd.locate(0,0); lcd.printf("Sp: %d",sp); while (1) { if (c==0){ lcd.locate(3,0); lcd.putc(0xFE); lcd.locate(4,0); lcd.printf("%d",sp); //NEW !! (not zeros in -- process) if(sp<10){ lcd.locate(5,0); lcd.putc(0xFE); } if(sp<100){ lcd.locate(6,0); lcd.putc(0xFE); } lcd.locate(4,0); lcd.printf("%d", sp); //wait(0.1); // } if (c==1){ lcd.locate(11,0); lcd.putc(0xFE); lcd.locate(12,0); lcd.printf("%d",kp); //NEW !! (not zeros in -- process) if(kp<10){ lcd.locate(13,0); lcd.putc(0xFE); } if(sp<100){ lcd.locate(14,0); lcd.putc(0xFE); } lcd.locate(12,0); lcd.printf("%d", kp); //wait(0.1); // } if (c==2) { lcd.locate(3,1); lcd.putc(0xFE); lcd.locate(4,1); lcd.printf("%d",ki); //NEW !! (not zeros in -- process) if(ki<10){ lcd.locate(5,1); lcd.putc(0xFE); } if(ki<100){ lcd.locate(6,1); lcd.putc(0xFE); } lcd.locate(4,1); lcd.printf("%d", ki); //wait(0.2); // } if (c==3) { lcd.locate(11,1); lcd.putc(0xFE); lcd.locate(12,1); lcd.printf("%d",kd); //NEW !! (not zeros in -- process) if(kd<10){ lcd.locate(13,1); lcd.putc(0xFE); } if(kd<100){ lcd.locate(14,1); lcd.putc(0xFE); } lcd.locate(12,1); lcd.printf("%d", kd); //wait(0.2); } if(c==4 || c>4){ c=0; } if(p==1){ c=0; break; } } lcd.writeCommand(C4);//escribimos un comando segun el manual del modulo LCD para quitar cursor bajo lcd.cls(); //borra la pantalla lcd.printf(" GUARDADOS!"); wait(2); lcd.cls(); lcd.printf(" INICIA EL PID"); wait(2); // se imprimen los parches del control ***************************************** 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 // }//int main