3 channel_MUX

Dependencies:   BufferedSerial MAX30003 max32630fthr1 DS1307

Revision:
12:2f1730e0e638
Parent:
11:1d4ecbca034e
Child:
13:3a49fb19b94b
--- a/main.cpp	Mon May 03 19:03:21 2021 +0000
+++ b/main.cpp	Tue May 25 18:49:41 2021 +0000
@@ -5,7 +5,10 @@
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
  
 void ecg_config(MAX30003 &ecgAFE);
-DigitalOut led1(P3_0,LED_ON); 
+DigitalOut led1(P2_0,LED_ON); 
+
+
+
 /* ECG FIFO nearly full callback */
 volatile bool ecgFIFOIntFlag = 0; 
 void ecgFIFO_callback()  {
@@ -13,10 +16,21 @@
     ecgFIFOIntFlag = 1;
  
 }  
+Timer timer1;
+//void MUX()
+//{
+DigitalOut EN(P1_7);
+DigitalOut A0(P1_4);
+DigitalOut A1(P7_2);
+//}
+ bool mux1= false ;
+ bool mux2= false ;
+ bool mux3= false ;
+
  
 int main()
 {   
- 
+
     // Constants
     const int EINT_STATUS_MASK =  1 << 23;
     const int FIFO_OVF_MASK =  0x7;
@@ -24,11 +38,20 @@
     const int FIFO_FAST_SAMPLE_MASK =  0x1;
     const int ETAG_BITS_MASK = 0x7;
     
+    
+ 
+  //  EN=0; 
+  //  EN=1;
+  //  A0=0;
+   // A1=0;
+    
     // Ports and serial connections
-    Serial pc(P3_0,P3_1);            // Use USB debug probe for serial link
+    Serial pc(P0_0,P0_1);            // Use USB debug probe for serial link
     pc.baud(230400);                    // Baud rate = 115200
-    
-    DigitalOut bLed(LED3, LED_ON);      // Debug LEDs
+    DigitalOut bLed(LED3, LED_ON);
+    DigitalOut gLed(LED2, LED_ON);
+    DigitalOut rLed(LED1, LED_ON);
+         // Debug LEDs
     
     InterruptIn ecgFIFO_int(P5_4);          // Config P5_4 as int. in for the
     ecgFIFO_int.fall(&ecgFIFO_callback);    // ecg FIFO almost full interrupt
@@ -47,12 +70,44 @@
     
     uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
     int16_t ecgSample[32];
-    
+    int x=0;
     while(1) {
        
-        
+   while (x<100 && mux1==false)   
+       {
+        // if (0<x<=1000 && mux1==false)
+      // { 
+       
+       EN = 0; 
+       EN = 1;
+       A0 = 0;
+       A1 = 0;
+       mux1= true ;
+       }
+     while (101<x<=200 && mux2==false)
+       { 
+       gLed = 1 ;
+       EN = 0;
+       EN = 1;
+       A0 = 1;
+       A1 = 0;
+         mux2=true ;
+       }
+       
+   while (201<x<=300 && mux3==false)
+       {
+     rLed = 1 ;  
+       EN = 0 ;      
+       EN = 1;
+       A0 = 0;
+       A1 = 1;
+       mux3=true;
+       } 
+         
+            
         // Read back ECG samples from the FIFO 
         if( ecgFIFOIntFlag ) {
+            timer1.start();
             
             ecgFIFOIntFlag = 0; 
             status = ecgAFE.readRegister( MAX30003::STATUS );      // Read the STATUS register
@@ -83,11 +138,20 @@
                     pc.printf("%6d\r\n", ecgSample[idx]);           
                   //   pc.printf("Hello\n");    
                 } 
-                bLed = ! bLed;
-                               
-            }
+             //   bLed = ! bLed;
+             //   gLed = ! gLed;
+             //   rLed = ! rLed;
+                
+             
+                     x++;   
+                      if (x>300) 
+                      
+                      {x=0;}     
+            }           
         }
-    }
+        
+        
+   }
 }