Version Final

Dependencies:   mbed DS1820

Revision:
7:a16d4e848e5e
Parent:
6:75b0f24dad9b
Child:
8:53555acc118b
--- a/main.cpp	Wed Jun 05 01:42:32 2019 +0000
+++ b/main.cpp	Wed Jun 05 02:02:58 2019 +0000
@@ -254,20 +254,22 @@
             if((lectura == 1) && (lecant == 0)) {
                 estado = RISING_P;
             }
-            tp = 0;
+            tp = 0;//Reinicio el acumulador de tiempo
             break;
         case RISING_P:
+            /*Devuelvo el estado uno , una unica vez (Saco el rebote)*/
             estado = RETENCION_P;
             tp = 0;
-            return 1;
+            return 1;   //Devuelvo el estado alto ya que tuve un flanco
         case RETENCION_P:
+            /*Durante un segundo y siempre que la lectura siga siendo alta retengo*/
             if((tp >= 2) && (lectura == 0)) {
                 estado = INICIO_P;
             }
             break;
     }
-    lecant = lectura;
-    return 0;
+    lecant = lectura;   //Asigno el estado previo para el proximo ciclo..
+    return 0;           //Devuelvo el estado nulo o cero 
 }
 
 //Funcion relacionada al timmer , es llamada cada 0.5 segundos
@@ -289,7 +291,9 @@
 //Funcion dedicada a controlar el pulsador y analizar los cambios de modo..
 void CambioDeModo()
 {
+    /*Si tengo un flanco ascendente en el pulsador (Apretaron)*/
     if(antirrebote(P)) {
+        /*Switcheo entre MODO = 1 y MODO = 2 (LazoAbierto | LazoCerrado)*/
         Modo ++;
         if(Modo > 2) {
             Modo = 1;
@@ -298,13 +302,18 @@
     }
 }
 
+/*///////////////////////////////////////////////////////////////////////////ETAPAS DE MEDICION DE VELOCIDAD///////////////////////////////////////////////////////////////////////////*/
+
 /*
 UN PERIODO ==> RISE - FALL - RISE
 2 PERIODOS ==> Una vuelta 
 60 seg ==> 1 minuto / tiempo que tardo en dar una vuelta ==> RPM
 */
 
-//Inicio la medicion del tiempo de On del pulso
+/*LA MAQUINA DE ESTADOS SE SUBDIVIDE EN TRES FUNCIONES (2 INTERRUPCIONES + 1 FUNCION EN LA MAQUINA PRINCIPAL)*/
+
+//Interrupcion relacionada al Rising..
+
 void R_ton()
 {
     switch(EMV) {
@@ -331,6 +340,8 @@
     }
 }
 
+//Interrupcion relacionada a el falling..
+
 void F_ton()
 {
     if(em) {
@@ -349,6 +360,28 @@
 
 }
 
+//Estado final de la maquina de estados
+//Aqui genero la cuenta de donde obtengo las RPM y espero el tiempo prudencial..
+
+void medicion_velocidad(void)
+{
+    if(EMV == ESPERA_V) {
+        if(tv >= 1) {
+            RPM = 60.00 / (ap.read() * 2);
+            printf("Velocidad maxima = %f RPM\r\n",RPM);
+            VMAX = RPM;
+            tv = 0;
+            EMV = INCIO_V;
+            Modo = LazoAbierto;
+            printf("Modo Lazo Abierto...!\r\n");
+        }
+    }
+}
+
+/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
+
+
+
 void cambio_duty_pwm(float nuevoDuty)
 {
     static float ND = 0;
@@ -387,14 +420,14 @@
             break;
         case CAMBIO_MAYOR:
             Cooler.write(ND);
-            printf("\tNuevo Duty = %f%\r\n", ND* 100);
+            printf("\tNuevo Duty = %f%\r\n", floor(ND* 100.0f));
             DAN = ND;
             tcd = 0;
             ECM = ESPERA_FINAL;
             break;
         case INICIO_CAMBIO_MENOR:
             cantv = abs( (int(DAN*100)) - (int(ND*100)));
-            printf("\tVoy a hacer %.0f pasos intermedios desde %.0f para llegar a %.0f%\r\n", cantv, DAN*100, ND * 100);
+            //printf("\tVoy a hacer %.0f pasos intermedios desde %.0f para llegar a %.0f%\r\n", cantv, DAN*100, ND * 100);
             ECM = CAMBIO_MENOR;
             jv = 0;
             D = DAN;
@@ -402,7 +435,7 @@
         case CAMBIO_MENOR:
             if(cantv >= jv) {
                 Cooler.write(D);
-                printf("\t\tEtapa intermedia en %.0f%\r\n", D * 100.00f);
+                //printf("\t\tEtapa intermedia en %.0f%\r\n", D * 100.00f);
                 /*Si quiero alcanzar un duty inferior*/
                 if(ND < DAN)
                     D -= 0.01f;                                             //Decremeto 1%
@@ -470,7 +503,7 @@
             if(EMV == ESPERA_V) {
                 if(tv >= 1) {
                     RPM = 60.00 / (ap.read() * 2);
-                    printf("Velocidad = %f RPM\r\n",RPM);
+                    //printf("Velocidad = %f RPM\r\n",RPM);
                     tv = 0;
                     EMV = INCIO_V;
 
@@ -530,6 +563,7 @@
             break;
 
         case ESPERA_ENTRE_MODIFICACIONES:
+            /*Si se cumplio el tiempo..*/
             if(IM >= 1)
                 CPT = MEDICION_TEMPERATURA;
             break;
@@ -555,7 +589,7 @@
                 /*Apago el PWM*/
                 Cooler.write(0);
                 duty = 0;
-                printf("Cooler APAGADO!\r\n");
+                //printf("Cooler APAGADO!\r\n");
                 /*Voy al final de la maquina*/
                 ty = 0;                 //Reinicio el acumulador de tiempo final...
                 FTR = ESPERA_FINAL;
@@ -636,17 +670,3 @@
     }
 }
 
-void medicion_velocidad(void)
-{
-    if(EMV == ESPERA_V) {
-        if(tv >= 1) {
-            RPM = 60.00 / (ap.read() * 2);
-            printf("Velocidad maxima = %f RPM\r\n",RPM);
-            VMAX = RPM;
-            tv = 0;
-            EMV = INCIO_V;
-            Modo = LazoAbierto;
-            printf("Modo Lazo Abierto...!\r\n");
-        }
-    }
-}
\ No newline at end of file