codigo sin probar

Dependencies:   mbed CMSIS_DSP_5 TextLCD

Files at this revision

API Documentation at this revision

Comitter:
MIGUI
Date:
Tue Dec 11 17:41:46 2018 +0000
Parent:
6:84f33f8a9c9d
Commit message:
PROGRAMA DE PRUEBA PARA EL PROYECTO DEL MASTER. SE PUEDEN INTRODUCIR LOS VALORES DE MUESTRO DE FORMA FICTICIA METIENDOLOS EN LOS FICHEROS DATOS DE MUESTRO.H

Changed in this revision

CMSIS_DSP_5.lib Show annotated file Show diff for this revision Revisions of this file
datos_muestreo_corriente.h Show annotated file Show diff for this revision Revisions of this file
datos_muestreo_voltaje.h 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CMSIS_DSP_5.lib	Tue Dec 11 17:41:46 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/xorjoep/code/CMSIS_DSP_5/#4098b9d3d571
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/datos_muestreo_corriente.h	Tue Dec 11 17:41:46 2018 +0000
@@ -0,0 +1,103 @@
+float muestreo_intensidad[100]=
+{
+0.483273811042197,
+0.559621156398964,
+0.640359072516493,
+0.725162456302525,
+0.813689834461378,
+0.905584738486394,
+1.00047714003280,
+1.09798494089124,
+1.19771551156244,
+1.29926727223759,
+1.40223130981850,
+1.50619302446636,
+1.61073379904892,
+1.71543268476395,
+1.81986809615149,
+1.92361950866972,
+2.02626915199883,
+2.12740369225470,
+2.22661589633851,
+2.32350627172076,
+2.41768467505663,
+2.50877188315557,
+2.59640111997923,
+2.68021953351910,
+2.75988961660707,
+2.83509056593758,
+2.90551957382939,
+2.97089304752519,
+3.03094775111959,
+3.08544186551713,
+3.13415596215250,
+3.17689388655187,
+3.21348354817778,
+3.24377761337696,
+3.26765409864095,
+3.28501686179064,
+3.29579598910692,
+3.29994807684850,
+3.29745640602350,
+3.28833100971093,
+3.27260863266096,
+3.25035258333688,
+3.22165247899417,
+3.18662388482350,
+3.14540784861047,
+3.09817033278597,
+3.04510154615404,
+2.98641517798814,
+2.92234753757989,
+2.85315660270494,
+2.77912098083753,
+2.70053878729650,
+2.61772644484014,
+2.53101740954343,
+2.44076082808809,
+2.34732013187215,
+2.25107157359996,
+2.15240271224535,
+2.05171085248843,
+1.94940144490988,
+1.84588645338455,
+1.74158269624835,
+1.63691016791790,
+1.53229034772127,
+1.42814450274947,
+1.32489199156259,
+1.22294857558084,
+1.12272474496009,
+1.02462406569286,
+0.929041554590557,
+0.836362088690123,
+0.746958855490101,
+0.661191850256278,
+0.579406426447797,
+0.501931905100679,
+0.429080248768242,
+0.361144805357996,
+0.298399126923164,
+0.241095868165106,
+0.189465769082013,
+0.143716725860371,
+0.104032953750393,
+0.0705742452962275,
+0.0434753269077748,
+0.0228453163649922,
+0.00876728343910127,
+0.00129791539994084,
+0.000467288756337059,
+0.00627874814861973,
+0.0187088928809347,
+0.0377076711475868,
+0.0631985815739966,
+0.0950789812607347,
+0.133220499090251,
+0.177469552632059,
+0.227647966564971,
+0.283553690126238,
+0.344961610698656,
+0.411624460259624,
+0.483273811042196
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/datos_muestreo_voltaje.h	Tue Dec 11 17:41:46 2018 +0000
@@ -0,0 +1,103 @@
+float muestreo_voltaje[100]=
+{
+1.65000000000000,
+1.75464946743333,
+1.85887754839669,
+1.96226455319468,
+2.06439417884878,
+2.16485518540250,
+2.26324305183954,
+2.35916160494713,
+2.45222461456577,
+2.54205734880174,
+2.62829808294016,
+2.71059955598279,
+2.78863036894548,
+2.86207631928493,
+2.93064166608140,
+2.99405032088305,
+3.05204695941670,
+3.10439804968851,
+3.15089279233496,
+3.19134396943743,
+3.22558869838272,
+3.25348908773384,
+3.27493279247014,
+3.28983346636107,
+3.29813110965196,
+3.29979231066189,
+3.29481038032070,
+3.28320537910354,
+3.26502403625438,
+3.24033956162390,
+3.20925135087920,
+3.17188458527256,
+3.12838972758070,
+3.07894191624432,
+3.02374026014737,
+2.96300703687587,
+2.89698679768453,
+2.82594538277512,
+2.75016885085188,
+2.66996232726400,
+2.58564877537357,
+2.49756769609612,
+2.40607376085023,
+2.31153538342091,
+2.21433323648735,
+2.11485871878836,
+2.01351237909779,
+1.91070230335603,
+1.80684247145190,
+1.70235109027181,
+1.59764890972819,
+1.49315752854810,
+1.38929769664397,
+1.28648762090221,
+1.18514128121164,
+1.08566676351265,
+0.988464616579088,
+0.893926239149774,
+0.802432303903879,
+0.714351224626429,
+0.630037672736002,
+0.549831149148119,
+0.474054617224877,
+0.403013202315474,
+0.336992963124127,
+0.276259739852627,
+0.221058083755676,
+0.171610272419296,
+0.128115414727441,
+0.0907486491207972,
+0.0596604383760957,
+0.0349759637456153,
+0.0167946208964609,
+0.00518961967929510,
+0.000207689338105999,
+0.00186889034803706,
+0.0101665336389307,
+0.0250672075298564,
+0.0465109122661558,
+0.0744113016172781,
+0.108656030562574,
+0.149107207665045,
+0.195601950311489,
+0.247953040583301,
+0.305949679116946,
+0.369358333918601,
+0.437923680715069,
+0.511369631054514,
+0.589400444017209,
+0.671701917059844,
+0.757942651198264,
+0.847775385434227,
+0.940838395052866,
+1.03675694816046,
+1.13514481459750,
+1.23560582115122,
+1.33773544680532,
+1.44112245160331,
+1.54535053256667,
+1.65000000000000
+};
\ No newline at end of file
--- a/main.cpp	Tue Dec 11 10:53:55 2018 +0000
+++ b/main.cpp	Tue Dec 11 17:41:46 2018 +0000
@@ -2,12 +2,15 @@
 #include "arm_math.h"
 #include "TextLCD.h"
 
+#include "datos_muestreo_corriente.h"
+#include "datos_muestreo_voltaje.h"
+
 Ticker timerCapturaMuestreo;
 Ticker timerMostrar;
 
 Serial pc(USBTX, USBRX); // tx, rx
 
-#define longitud 360
+#define longitud 100
 
 float Vrms;
 float Irms;
@@ -17,12 +20,12 @@
 float FDP;
 
 //BUFFERS DE VOLTAJE
-int16_t bufferA[longitud];
-int16_t bufferB[longitud];
+float bufferA[longitud];
+float bufferB[longitud];
 
 //BUFFERS DE INTENSIDAD
-int16_t bufferC [longitud];
-int16_t bufferD [longitud];
+float bufferC [longitud];
+float bufferD [longitud];
 
 //
 int contador=0 ;
@@ -36,14 +39,11 @@
 int16_t *pA ;
 int16_t *pB ;
 
-AnalogIn voltaje (A0); //ENTRADA DE VOLTAJE
-AnalogIn intensidad (A5); //ENTRADA DE INTENSIDAD
-
 void muestreo () //hay que programar que se ejecute la funcion cada X tiempo (siendo X el tiempo de muestreo)
 {
     if (nbuffer==1) { //si nbuffer=1 entonces se guardan los datos en el buffer A, else buffer B
-        bufferA[contador]=voltaje.read ()*197-325 ; //VOLTAJE
-        bufferC[contador]=intensidad.read ()*8-14 ;  //INTENSIDAD
+        bufferA[contador]=muestreo_voltaje [contador]*1.971327996035224e+02-3.252691193458119e+02 ; //VOLTAJE
+        bufferC[contador]=muestreo_intensidad [contador]*7.453035901834493-12.297509238026914 ;  //INTENSIDAD
         contador=contador+1 ;
         if (contador==longitud) {
             nbuffer=0 ;
@@ -51,8 +51,8 @@
             bufferlleno=1;
         }
     } else {
-        bufferB[contador]=voltaje.read ()*197-325 ; //VOLTAJE ;
-        bufferD[contador]=intensidad.read ()*8-14 ;  //INTENSIDAD ;
+        bufferB[contador]=muestreo_voltaje [contador]*1.971327996035224e+02-3.252691193458119e+02; //VOLTAJE ;
+        bufferD[contador]=muestreo_intensidad [contador]*7.453035901834493-12.297509238026914 ;  //INTENSIDAD ;
         contador=contador+1 ;
         if (contador==longitud) {
             nbuffer=1 ;
@@ -89,48 +89,30 @@
 
 void mostrar ()
 {
-    if (mostrarDato==1) {
-        pc.printf("voltaje:\n%f",Vrms);
-    } else if (mostrarDato==2) {
-        pc.printf("intensidad:\n%f",Irms);
-    } else if  (mostrarDato==3) {
-        pc.printf("potencia activa:\n%f",P);
-    } else if (mostrarDato==4) {
-        pc.printf("potencia reactiva:\n%f",Q);
-    } else if (mostrarDato==5) {
-        pc.printf("potencia aparente:\n%f",S);
-    } else if (mostrarDato==6) {
-        pc.printf("energia activa:\n%f",0);
-    } else if (mostrarDato==7) {
-        pc.printf("energia reactiva:\n%f",0);
-    } else if (mostrarDato==8) {
-        pc.printf("factor de potencia:\n%f",FDP);
-    }
 }
 
 
-float calcularRMS(int16_t *datos, int N); //definicion del tipo de variable que devuelve la funcion
-float calcularRMS(int16_t *datos, int N)   // definicion de los estamentos de la funcion
+float calcularRMS(float *datos, int N); //definicion del tipo de variable que devuelve la funcion
+float calcularRMS(float *datos, int N)   // definicion de los estamentos de la funcion
 {
-    float32_t k=5.035400390625000e-05;
-    int64_t producto=0;
-
-    for (int n=0; n<N; n++) {
+    float32_t producto=0;
+    
+    for (int n=0; n<longitud; n++) {
         producto+=datos[n]*datos[n];
     }
-    return sqrt((float(producto)/N))*k;
-
+    return sqrt((float(producto)/longitud));
+    
 }
 
-float calcular_potencia_activa(int16_t *datos1,int16_t *datos2, int N);
-float calcular_potencia_activa(int16_t *datos1,int16_t *datos2, int N)
+float calcular_potencia_activa(float *datos1,float *datos2, int N);
+float calcular_potencia_activa(float *datos1,float *datos2, int N)
 {
-    int32_t sumatorio=0;
+    float sumatorio=0;
     for (int16_t n=0; n<N; n++)
     {
-        sumatorio+=sumatorio+datos1[N]*datos2[N];
+        sumatorio+=datos1[n]*datos2[n];
     }
-    return datos1[N]*datos2[N]/N;
+    return sumatorio/N;
 }
     
 float calcular_potencia_reactiva_MAL(float Vrms,float Irms,float P,float S);
@@ -149,8 +131,8 @@
 }
     
     
-float calcular_potencia_reactiva(int16_t *datos1,int16_t *datos2, int N);
-float calcular_potencia_reactiva(int16_t *datos1,int16_t *datos2, int N)
+float calcular_potencia_reactiva(float *datos1,float *datos2, int N);
+float calcular_potencia_reactiva(float *datos1,float *datos2, int N)
 {
     return 0;
 }
@@ -170,27 +152,41 @@
     timerCapturaMuestreo.attach_us(&muestreo,200);
     timerMostrar.attach(&mostrar,1.0);
     while(1) {
+        wait (4);
         if (bufferlleno==1) {
             bufferlleno=0;
             if (nbuffer==0) 
             {
                 float Vrms=calcularRMS(bufferA,longitud);
+                pc.printf("voltaje:\n%f",Vrms,"\t //");
                 float Irms=calcularRMS(bufferC,longitud);
-                float P=calcular_potencia_activa(bufferA,bufferC,longitud);    
+                pc.printf("intensidad:\n%f",Irms,"\t //");
+                float P=calcular_potencia_activa(bufferA,bufferC,longitud);  
+                pc.printf("potencia activa:\n%f",P,"\t //");  
+                float S=calcular_potencia_aparente(Vrms,Irms);
+                pc.printf("potencia aparente:\n%f",S,"\t //");
+                float Q=calcular_potencia_reactiva_MAL(Vrms,Irms,P,S);
+                pc.printf("potencia reactiva:\n%f",Q,"\t //");
+                float FDP=fdp(S,P);
+                pc.printf("FDP:\n%f",FDP,"\t //");
             }
              
             else
-             
             {
                 float Vrms=calcularRMS(bufferB,longitud);
+                pc.printf("voltaje:\n%f",Vrms,"\t //");
                 float Irms=calcularRMS(bufferD,longitud);
+                pc.printf("intensidad:\n%f",Irms,"\t //");
                 float P=calcular_potencia_activa(bufferB,bufferD,longitud);
+                pc.printf("potencia activa:\n%f",P,"\t //");
+                float S=calcular_potencia_aparente(Vrms,Irms);
+                pc.printf("potencia aparente:\n%f",S,"\t //");
+                float Q=calcular_potencia_reactiva_MAL(Vrms,Irms,P,S);
+                pc.printf("potencia reactiva:\n%f",Q,"\t //");
+                float FDP=fdp(S,P);
+                pc.printf("FDP:\n%f",FDP,"\t //");
             }
-            
-            float S=calcular_potencia_aparente(Vrms,Irms);
-            float Q=calcular_potencia_reactiva_MAL(Vrms,Irms,P,S);
-            float FDP=fdp(S,P);
-        }
+            }        
     }
 }