Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CMSIS_DSP_5
Revision 9:18713ed17fc0, committed 2019-10-24
- Comitter:
- borjazuma
- Date:
- Thu Oct 24 15:42:06 2019 +0000
- Parent:
- 8:99642487de6f
- Commit message:
- PracticaVrms
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 99642487de6f -r 18713ed17fc0 main.cpp --- a/main.cpp Thu Oct 17 21:12:26 2019 +0000 +++ b/main.cpp Thu Oct 24 15:42:06 2019 +0000 @@ -7,15 +7,14 @@ float resultado; int tiempo; -struct estructuraMedidas -{ - float vrms; - float irms; - float potenciaActiva; - float potenciaReactiva; - float potenciaAparente; - float energiaConsumida; - float factorDePotencia; +struct estructuraMedidas { + float vrms; + float irms; + float potenciaActiva; + float potenciaReactiva; + float potenciaAparente; + float energiaConsumida; + float factorDePotencia; }; float calcularRMS(int16_t *datos, int longitud); @@ -25,16 +24,16 @@ int main() { - + timer.reset(); timer.start(); resultado=calcularRMS(datos, longitudTrama); timer.stop(); printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us()); - + estructuraMedidas medidas; medidas.energiaConsumida=0; - + timer.reset(); timer.start(); calcularDatos(datosV,datosI,longitudTrama,&medidas); @@ -52,11 +51,50 @@ float calcularRMS(int16_t *datos, int longitud) { - return 0.0; + int i=0; + int64_t acumulador=0; + float vrms; + + for (i=0; i<longitud; i++) + { + acumulador+=(datos[i]*datos[i]); + + } + + vrms=0.000100708*sqrt(((float)acumulador)/longitud); + + + + return vrms; + } + void calcularDatos(int16_t *datosV, int16_t *datosI, int longitud, estructuraMedidas *medidas) { + int i; + int64_t acumulador=0; + float vrms; + float potac; + float potap; + float facpot; + float potre; -} + for (i=0; i<longitud; i++) + { + acumulador+=(datosV[i]*datosI[i]); + } + potac=(0.00000001014*acumulador)/longitud; + vrms=0.000100708*sqrt(((float)acumulador)/longitud); + potap=vrms*vrms; + facpot=potac/potap; + potre=potap*(sin(facpot)); + medidas->potenciaActiva=potac; + medidas->vrms=vrms; + medidas->irms=vrms; + medidas->potenciaAparente=potap; + medidas->factorDePotencia=facpot; + medidas->potenciaReactiva=potre; + +}