ccvcv

Dependencies:   TextLCD mbed

Fork of PRACTICA3 by compartido

Revision:
2:0ef1b1712e64
Parent:
1:591fea5f363b
Child:
3:30f1e2f8308c
--- a/main.cpp	Fri Nov 10 08:48:12 2017 +0000
+++ b/main.cpp	Fri Nov 10 12:10:53 2017 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 // librería LCD
 
-#define vector 100
+#define vector 100      // valor para definir el tamaño de los búfferes de muestreo
 //TextLCD (6 puertos, TextLCD::LCD16x2); rs,e,d4-d7
 
 InterruptIn Sw (); //pulsador en el puerto
@@ -10,30 +10,34 @@
 Ticker visualizar;
 int contt=0;
 int contm=0;
+int contvpp=0;
 int dato=0,
-int bufferlleno=0;
-int flag;
-float buffer1 [vector];
-float buffer2 [vector];
-float Vrms;
-float suma;
-float muestra;
+int bufferlleno=0;      // variable de estado
+int flag1;              // variable para indicar cuando se tiene que cambiar de buffer
+int flag2;              // variable para indicar cuando se tiene que
+int flag3;              // variable para indicar cuando se tiene que calcular Vpp
+int Vpmax=0;
+int Vpmin=0;
+int Vpp=0;
+float buffer1 [vector]; // buffer de muestreo 1 de tamaño 100
+float buffer2 [vector]; // buffer de muestreo 2 de tamaño 100
+float Vrms;             // variabla para guardar el valor de RMS
+float suma;             // variable que es la suma de los valores de la muestra
+float muestra;          // variabla para hacer las operaciones
 
-void temporizador 
 
+void temporizador
 {
-    if (flag) 
-    {
-        
-        }
-        contt++;
-        if (contt==100)
-        {
-            contt =0;
-            flag =!flag;
-            bufferlleno=0;
-            }
+    if (flag2) {
+
     }
+    contt++;
+    if (contt==100) {
+        contt =0;
+        flag2 =!flag2;
+        bufferlleno=0;
+    }
+}
 
 void boton()
 {
@@ -56,11 +60,27 @@
     }
 }
 
+void calculovpp ()
+{
+    for(contvpp=0; contvpp=99; contvpp++)
+        if (muestra(contvpp)>Vpmax) {
+            Vpmax=muestra(contvpp);
+        } else {
+            if (muestra(contvpp)<Vpmin) {
+                Vpmin=muestra(contvpp);
+            } else {
+                if(!flag3) {
+                    Vpp = Vpmax-Vpmin;
+                    flag3=!flag3;
+                }
+            }
+        }
+
+}
+
+
 int main()
 {
-
-    contador = 0 ;
-
     muestreo.attach_us (&temporizador,200);
     visualizar.attach (&mostrar, 1);
     Sw.rise(&boton);
@@ -70,8 +90,9 @@
     while(1) {
         if (bufferlleno) {
             suma=0;
+            flag3=0;
             for (contm=0; contm<100: contm++) {
-                if (flag==1) {
+                if (flag1==1) {
                     muestra=buffer1[contm];
                 } else {
                     muestra=buffer2[contm];