holi

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
carmenron
Date:
Tue Nov 27 09:32:17 2018 +0000
Commit message:
proyecto

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 27 09:32:17 2018 +0000
@@ -0,0 +1,108 @@
+#include "mbed.h"
+#include "math.h"
+#define constanteTension 1.4709e-06
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+#define muestras 100
+
+//datos para la simulación
+uint16_t SimulaADCTension[muestras]={60202,60330,58625,59923,58998,57466,57255,57119,57170,56327,53777,54359,53219,51091,50453,47815,46978,46509,44763,43549,41361,38513,38484,36990,34806,33279,31567,29193,28053,25447,24892,21968,20909,18951,17602,17651,16065,14052,14118,11186,10956, 9896, 9801, 9096, 7219, 7250, 6692, 6723, 6585, 6516, 5513, 6368, 6477, 5763, 6043, 7267, 8753, 8192, 9443, 9583,11577,11624,13236,14810,16455,17921,18496,19134,20656,22417,25159,25612,28368,28898,31937,32470,33848,35633,38022,39382,40758,43294,44352,45782,47961,48101,50367,51624,52074,53559,53615,54518,56322,57580,58557,57530,58872,59042,58397,59201};
+uint16_t SimulaADCIntensidad[muestras]={50233,51231,50075,49752,48077,47954,47431,47039,45074,43363,42265,42317,41528,40167,38300,38291,36222,35848,32856,31874,31756,30792,29301,27121,25643,25859,24596,22473,21324,20488,20525,19587,18219,17412,16095,16230,15805,14552,14084,13718,13018,13552,13830,13742,13402,12494,13483,12590,12865,13365,13717,15102,14670,16809,17329,18512,18492,19710,21125,21425,21959,24420,23675,25403,27867,27863,28974,29835,32658,32356,33992,36355,36794,38237,39365,40761,40570,42662,42741,45341,45347,47276,46952,48428,49884,48802,49433,49915,51705,51945,51311,52919,52741,51751,51769,51843,53002,51405,51402,51047};
+//datos para la simulación
+uint16_t SimulaADCMedio[muestras]={33393,33574,32027,33589,33031,31969,32328,32861,33677,33691,32088,33703,33676,32739,33364,32057,32613,33594,33348,33681,33077,31846,33461,33630,33123,33280,33251,32554,33077,32115,33177,31838,32325,31867,31968,33410,33155,32405,33662,31843,32646,32533,33295,33354,32146,32748,32660,33059,33184,33274,32323,33125,33076,32098,32011,32765,33681,32451,32937,32220,33267,32282,32780,33163,33544,33680,32862,32050,32072,32286,33445,32280,33392,32259,33620,32470,32165,32274,32998,32715,32473,33425,32937,32867,33597,32343,33279,33272,32531,32903,31926,31882,32829,33322,33630,32033,32905,32707,31799,32445};
+
+int16_t  vTensionA[muestras];
+int16_t  vTensionB[muestras];
+
+int16_t  vIntensidadA[muestras];
+int16_t  vIntensidadB[muestras];
+
+float rms;
+
+
+int contador=0;
+
+//Para la simulacion
+uint16_t adcTension()
+{
+    return SimulaADCTension[contador];
+}
+
+uint16_t adcIntensidad()
+{
+    return SimulaADCIntensidad[contador];
+}
+
+//Para la simulacion
+uint16_t adcMedio()
+{
+    return SimulaADCMedio[contador];
+}
+
+
+void visualizacion()
+{
+    printf("RMS: %3.4f\n\r", rms);
+}
+
+int16_t medidaTension;
+int16_t medidaIntensidad;
+int16_t medidaOffset;
+int16_t medidaTensionSinOffset;
+int16_t medidaIntensidadSinOffset;
+int bufferActivo=0;
+int flag=0;
+int eBoton=0;
+
+void captura()
+{
+    medidaTension=(int16_t)(adcTension()^0x8000);
+    medidaIntensidad=(int16_t)(adcIntensidad()^0x8000);
+    medidaOffset=(int16_t)(adcMedio()^0x8000);
+    medidaTensionSinOffset=medidaTension-medidaOffset;
+    medidaIntensidadSinOffset=medidaIntensidad-medidaOffset;
+
+    if(bufferActivo) {
+        vTensionA[contador] = medidaTensionSinOffset;
+        vIntensidadA[contador] = medidaIntensidadSinOffset;
+    } else {
+        vTensionB[contador] = medidaTensionSinOffset;
+        vIntensidadB[contador] = medidaIntensidadSinOffset;
+    }
+    contador++;
+    if(contador==muestras) {
+        contador=0;
+        bufferActivo=!bufferActivo;
+        flag=1;
+    }
+}
+
+int main()
+{
+
+    Ticker timerCaptura;
+    Ticker timerVisualizacion;
+    timerCaptura.attach_us(&captura,200);
+    timerVisualizacion.attach(&visualizacion,1.0);
+    while(1) {
+        if(flag) {
+            flag=0;
+            int16_t meas;
+            int32_t producto;
+            int64_t sumatorio=0;
+
+            for (int b=0; b<muestras; b++) {
+                if (!bufferActivo) {
+                    meas=vTensionA[b];
+                } else {
+                    meas=vTensionB[b];
+                }
+                producto=meas*meas;
+                sumatorio+=producto;
+
+            }
+            rms=sqrt((float)constanteTension*(float(sumatorio)));
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 27 09:32:17 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file