![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
tarea encoder , configuracion pid con el encoder
Dependencies: Debounced QEI TextLCD mbed
Fork of Tarea4_Encoder by
Diff: main.cpp
- Revision:
- 0:cdf4bcffb35a
- Child:
- 1:edbfc09232ed
diff -r 000000000000 -r cdf4bcffb35a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Apr 03 20:19:31 2014 +0000 @@ -0,0 +1,159 @@ +//Jesse Mauricio Beltran +//Michelle Maceas Henao + + +#include "mbed.h" +#include "DebouncedIn.h" +#include "TextLCD.h" +#include "QEI.h" + + +QEI wheel (PTA16, PTA17, NC, 48); +TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 + + +DebouncedIn Enco(PTC5); +DebouncedIn button1(PTC10); +DebouncedIn button2(PTC6); +DebouncedIn button3(PTC11); +PwmOut Pwm(PTA5); + + +float pp=0.001; +float Dd=0.1; +int SP1=0,Sp=0,Kp1=0,Kp=0,Ki=0,Ki1=0,Kd=0,Kd1=0,v,m; +int C1=0x0E; // solo muestra el curzor +int i; // indice de la variable + +int PWMmodule(float pp,float Dd) +{ + Pwm.period(pp); + Pwm.write(Dd); + wait(0.2); + Pwm.write(0); + return 0; +} + +int main() + +{ + lcd.writeCommand(0x0E); + lcd.printf("Sp=0 Kp=0"); + lcd.locate(0,1); + lcd.printf("Ki=0 Kd=0"); + lcd.locate(2,0); + lcd.printf("="); + + while(1) + { + m=wheel.getPulses(); + + if(m!=v) { + + switch(i) { + + case 0: + Kd1=Kd; + + lcd.locate(2,0); + lcd.printf("= "); + lcd.locate(3,0); + lcd.printf("%d",Sp); + //Sp=m; + Sp=SP1+m; + if(Sp<0) + { + Sp=0; + wheel.reset(); + m=0; + } + break; + case 1: + SP1=Sp; + lcd.locate(10,0); + lcd.printf("= "); + lcd.locate(11,0); + lcd.printf("%d",Kp); + //Kp=m; + Kp=Kp1+m; + if(Kp<0) + { + Kp=0; + wheel.reset(); + m=0; + } + break; + case 2: + Kp1=Kp; + lcd.locate(2,1); + lcd.printf("= "); + lcd.locate(3,1); + lcd.printf("%d",Ki); + //Ki=m; + Ki=Ki1+m; + if(Ki<0) + { + Ki=0; + wheel.reset(); + m=0; + } + + break; + case 3: + Ki1=Ki; + lcd.locate(10,1); + lcd.printf("= "); + lcd.locate(11,1); + lcd.printf("%d",Kd); + Kd=Kd1+m; + if(Kd<0) + { + Kd=0; + wheel.reset(); + m=0; + } + + break; + } + v=m; + } + + + if(button3.falling() || Enco.falling()) + { + PWMmodule(pp,Dd); + wait(0.2); + wheel.reset(); + i++; + if(i>3) + { + i=0; + } + switch (i) + { + case 0: + lcd.locate(2,0); + lcd.printf("="); + break; + case 1: + lcd.locate(10,0); + lcd.printf("="); + break; + case 2: + lcd.locate(2,1); + lcd.printf("="); + break; + case 3: + lcd.locate(10,1); + lcd.printf("="); + break; + + + } + } + /*if(button3.falling()) + { + PWMmodule(pp,Dd); + } */ + } +} \ No newline at end of file