Grupo AAE / Mbed 2 deprecated P2_E4

Dependencies:   mbed

Committer:
elenaramirezperez1
Date:
Tue Oct 15 10:04:42 2019 +0000
Revision:
0:2b6bac81f08c
p2_e4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elenaramirezperez1 0:2b6bac81f08c 1 #include "mbed.h"
elenaramirezperez1 0:2b6bac81f08c 2 #include "datos.h"
elenaramirezperez1 0:2b6bac81f08c 3 #include "math.h"
elenaramirezperez1 0:2b6bac81f08c 4
elenaramirezperez1 0:2b6bac81f08c 5 Timer timer;
elenaramirezperez1 0:2b6bac81f08c 6 float resultado;
elenaramirezperez1 0:2b6bac81f08c 7 int tiempo;
elenaramirezperez1 0:2b6bac81f08c 8
elenaramirezperez1 0:2b6bac81f08c 9 float calcularRMS(int16_t *datos, int longitud);
elenaramirezperez1 0:2b6bac81f08c 10
elenaramirezperez1 0:2b6bac81f08c 11
elenaramirezperez1 0:2b6bac81f08c 12 int main()
elenaramirezperez1 0:2b6bac81f08c 13 {
elenaramirezperez1 0:2b6bac81f08c 14
elenaramirezperez1 0:2b6bac81f08c 15 timer.reset();
elenaramirezperez1 0:2b6bac81f08c 16 timer.start();
elenaramirezperez1 0:2b6bac81f08c 17 resultado=calcularRMS(datos, 500);
elenaramirezperez1 0:2b6bac81f08c 18 timer.stop();
elenaramirezperez1 0:2b6bac81f08c 19 printf("****El valor Vrms es %f calculado en %d us ****\n",resultado,timer.read_us());
elenaramirezperez1 0:2b6bac81f08c 20
elenaramirezperez1 0:2b6bac81f08c 21 }
elenaramirezperez1 0:2b6bac81f08c 22
elenaramirezperez1 0:2b6bac81f08c 23 float calcularRMS(int16_t *datos, int longitud)
elenaramirezperez1 0:2b6bac81f08c 24 {
elenaramirezperez1 0:2b6bac81f08c 25 int64_t sumatorio=0;
elenaramirezperez1 0:2b6bac81f08c 26 for (int i=0; i< longitud;i++)
elenaramirezperez1 0:2b6bac81f08c 27 {
elenaramirezperez1 0:2b6bac81f08c 28 sumatorio =+ datos[i]*datos[i];
elenaramirezperez1 0:2b6bac81f08c 29 }
elenaramirezperez1 0:2b6bac81f08c 30
elenaramirezperez1 0:2b6bac81f08c 31 float cte = 0.0001007080078125;
elenaramirezperez1 0:2b6bac81f08c 32 int resultado = cte * sqrt((float)sumatorio/longitud);
elenaramirezperez1 0:2b6bac81f08c 33 return resultado;
elenaramirezperez1 0:2b6bac81f08c 34 }
elenaramirezperez1 0:2b6bac81f08c 35