el encoder al presionarlo pita y ademas es incremental y decremental
Dependencies: Debounced QEI TextLCD mbed
Revision 0:41a3a16a7de0, committed 2014-04-09
- Comitter:
- mescobart22
- Date:
- Wed Apr 09 15:32:24 2014 +0000
- Commit message:
- funcion encoder con pitido
Changed in this revision
diff -r 000000000000 -r 41a3a16a7de0 Debounced.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Debounced.lib Wed Apr 09 15:32:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/WarwickRacing/code/Debounced/#8992c13bbb9b
diff -r 000000000000 -r 41a3a16a7de0 QEI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QEI.lib Wed Apr 09 15:32:24 2014 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 41a3a16a7de0 TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Wed Apr 09 15:32:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/amarincan/code/TextLCD/#d692719a4c59
diff -r 000000000000 -r 41a3a16a7de0 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Apr 09 15:32:24 2014 +0000 @@ -0,0 +1,153 @@ +#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 Encoder_bu(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; +int r; // 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(r) { + + case 0: + Kd1=Kd; + + lcd.locate(2,0); + lcd.printf("= "); + lcd.locate(3,0); + lcd.printf("%d",Sp); + + 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=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=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() || Encoder_bu.falling()) + { + PWMmodule(pp,Dd); + wait(0.2); + wheel.reset(); + r++; + if(r>3) + { + r=0; + } + switch (r) + { + 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; + + + } + } + { + } + } +} \ No newline at end of file
diff -r 000000000000 -r 41a3a16a7de0 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Apr 09 15:32:24 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e \ No newline at end of file