Dan Allen
/
MAX86150_ECG_PPG
MAX86150 code
Fork of MAX86150_ECG_PPG by
Diff: main.cpp
- Revision:
- 2:c8b7ef52c65c
- Parent:
- 1:f62247cbeac6
- Child:
- 3:a7df33374b48
--- a/main.cpp Wed Jan 04 17:00:53 2017 +0000 +++ b/main.cpp Wed Jan 04 23:14:42 2017 +0000 @@ -75,9 +75,12 @@ #define PartIDReg 0xFF #define maxi2cFreq 1000000 #define recommendedi2cFreq 400000 +#define interrupt_pin D12 //INTB pin --see InterruptIn declaration #define maxECGrate 0 #define normECGrate 1 -const int16_t i2cBufferSize=32; +#define BaudRate 921600 +//also try 921600, 460800 230400 +const int16_t i2cBufferSize=36; //32 was stable. In this rev exploring 36 //global variables @@ -85,6 +88,7 @@ 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 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 @@ -108,7 +112,7 @@ //NOT USER CONFIGURABLE****************** -#define interrupt_pin D12 //INTB pin --see InterruptIn declaration + const int16_t irChannel = ppgOn-1; //-1 or 0 const int16_t rChannel = ppgOn*(2)-1; //-1 or 1 const int16_t ecgChannel = ecgOn*(1+2*ppgOn)-1; //-1, 0, or 2 @@ -135,7 +139,7 @@ //setup I2C, serial connection and timer InterruptIn intPin(interrupt_pin); //config p5 as interrupt I2C i2c(I2C_SDA,I2C_SCL); -Serial pc(USBTX,USBRX,NULL,230400); //open serial port (optionally add device name and baud rate after specifying TX and RX pins) +Serial pc(USBTX,USBRX,NULL,BaudRate); //open serial port (optionally add device name and baud rate after specifying TX and RX pins) //declare subroutines @@ -218,7 +222,7 @@ writeRegister(MAX86150_Addr,SystemControlReg,0x01); //chip reset wait_ms(2); //wait for chip to come back on line //if PPG or ETI are not enabled, then FIFO is setup for ECG - writeRegister(MAX86150_Addr,FIFOConfigReg,0x1F); // [4] FIFO_ROLLS_ON_FULL, clears with status read or FIFO_data read + writeRegister(MAX86150_Addr,FIFOConfigReg,0x7F); // [4] FIFO_ROLLS_ON_FULL, clears with status read or FIFO_data read, asserts only once uint16_t FIFOCode; FIFOCode = etiOn ? 0x000A : 0x0000 ; //ETI is last in FIFO FIFOCode = ecgOn ? (FIFOCode<<4 | 0x0009) : FIFOCode; //insert ECG front of ETI in FIFO @@ -256,16 +260,16 @@ bool readFIFO(int numSamples, char *fifodata) { - char stat[1]; +// char stat[1]; bool dataValid = 0; - uint8_t tries = 0; - char newReadPointer; - clearInterrupts(stat); +// uint8_t tries = 0; +// char newReadPointer; +// clearInterrupts(stat); //get FIFO position readRegisters(MAX86150_Addr, FIFOReadPointerReg, i2cReadBuffer, 1); //you can do more sophisticated stuff looking for missed samples, but I'm keeping this lean and simple char readPointer = i2cReadBuffer[0]; - while(!dataValid) { - tries++; +// while(!dataValid) { +// tries++; //try reading FIFO readRegisters(MAX86150_Addr, FIFODataReg, fifodata, bytes2Read); //get data //see if it worked if you are not servicing interrupts faster than the sample rate @@ -283,7 +287,7 @@ // else { // wait_us(100); //try again a moment later // } - } +// } return dataValid; } //end readFIFO @@ -362,7 +366,7 @@ // regDump(MAX86150_Addr,0xD0, 0xD0); // writeRegister(MAX86150_Addr,0xFF,0x00); clearInterrupts(i2cReadBuffer); - i2c.frequency(maxi2cFreq); +// i2c.frequency(maxi2cFreq); //configure averaging if(ppgOn) { bits2Avg[rChannel]=ppgBits2Avg;