This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AFE4403: How does the EVM's LED calibration code works?

Part Number: AFE4403

Hi, I'm looking at the AFE4403 EVM's source code (FW_SRCV2.3_Release).

/* Variables to modify depending on the application */
const unsigned char ILED1_CURR_MAX_mA = 45;     // LED1 max current reqd. for application
const unsigned char ILED1_CURR_MIN_mA = 5;      // LED1 min current reqd. for application
const unsigned char ILED2_CURR_MAX_mA = 45;     // LED2 max current reqd. for application
const unsigned char ILED2_CURR_MIN_mA = 5;      // LED2 min current reqd. for application
const unsigned char LOW_THR_PERCENT = 10;       // Low Threshold Percent
const unsigned char HIGH_THR_PERCENT = 90;      // High Threshold percent
const unsigned char HYS_PERCENT = 3;            // Hysteresis percent
const unsigned char TARGET_THR_PERCENT = 33;    // Target Threshold percent
/* End of Variables to modify depending on the application */
calibRoutineParams calibParams;


void AFE44xx_PowerOn_Init(void){
  Init_AFE44xx_DRDY_Interrupt();
  AFE44xx_Default_Reg_Init();
}

VOID main (VOID){ // code for MSP430F5529

  WDTCTL = WDTPW + WDTHOLD;
  AFE44xx_PowerOn_Init();
  // ...

  while (1){
    if (readDataFlag){
      readDataFlag = 0;
      AFE44xx_SPO2_Data_buf[0] = AFE44xx_Reg_Read(42);  //read RED Data
      AFE44xx_SPO2_Data_buf[1] = AFE44xx_Reg_Read(43);  //read Ambient data
      AFE44xx_SPO2_Data_buf[2] = AFE44xx_Reg_Read(44);  //read IR Data
      AFE44xx_SPO2_Data_buf[3] = AFE44xx_Reg_Read(45);  //read Ambient Data
      AFE44xx_SPO2_Data_buf[4] = AFE44xx_Reg_Read(46);  //read RED - Ambient Data
      AFE44xx_SPO2_Data_buf[5] = AFE44xx_Reg_Read(47);  //read IR - Ambient Data
      
      //P5OUT |= BIT0;                                    //Turn on LED P5.0 (Green)
      if (CALIBRATION_ENABLED == TRUE)
      {
        calibrationLED1(AFE44xx_SPO2_Data_buf[2]);
        calibrationLED2(AFE44xx_SPO2_Data_buf[0]);
      }
      // ...
          else if (wholeString[0] == CALIBRATION_CMD) // Calibration Code Command
          {
            if (wholeString[1] == CALIBRATION_TRUE)
            {
              CALIBRATION_ENABLED = TRUE;
              AFE44xx_Default_Reg_Init();
              calibParams.ILED1_CURR_MAX_mA = ILED1_CURR_MAX_mA;        // LED1 max current
              calibParams.ILED1_CURR_MIN_mA = ILED1_CURR_MIN_mA;        // LED1 min current
              calibParams.ILED2_CURR_MAX_mA = ILED2_CURR_MAX_mA;        // LED2 max current
              calibParams.ILED2_CURR_MIN_mA = ILED2_CURR_MIN_mA;        // LED2 min current
              calibParams.LOW_THR_PERCENT = LOW_THR_PERCENT;            // Low Threshold Percent
              calibParams.HIGH_THR_PERCENT = HIGH_THR_PERCENT;          // High Threshold percent
              calibParams.HYS_PERCENT = HYS_PERCENT;                    // Hysteresis percent
              calibParams.TARGET_THR_PERCENT = TARGET_THR_PERCENT;      // Target Threshold percent
              initCalibrationRoutine(&calibParams);
            }
            else if (wholeString[1] == CALIBRATION_FALSE)
            {
              CALIBRATION_ENABLED = FALSE;
            }
          }
      // ...
}

void calibrationLED1(unsigned long LED1data)
{
  // Variable declaration  
  static unsigned int LED1_waitTimeCount = 0;
  static unsigned int LED1_blockSizeCount = 0;
  static unsigned int LED1_freezeTimeCount = 0;
  static unsigned long LED1_Meas_DC = 0;
  static unsigned long LED1_Meas_DC_Est = 0;
  static unsigned long ILED1Code;
  unsigned long LED1InterimCode;
  
  // LED1 Calibration State machine
  switch (LED1CalibrationState){
  // ...
}

How does this LED calibration State machine work for LED1 (IR LED) and LED2 (Red LED)?

Also, does each calibration algorithm works the same? I was curious whether there are some common parts of the both "calibrationLED1" and "calibrationLED2" function.

Lastly, how did those min/max/threshold/hysteresis values calculated?