MAX86150 code

Dependencies:   mbed

Fork of MAX86150_ECG_PPG by Bidet Remote

Revision:
4:3c728f3d1f10
Parent:
3:a7df33374b48
--- a/main.cpp	Wed Jan 04 23:16:05 2017 +0000
+++ b/main.cpp	Sat Jun 03 04:01:34 2017 +0000
@@ -78,7 +78,8 @@
 #define interrupt_pin D12 //INTB pin --see InterruptIn declaration
 #define maxECGrate 0
 #define normECGrate 1
-#define BaudRate 921600 
+//#define BaudRate 921600
+#define BaudRate 256000 
 //also try 921600, 460800 230400
 const int16_t i2cBufferSize=36; //32 was stable. In this rev exploring 36
 
@@ -87,11 +88,11 @@
 //USER SELECTABLE****************************
 const uint8_t ppgOn = 1; //turn on PPG (IR and Red both)
 const uint8_t ecgOn = 1; //turn on ECG measurement
-const uint8_t etiOn = 1; //turn on ETI (lead check) electrical tissue impedance. Checks if your fingers are on or not.
+const uint8_t etiOn = 0; //turn on ETI (lead check) electrical tissue impedance. Checks if your fingers are on or not.
 //const uint8_t ecgRate = maxECGrate; //use normECGrate 800Hz or maxECGrate 1600Hz
 const uint8_t ecgRate = maxECGrate; //use normECGrate 800Hz or maxECGrate 1600Hz
 const int16_t printEvery = 5 *(2-ecgRate); //print data only every X samples to reduce serial data BW (print fewer for faster sampling)
-const int16_t ppgBits2Avg = 0; //log(2) of IIR filter divisor, data = data + (new_data-data)>>bits2Avg for PPG IR and R, use 0 for no averaging
+const int16_t ppgBits2Avg = 4; //log(2) of IIR filter divisor, data = data + (new_data-data)>>bits2Avg for PPG IR and R, use 0 for no averaging
 const int16_t ecgBits2Avg = 3 + (1-ecgRate);; //(Recommend 3) log(2) of IIR filter divisor, data = data + (new_data-data)>>bits2Avg for ECG, use 0 for no averaging, or 4 with fast rate
 const int16_t etiBits2Avg = 0; //log(2) of IIR filter divisor, data = data + (new_data-data)>>bits2Avg for ETI, use 0 for no averaging
 const int16_t ppgBaselineBits = 9; //log(2) of baseline IIR filter divisor for PPG IR and PPG R, use 0 for no baseline removal
@@ -101,7 +102,8 @@
 const uint8_t irCurrent = 0x50; //PPG LED current (when enabled), max=0xFF (255) in increments of 0.2mA or 0.4mA if hi pwr is enabled.
 const uint8_t redHiPWR = 0; //0 = use normal pwr level (recommended for PPG). Note hi pwr is useful for proximity detection.
 const uint8_t irHiPWR = 0; //0 = use normal pwr level (recommended for PPG). Note hi pwr is useful for proximity detection.
-
+const uint8_t ppgAvg = 1; //1 = turn on ppg averaging on-chip
+const uint8_t ppgOnChipAvg =3; //average 2^n ppg samples on chip
 bool runSetup =1; //tells program to reprogram ASIC (used on startup)
 //***************************************
 
@@ -232,6 +234,7 @@
     writeRegister(MAX86150_Addr, ppgConfigReg0,0b11010111); //D3 for 100Hz, PPG_ADC_RGE: 32768nA, PPG_SR: 100SpS, PPG_LED_PW: 400uS
     writeRegister(MAX86150_Addr,LED1PulseAmpReg, ppgOn ? rCurrent : 0x00 );
     writeRegister(MAX86150_Addr,LED2PulseAmpReg, ppgOn ? irCurrent : 0x00);
+    writeRegister(MAX86150_Addr,pggConfigReg1, ppgAvg ? ppgOnChipAvg : 0x00);
     writeRegister(MAX86150_Addr,LEDRangeReg, irHiPWR * 2 + redHiPWR ); // PPG_ADC_RGE: 32768nA
     //ecg configuration
     if (ecgOn) {