Miller villamar / Mbed 2 deprecated TUTORIA_MVILLAMAR

Dependencies:   mbed PID KeypadLib TextLCD

Files at this revision

API Documentation at this revision

Comitter:
mvillamar
Date:
Mon Feb 17 02:34:21 2020 +0000
Parent:
2:9fa12e9c368d
Commit message:
Lectura de temperatura mediante termistor NTC

Changed in this revision

PID.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9fa12e9c368d -r 977c21fea266 PID.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PID.lib	Mon Feb 17 02:34:21 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/aberk/code/PID/#6e12a3e5af19
diff -r 9fa12e9c368d -r 977c21fea266 main.cpp
--- a/main.cpp	Fri Feb 14 06:00:49 2020 +0000
+++ b/main.cpp	Mon Feb 17 02:34:21 2020 +0000
@@ -7,10 +7,15 @@
 #include "mbed.h"
 #include "keypad.h"                                 //se incluye libreria del teclado 4x4
 #include "TextLCD.h"                                //Libreria para el lcd
+#include <math.h>
+#include <iostream>
+#include <string>
+#include <sstream>
+
 ////////////////////////////////////////////////////////////////////////////////
 
 //////////TIMERS////////////////////////////////////////////////////////////////
-Ticker tempo1;                                       //Tiempo para lectura de tecla
+Ticker tempo1;                                       //Tiempo para lectura del termistor
 Timer Rele;
 
 //////////CONFIGURACION PUERTO SERIE///////////////////////////////////////////
@@ -22,18 +27,18 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 /////////CONFIGRACION PUERTO ANALOGICO//////////////////////////////////////////
-AnalogIn ain(PC_1);                                 // pin para lectura del termistor
-float vm=0.0;                                    //variable con dato analogo proveniente del divisor
+AnalogIn ain(PC_5);                                 // pin para lectura del termistor
+float vm=0;                                    //variable con dato analogo proveniente del divisor
+
 ////////////////////////////////////////////////////////////////////////////////
 
 /////////Datos de fabrica del termistor////////////////////////////////////////
-float Raux=10000.0;                                     // Resisrencia auxiliar para el divisor de voltaje
-float vcc=5.0;                                          // voltaje del divisor de tension
-float Beta=3977.0;                                      //constante ntc OBTENIDO de la hoj de datos
-float temp0 = 298.0;
-//float T0=25.0;                                          //tempertura referencia
-float r0 = 10000.0;                                       //resistencia a la temperatura referencia
-float Rntc=0.0;
+float Raux=100000.0;                                     // Resisrencia auxiliar para el divisor de voltaje
+float vcc=3.34;                                          // voltaje del divisor de tension
+float temp0 = 298.0;                                    //temperatua 24C en grados kelvin
+float r0 = 100000.0;                                    //resistencia a los 24C
+float Beta=3950.0;                                      //constante ntc OBTENIDO de la hoj de datos
+float Rntc=0;
 float tempC=0.0;
 float temperaturaK = 0.0;
 ////////////////////////////////////////////////////////////////////////////////
@@ -42,43 +47,55 @@
 char key;                                                 //variable para almacenar la tecla pulsada
 //  c0   c1    c2    c3   r0   r1    r2    r3
 //define pines para el teclado
+//  c0   c1   c2   c3  r0   r1   r2   r3
+Keypad keypad(PD_7,PC_8,PD_6,PB_0,PC_9,PA_8,PC_6,PC_7 );
+
 /////////////////////////////////////////////////
 
-int x=0;
-DigitalOut RLY(PB_3);
+char setpoint;
+
+int numero;
+int unidad;
+int decena;
+int centena;
+int total; //valor de setpoint para pid
+int i=0;
+
+
+DigitalOut RLY(PB_1);       //Rele de estado solido para activar el cautin.
+DigitalOut Bled(PD_15);    //LED AZUL
+DigitalOut Rled(PD_14);    //LED ROJO
+
 ///////////DECLARACION DE FUNCIONES////////////////////////////////////////////
 void TermistorRead();
 void lcd_16x2();
-void teclado(void);
+void asiganacion();
 void Calentador();
