Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of controlPID by
Revision 2:434bb36fa59f, committed 2013-10-18
- Comitter:
- jmcallef
- Date:
- Fri Oct 18 05:12:02 2013 +0000
- Parent:
- 1:83ffe66ee756
- Commit message:
- Asignar valores control PID sencillo
Changed in this revision
TextLCD.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 83ffe66ee756 -r 434bb36fa59f TextLCD.lib --- a/TextLCD.lib Fri Oct 11 05:41:20 2013 +0000 +++ b/TextLCD.lib Fri Oct 18 05:12:02 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/tony63/code/TextLCD/#31946c9940c3 +http://mbed.org/users/jmcallef/code/TextLCD/#cbc652aee573
diff -r 83ffe66ee756 -r 434bb36fa59f main.cpp --- a/main.cpp Fri Oct 11 05:41:20 2013 +0000 +++ b/main.cpp Fri Oct 18 05:12:02 2013 +0000 @@ -16,7 +16,6 @@ 1A para derecha */ - int C1=0x0E; // solo muestra el curzor int C2=0x18; // desplaza izquierda int C3=0x1A; // desplaza derecha @@ -26,7 +25,11 @@ int kp, ki, kd, sp, err, med, yr, pid, ap, ai, ad, err_v, cycle; int main() { + +lcd.writeCommand(C1); // Ubico el cursor en el Display. + lcd.cls(); + lcd.locate(0,0); lcd.printf("Sp%d",sp); lcd.locate(8,0); lcd.printf("Kp%d",kp); @@ -34,7 +37,7 @@ 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); @@ -42,19 +45,19 @@ while(1) { if (button3.falling()) { ++j; - } //INCREMENTA POSICION DEL MENU COB BOTON 3 + } //INCREMENTA POSICION DEL MENU CON BOTON 3 if (j==0){ - lcd.locate(2,0); + lcd.locate(3,0); lcd.printf("%d",sp); if (button1.falling()) { - ++sp; // ademas revisa boton 1 para incrementar + ++sp; // ademas revisa boton 1 para incrementar } if (button2.falling()) { - --sp; // ademas revisa boton 2 para decrementar + --sp; // ademas revisa boton 2 para decrementar } } if (j==1) { - lcd.locate(10,0); + lcd.locate(11,0); lcd.printf("%d",kp); if (button1.falling()) { ++kp; @@ -64,17 +67,17 @@ } } if (j==2) { - lcd.locate(2,1); + lcd.locate(3,1); lcd.printf("%d",ki); if (button1.falling()){ - ++ki; + ++ki;9 } if (button2.falling()){ --ki; } } if (j==3) { - lcd.locate(10,1); + lcd.locate(11,1); lcd.printf("%d",kd); if (button1.falling()){ ++kd; @@ -91,59 +94,6 @@ break; //sale del bucle si pisan suiche4 } - } - 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 ***************************************** - lcd.cls(); - lcd.printf("Er%d",err); - lcd.locate(8,0); - lcd.printf("Me%d",med); - lcd.locate(0,1); - lcd.printf("Sp%d",sp); - lcd.locate(8,1); - lcd.printf("Co%d",pid); - wait(5); - - // CICLO PRINCIPAL CONTROLADOR PID - - while(1) { - //leer puerto analogo y asignar a med - err = (sp-med); - ap = kp*err; - ai =(ki*err)+ai; //calculo de la integral del error - // se verifica que la accion integral no sea muy grande - ad = kd*(err-err_v); //calculo de la accion derivativa - pid = (ap+ai+ad); - //****se muestran las variables****************************************** - if (pid > 999){ - pid=1000; - } - - wait(.5); - lcd.locate(2,0); - lcd.printf("%d",err); - lcd.locate(10,0); - lcd.printf("%d",med); - lcd.locate(2,1); - lcd.printf("%d",sp); - lcd.locate(10,1); - lcd.printf("%d",pid); - - - // se actualizan las variables ******************************************* - err_v = err; - // se verifica que pid sea positivo ************************************** - - // se verifica que pid sea menor o igual la valor maximo ***************** - - - // se envia el valor pid a puerto analogico de salida (D/A) ************** - // se repite el ciclo - } + +} } \ No newline at end of file