david steven camargo
/
Motor_Encoder_DANIEL
ENCO
Revision 1:214e5fb18573, committed 2020-12-07
- Comitter:
- jota_ud
- Date:
- Mon Dec 07 15:49:55 2020 +0000
- Parent:
- 0:fb45c2082cb8
- Commit message:
- Programa para contar las revoluciones de un motor con RTOS
Changed in this revision
--- a/SLCD.lib Wed Jun 24 23:39:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
--- a/main.cpp Wed Jun 24 23:39:49 2020 +0000 +++ b/main.cpp Mon Dec 07 15:49:55 2020 +0000 @@ -1,19 +1,23 @@ #include "mbed.h" #include "rtos.h" -#include "ssd1306.h" -#include "SLCD.h" + -SLCD slcd; -SSD1306 lcd (D7,D6); + InterruptIn botoncito(PTC12); InterruptIn botoncito2(PTC3); InterruptIn botoncito3(D2); -PwmOut pwm1(D5); -PwmOut pwm2(D8); -DigitalOut mo(D9); -int contador=0,a=1,c=0,r,h,q; -bool s=0,k=0; +//DigitalOut myled(LED_RED); + + +PwmOut pwm1(PTD4); +PwmOut pwm2(PTA13); +DigitalOut myled(D9); + +int contador=0,a=1,c=0,r,h,q,nivel=0; +bool s=0,k=0,DC=0; + Serial pc(USBTX,USBRX); + Semaphore one_slot(1); Mutex mutex1; @@ -22,14 +26,15 @@ Thread thread1; Thread thread2; Thread thread3; -Thread thread4; -void herra() -{ +void herra(){ + one_slot.release(); one_slot.wait(); r=r+1; + + one_slot.release(); } @@ -39,7 +44,6 @@ one_slot.wait(); //one_slot.try_acquire(); s=!s; - mo=s; one_slot.release(); } void boton2() @@ -61,153 +65,147 @@ case 1: pwm2=0.3; q=30; - mo=s; + nivel=1; Thread::wait(2000); break; case 2: pwm2=0.5; q=50; - mo=s; + nivel=1; Thread::wait(2000); break; case 3: pwm2=0.7; q=70; - mo=s; + nivel=1; Thread::wait(2000); break; case 4: pwm2=1; q=100; - mo=s; + nivel=2; Thread::wait(6000); break; case 5: pwm2=0.7; q=70; - mo=s; + nivel=3; Thread::wait(2000); break; case 6: pwm2=0.5; q=50; - mo=s; + nivel=3; Thread::wait(2000); break; case 7: q=30; pwm2=0.3; - mo=s; + nivel=3; Thread::wait(2000); c=0; break; } - } + + }else{ + pwm2=0.0; + Thread::wait(1000); + } } } -void oled() -{ - while(1) { - + - if(k==0){ - lcd.init(); - lcd.speed (SSD1306::Fast); - lcd.cls(); - lcd.locate (1,0); - time_t seconds = time(NULL); - lcd.printf("Fecha= %s", ctime(&seconds)); - lcd.locate (4,1); - lcd.printf ("nivel: %d ",q); - lcd.locate (5,1); - lcd.printf ("rpm: %d ",h); - lcd.redraw(); - - }else if(k==1){ - lcd.init(); - lcd.speed (SSD1306::Fast); - lcd.cls(); - lcd.locate (2,1); - lcd.printf ("error"); - lcd.locate (5,0); - lcd.printf ("por favor revise el sistema"); - lcd.redraw(); - } - - Thread::wait(300); - } -} + void s7() { while(1) { - if(s==1 && r==0){ + if(s==1 && r==0) { k=1; + r=0; + DC=1; + myled=!myled; + Thread::wait(1000); + + } else if(s==1 && r>0){ + k=0; + h=r*60; + h=h/4; + //pc.printf("%d",h); + r=0; + DC=1; + myled=0; + Thread::wait(1000); - slcd.Home(); - slcd.putc('e'); - slcd.putc('r'); - r=0; - Thread::wait(1000); - slcd.clear(); + } else if(s==0){ + k=1; + DC=0; + myled=0; + } - }else{ - k=0; - slcd.Home(); - h=r*60; - h=h/4; - slcd.printf("%d",h); - r=0; - Thread::wait(1000); - slcd.clear(); - - } } } + void serial() { while(1) { - - one_slot.release(); - one_slot.wait(); - - time_t seconds = time(NULL); - - char buffer2[32]; - strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds)); - pc.printf("%s", buffer2); + + if(k==1) { + if(DC==0){ + pc.printf("Estado - Detenido - nivel:%d\n",q); + }else{ + if(nivel==1){ + pc.printf("Estado - acelerando\n\r Nivel:%d - rpm:Error - Revise el sistema\n",q,h); + + }else if(nivel==2){ + pc.printf("Estado - establecimiento\n\r Nivel:%d - rpm:Error - Revise el sistema\n",q,h); + + }else if(nivel==3){ + pc.printf("Estado - frenado\n\r Nivel:%d - rpm:Error - Revise el sistema\n",q,h); + } + + } + - char buffer1[32]; - strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds)); - pc.printf(" , %s", buffer1); - if(k==1) { - pc.printf(" , %d ciclo, %d rpm, error",q,h); - - } else { - pc.printf(" , %d ciclo, %d rpm, ok",q,h); + } else if(k==0){ + if(nivel==1){ + pc.printf("Estado - acelerando\n\r Nivel:%d - rpm:%d - ok\n",q,h); + + }else if(nivel==2){ + pc.printf("Estado - establecimiento\n\r Nivel:%d - rpm:%d - ok\n",q,h); + + }else if(nivel==3){ + pc.printf("Estado - frenado\n\r Nivel:%d - rpm:%d - ok\n",q,h); + + } + + } + + + + pc.printf("\n\r"); - Thread::wait(100); - one_slot.release(); + Thread::wait(200); } } int main() -{ - - set_time(1593041944); +{ botoncito.mode(PullUp); botoncito.fall(&boton1); + botoncito2.mode(PullUp); botoncito2.fall(&boton2); + botoncito3.mode(PullUp); botoncito3.fall(&herra); - - thread1.start(oled); - thread2.start(s7); - thread3.start(serial); - thread4.start((motor1)); - thread4.join(); + + + thread1.start(s7); + thread2.start(serial); + thread3.start((motor1)); + thread3.join(); } \ No newline at end of file
--- a/ssd1306_library.lib Wed Jun 24 23:39:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/rodriguj/code/ssd1306_library/#57209a7e9cba