+void menu();
 
 
 int main()
 {
-    Rele.start(); //da inicio al temportizador RELE. 
+    keypad.enablePullUp();
+    //Rele.start(); //da inicio al TIMER RELE.
     tempo1.attach(&TermistorRead, 1.5); //caca 1.5 seg se ejecuta la lectura del termistor
     while(1) {
-        if (Rele.read_ms()>=1000) { // read time in ms
-            Calentador(); // call tarea function
-            Rele.reset(); // reset timer
+        //if (Rele.read_ms()>=1000) { // read time in ms
+        //   Calentador(); // call tarea function
+        //   Rele.reset(); // reset timer
+        //}
+        //teclado();
+        key = keypad.getKey();
+        if(key != KEY_RELEASED) {
+            wait(0.6);
         }
-        //lcd.locate(1,0);
-        //lcd.printf("%c",key);
-        // hercules.printf("%c",key);
-        //lcd.locate(0,1);
-        teclado();
+        if (key=='A') {
+            menu();
+        }
         lcd_16x2();
-        //TermistorRead();
-        //hercules.printf("%f\n\r",vm);
-        //hercules.printf("%f\n\r",Rntc);
-        hercules.printf("%c",key);
-        //lcd.printf("Valor: %3.3f%\n",termistor);                        //presentacion de datos
-        x+=1;
-        if (x==1000) {
-            x=0;
-        }
+        menu();
         RLY =! RLY;
-        wait(0.1);
+        wait(0.3);
     }//WHILE
 }//MAIN
 
@@ -87,42 +104,90 @@
 
 void TermistorRead()  //lectura de dato analogico proveniente del divisor de voltaje.
 {
-
-    //vm=(ain*3.3)/4096;
-    vm=(vcc/1024)*ain; //lectura puerto analogico
-    //vm= (ain*3.3)/4096;
-    Rntc= Raux/((vcc/vm)-1);
-    temperaturaK =Beta/(log(Rntc/r0)+(Beta/temp0));
-    tempC= temperaturaK - 273;
+    vm=ain;
+    vm*=3,3;
+    Rntc= ((Raux*vcc)/vm)-Raux; //despejando Rntc la formula del divisor.
+    temperaturaK =Beta/(log(Rntc/r0)+(Beta/temp0));     //formula para encontrar la temperatura
+    tempC= temperaturaK - 273;                          //convertir kelvin a C
+    Bled =! Bled;
 }
 
 void lcd_16x2()
 {
     lcd.cls();
-    lcd.printf("%d",x);
-    lcd.locate(0,1);
-    lcd.printf("%c",key);
-    lcd.locate(8,1);
-    lcd.printf("T:%3.2f",tempC);
+    lcd.locate(0,0);
+    lcd.printf("%.0f",tempC);                       // solo muestra la partedecimal
+}
+
+void menu()
+{
+    if (key=='A') {
+        for(i=0; i<3; i++) {
+            if (i==0) {
+                hercules.printf("ingrese SetPoint\r\n");
+                asiganacion();
+                unidad =numero*1;
+                hercules.printf("%d\r\n",unidad);
+            }
+
+            if (i==1) {
+                hercules.printf("ingrese 2da tecla\r\n");
+                asiganacion();
+                decena =numero*10;
+                hercules.printf("%d\r\n",decena);
+            }
+
+            if (i==2) {
+                hercules.printf("ingrese 3era tecla\r\n");
+                asiganacion();
+                centena =numero*100;
+                hercules.printf("%3d\r\n",centena);
+            }
+            if (key == 'B') {   //sale del ciclo si se pulsa B
+                hercules.printf("Exit");
+                main();
+            }
+        }
+        wait(0.1);
+        total=unidad+decena+centena;
+        hercules.printf("%d",total);
+    }
+}
+
+
+void asiganacion ()
+{
+
+    do {
+        key = keypad.getKey();
+        if(key != KEY_RELEASED) {
+            wait(0.6);
+        }
+    } while (key ==0x00);
+    
+    if(key == '0') numero=0;
+    if(key == '1') numero=1;
+    if(key == '2') numero=2;
+    if(key == '3') numero=3;
+    if(key == '4') numero=4;
+    if(key == '5') numero=5;
+    if(key == '6') numero=6;
+    if(key == '7') numero=7;
+    if(key == '8') numero=8;
+    if(key == '9') numero=9;
 
 }
 
-void teclado ()
+
+void Calentador()
 {
-    //  c0   c1   c2   c3  r0   r1   r2   r3
-    Keypad keypad(PD_7,PC_8,PD_6,PB_0,PC_9,PA_8,PC_6,PC_7 );
-    keypad.enablePullUp();
-    //while (1) {
-    key = keypad.getKey();
-    if(key != KEY_RELEASED) {
-        wait(0.6);
-   }
+    RLY = !RLY;
 }
 
-void Calentador(){
-    RLY = !RLY;
-    }
-
 
 
 
+
+
+
+