tarea#3
Dependencies: FPointer TextLCD keypad mbed
Fork of Tarea2_Teclado by
Revision 3:3ebf00293772, committed 2014-04-03
- Comitter:
- walterg
- Date:
- Thu Apr 03 05:15:46 2014 +0000
- Parent:
- 2:4c3de5a37f24
- Commit message:
- tarea# 3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Apr 03 03:46:11 2014 +0000 +++ b/main.cpp Thu Apr 03 05:15:46 2014 +0000 @@ -1,16 +1,25 @@ //Programa para hacer control PID simple, ingresa parámetros con teclado 4x4. Imprime resultados en LCD 16x2 - + #include "mbed.h" #include "TextLCD.h" #include"keypad.h" //Librería del teclado 4x4 #include"FPointer.h" //Librería complementaria para libreria keypad - + TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 Keypad keypad(PTA2,PTD4,PTD3,PTD7,PTA13,PTD5,PTD0,PTD2); //Entradas del teclado (4r,3r,2r,1r,8,7,6,5) - + + +float Tdo=1/2093.005; +float Pdo=Tdo/2; +float Tre=1/2637.02; +float Pre=Tre/2; +float Tmi=1/3135.963; +float Pmi=Tmi/2; + AnalogIn Vin(PTB0); //Voltaje de alimentación AnalogOut Vout(PTE30); //Marcar la salida analógica - + //DigitalOut Vparlante(PTC5); +PwmOut pw(PTA12); //ASIGNACION DE VARIABLES Timer t; int cero; @@ -26,7 +35,7 @@ int ind=0; //vector de caracteres. float err, med, yr, ap, ai, ad, err_v, cycle; //Variable de control PID float pid; - + //MATRIZ DEL TECLADO float Keytable[] = {1,2,3,11, 4,5,6,12, @@ -49,9 +58,11 @@ lcd.locate(3,0); lcd.printf(" "); lcd.locate(3,0); lcd.printf("%.0f",sp); - Vout=2.5; - wait(0.1); - Vout=0; + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + } else if(j==1){ if (q!=1 && kp<10){ @@ -64,9 +75,11 @@ if(kp>999)kp=999; lcd.locate(11,0); lcd.printf(" "); lcd.locate(11,0); lcd.printf("%.0f",kp); - Vout=2.5; - wait(0.1); - Vout=0; + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + } else if(j==2){ if (q!=1 && ki<10){ @@ -79,9 +92,11 @@ if(ki>999)ki=999; lcd.locate(3,1); lcd.printf(" "); lcd.locate(3,1); lcd.printf("%.0f",ki); - Vout=2.5; - wait(0.1); - Vout=0; + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + } else{ if (q!=1 && kd<10){ @@ -96,17 +111,19 @@ lcd.locate(11,1); lcd.printf("%.0f",kd); } ind=0; cero=0; - Vout=2.5; - wait(0.1); - Vout=0; + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + } - + uint32_t cbAfterInput(uint32_t index) { ind=Keytable[index]; cero=index; return 0; } - + void def_posicion(int j){ if (j==0){ lcd.locate(3,0); lcd.printf("%.0f",sp); @@ -125,7 +142,7 @@ lcd.locate(11,1); } } - + //Dado que hay parámetros que no varía en el display en esta parte del código, se crea una función que los mantenga. void star_patch1(void){ lcd.cls(); @@ -139,7 +156,7 @@ lcd.locate(0,0); lcd.printf("Sp=%.0f",sp); } - + void star_patch2(void){ // uso nuevamente función que imprime los caracteres que no van a variar en el display lcd.writeCommand(C2); lcd.cls(); @@ -152,7 +169,7 @@ lcd.locate(8,1); lcd.printf("Co=%.0f",pid); wait(3); } - + int main(){ ini: ind=0; @@ -166,38 +183,28 @@ def_posicion(k); ind=0; q=0; - Vout=2.5; - wait(0.1); - Vout=0; - wait(0.05); - Vout=2.5; - wait(0.1); - Vout=0; + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + } if(ind==13){ - Vout=2.5; - wait(0.07); - Vout=0; - wait(0.03); - Vout=2.5; - wait(0.07); - Vout=0; - wait(0.03); - Vout=2.5; - wait(0.07); - Vout=0; + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + ind=0; goto PID; } if(ind==11){ - Vout=2.5; - wait(0.01); - Vout=0; - wait(0.02); - Vout=3.3; - wait(0.3); - Vout=0; + pw.period(Tdo); + pw.pulsewidth(Pdo); + wait(0.1); + pw=0; + if (k==0){ sp=0; lcd.locate(3,0); lcd.printf(" "); @@ -277,4 +284,5 @@ err_v = err; if(ind==13)goto ini; } -} \ No newline at end of file +} + \ No newline at end of file