MAX32620HSP ECG with lead off detection

Dependencies:   mbed HSP_ECG MAX14720 USBDevice

Files at this revision

API Documentation at this revision

Comitter:
douqan93
Date:
Fri Mar 29 09:20:05 2019 +0000
Parent:
0:9ead5978d784
Commit message:
MAX32620HSP ECG with Lead off detection

Changed in this revision

HSP_ECG.lib 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
diff -r 9ead5978d784 -r 8b09f627a713 HSP_ECG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HSP_ECG.lib	Fri Mar 29 09:20:05 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/douqan93/code/HSP_ECG/#9ead5978d784
diff -r 9ead5978d784 -r 8b09f627a713 main.cpp
--- a/main.cpp	Thu Mar 28 08:10:23 2019 +0000
+++ b/main.cpp	Fri Mar 29 09:20:05 2019 +0000
@@ -4,7 +4,7 @@
  #include "MAX30101.h"
  #include "System.h"
  #include "USBSerial.h"
- 
+
  /************************************************************************************************************************************/
  /// define the HVOUT Boost Voltage default for the MAX14720 PMIC
  #define HVOUT_VOLTAGE 4500 // set to 4500 mV
@@ -40,7 +40,7 @@
  // Settings for Lead Detection
  #define En_dcloff  0x01
  #define Ipol       0x00
- #define Imag       0x00
+ #define Imag       0x01
  #define Vth        0x00
  
  // Settings for the HR initialization
@@ -76,9 +76,10 @@
  PwmOut pwmout(P1_7);
   
  // Data of sensors
- int32_t ECG_Raw;
+ int32_t ECG_Raw, RtoR_data;
+ uint32_t index = 0;
+ 
  //int32_t SpO_Raw;
- uint32_t index = 0;
  DigitalOut led(LED1); 
  
  //@brief Creates a packet that will be streamed via USB Serial
@@ -88,10 +89,9 @@
  //@param number Number of elements in the buffer
  //
  void StreamPacketUint32_ex(uint32_t id, uint32_t *buffer, uint32_t number) {
-    int k;
     if(id == MAX30001_DATA_ECG)
     {
-        for (k = 0; k < number; k++) 
+        for (int k = 0; k < number; k++) 
         {
             ECG_Raw = (int32_t)(buffer[k] << 8);
             ECG_Raw = ECG_Raw >> 14;
@@ -99,24 +99,20 @@
             usbSerial.printf("%d\r\n", ECG_Raw);
             index++;
         }
-    } 
- }
- /*void StreamPacketUint32_ex(uint32_t id, uint32_t *buffer, uint32_t number) {
-    int i;
-    if(id == MAX30101_OXIMETER_DATA + 2)
+    }
+    /*if(id == MAX30001_DATA_RTOR)
     {
-        for (i = 0; i < number; i++) 
-        {
-            SpO_Raw = (int32_t)(buffer[i]);
-        }
-        usbSerial.printf("%d\r\n", SpO_Raw);
-    } 
- }*/
- //******************************************************************************
- /*void MAX30101_OnInterrupt(void){
-    I2CM_Init_Reset(2, 1);
- }*/
- //*******************************************************************************
+           for(int i = 0; i < number; i++)
+           {
+               RtoR_data = (buffer[i]);
+               //usbSerial.printf("HR: %d\r\n", (60000/(RtoR_data << 3)));
+           }     
+    }*/
+    if(id == MAX30001_DATA_LEADOFF_DC)
+    {
+        usbSerial.printf("LOFF\r\n");
+    }
+ }
  int main() {
     // hold results for returning functions
     int result;
@@ -129,15 +125,6 @@
     max14720.boostEn = MAX14720::BOOST_ENABLED;
     max14720.boostSetVoltage(HVOUT_VOLTAGE);
     
-    
-    // This is the SpO2 mode (IR&Red LED)
-    /*max30101.SpO2mode_init(FIFO_WATERLEVEL_MARK, SAMPLE_AVG, SAMPLE_RATE,PULSE_WIDTH, RED_LED_CURRENT,IR_LED_CURRENT);
-        
-    // MAX30101 initialize interrupt  
-    max30101.onInterrupt(&MAX30101_OnInterrupt);
-    max30101.onDataAvailable(&StreamPacketUint32_ex);
-    max30101_Interrupt.fall(&MAX30101MidIntHandler);*/
-    
     // Interrupt priority    
     NVIC_SetPriority(GPIO_P0_IRQn, 5);
     NVIC_SetPriority(GPIO_P1_IRQn, 5);
@@ -162,7 +149,6 @@
     // Configuring the FCLK for the ECG, set to 32.768KHZ
     pwmout.period_us(31);
     pwmout.write(0.5);          // 0-1 is 0-100%, 0.5 = 50% duty cycle.
-    //max30001.max30001_RtoR_InitStart(En_rtor, Wndw, Gain1, Pavg, Ptsf, Hoff, Ravg, Rhsf, Clr_rrint);
     max30001.max30001_sw_rst(); // Do a software reset of the MAX30001
     max30001.max30001_INT_assignment(
         MAX30001::MAX30001_INT_B,  // en_enint_loc
@@ -190,23 +176,27 @@
         
     // MAX30001 initialize interrupt
     max30001.max30001_ECG_InitStart(En_ecg, Openp, Openn, Pol, Calp_sel, Caln_sel, E_fit, Rate, Gain, Dhpf, Dlpf);
-    //max30001.max30001_Enable_DcLeadOFF_Init(En_dcloff, Ipol, Imag, Vth);
+    //max30001.max30001_RtoR_InitStart(En_rtor, Wndw, Gain1, Pavg, Ptsf, Hoff, Ravg, Rhsf, Clr_rrint);
+    max30001.max30001_Enable_DcLeadOFF_Init(En_dcloff, Ipol, Imag, Vth);
     //max30001.max30001_FIFO_LeadONOff_Read();
     max30001.max30001_synch();
     max30001.onDataAvailable(&StreamPacketUint32_ex);
     int a;
     while (1) 
     {
+        
         a = usbSerial._getc();
         if (a == 65)
         {
             max30001.max30001_Stop_ECG();
+            max30001.max30001_Disable_DcLeadOFF();
             index = 0;
         }
         if (a == 97)
         {
             //max30001.max30001_sw_rst(); 
             max30001.max30001_ECG_InitStart(En_ecg, Openp, Openn, Pol, Calp_sel, Caln_sel, E_fit, Rate, Gain, Dhpf, Dlpf);
+            max30001.max30001_Enable_DcLeadOFF_Init(En_dcloff, Ipol, Imag, Vth);
             //max30001.max30001_synch();
             //max30001.onDataAvailable(&StreamPacketUint32_ex);            
         }