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.

AFE4490SPO2EVM: AFE4490 and ADC RDY interrupt firing

Part Number: AFE4490SPO2EVM
Other Parts Discussed in Thread: AFE4490, AFE4404

Hi,

I interfaced AFE4490 SPO2 EVM with K53 MCU from NXP. I can read and write registers via SPI without issues. But when I try to use ADC_RDY interrupt to read register values, value remains the same. As in RED led ADC value stays at x0003000 and IR also stays at some fixed value. But without ADC_interrupt  AFE4490 gives out ppg signal. 

It would be great if anyone can point out why this is happening?

Is it okay to drive LEDs at a current greater than 25mA as my application is not power constrained?

  • Hi Annamol,

    Are you reading the output at rising edge of ADC_RDY? Can you please share the analog screenshot of the SPI signals and ADC_RDY while reading the output?
    Also to narrow down the root cause can you please try the register settings as mentioned in the datasheet ( i.e. Table 2).
    You can drive the LEDs with current > 25mA, given that they can withstand such current. You should also look for the LED linearity at such currents.

    Regards,
    Prabin
  • Hi,

    Sorry I was reading at the falling edge. I will correct it..
  • Hi,

    I have a small doubt in AFE4490 configuration. I want to sample at 950Hz (PRF) so in GUI i changed PRF to 950 and 25% duty cycle. From low level configuration tab, i took the register values and wrote onto AFE4490. Still samples comes around 600sps/620sps. When PRF is set from 100Hz to 500Hz I am able to see variations, but above 500Hz no change. Any idea on why this will happen? This is the configuration I am using. I can see ADC_RDY pulses and even interrupt gets triggered on ADC_RDY lines.

    // FOR 950Hz 25% duty cycle
    disable_afe4490_spi_read(afe4490); // Enable modification of AFE4490 registers
    afe4490_register_write(LED2STC, 0x000CA4,afe4490); //LED2STC
    afe4490_register_write(LED2ENDC, 0x00106E,afe4490); //LED2ENDC
    afe4490_register_write(LED2LEDSTC, 0x000C54,afe4490); //LED1LEDSTC
    afe4490_register_write(LED2LEDENDC,0x00106F,afe4490); //LED1LEDENDC
    afe4490_register_write(ALED2STC, 0x000050,afe4490); //ALED2STC
    afe4490_register_write(ALED2ENDC, 0x00041A,afe4490); //ALED2ENDC
    afe4490_register_write(LED1STC, 0x00046C,afe4490); //LED1STC
    afe4490_register_write(LED1ENDC, 0x000836,afe4490); //LED1ENDC
    afe4490_register_write(LED1LEDSTC, 0x00041C,afe4490); //LED2LEDSTC
    afe4490_register_write(LED1LEDENDC, 0x000837,afe4490); //LED2LEDENDC
    afe4490_register_write(ALED1STC, 0x000888,afe4490); //ALED1STC
    afe4490_register_write(ALED1ENDC, 0x000C52,afe4490); //ALED1ENDC
    afe4490_register_write(LED2CONVST, 0x000006,afe4490); //LED2CONVST
    afe4490_register_write(LED2CONVEND, 0x00041B,afe4490); //LED2CONVEND
    afe4490_register_write(ALED2CONVST, 0x000422,afe4490); //ALED2CONVST
    afe4490_register_write(ALED2CONVEND, 0x000837,afe4490); //ALED2CONVEND
    afe4490_register_write(LED1CONVST, 0x00083E,afe4490); //LED1CONVST
    afe4490_register_write(LED1CONVEND, 0x000C53,afe4490); //LED1CONVEND
    afe4490_register_write(ALED1CONVST, 0x000C5A,afe4490); //ALED1CONVST
    afe4490_register_write(ALED1CONVEND, 0x00106F,afe4490); //ALED1CONVEND
    afe4490_register_write(ADCRSTSTCT0, 0x000000,afe4490); //ADCRSTSTCT0
    afe4490_register_write(ADCRSTENDCT0,0x000005,afe4490); //ADCRSTENDCT0
    afe4490_register_write(ADCRSTSTCT1, 0x00041C,afe4490); //ADCRSTSTCT1
    afe4490_register_write(ADCRSTENDCT1, 0x000421,afe4490); //ADCRSTENDCT1
    afe4490_register_write(ADCRSTSTCT2, 0x000838,afe4490); //ADCRSTSTCT2
    afe4490_register_write(ADCRSTENDCT2, 0x00083D,afe4490); //ADCRSTENDCT2
    afe4490_register_write(ADCRSTSTCT3, 0x000C54,afe4490); //ADCRSTSTCT3
    afe4490_register_write(ADCRSTENDCT3, 0x000C59,afe4490); //ADCRSTENDCT3
    afe4490_register_write(PRPCT, 0x001072,afe4490); //PRPCT 0x009C3F 0x00115B
    afe4490_register_write(CONTROL1, 0x000101,afe4490); //CONTROL1
    afe4490_register_write(TIA_GAIN, 0x000000,afe4490); //TIA_GAIN
    afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490); //TIA_AMB_GAIN
    afe4490_register_write(LEDCTRL, 0x014401,afe4490); //LEDCTRL
    afe4490_register_write(CONTROL2, 0x000000,afe4490); //CONTROL2 0x124218
    enable_afe4490_spi_read(afe4490); // Enable modification of AFE4490 registers

    At times, while reading ADC values from 22-2Eh, say with LED current set as 0mA, I get 16777215 which is (2^24) -1, Is this ok??
  • Hi Annamol,

    Can you try following settings and observe the ADC_RDY.

    afe4490_register_write(CONTROL0, 0x000002,afe4490);
    afe4490_register_write((PRPCT, 0x001072,afe4490);
    afe4490_register_write(CONTROL0, 0x000000,afe4490);
    afe4490_register_write(CONTROL1, 0x000010,afe4490);

    Value of 16777215 for LED current of 0mA seems to be low, however does it change with increase in LED current?

    Regards,
    Prabin
  • Hi,

    I added these configurations alone, but no ADC_RDY signal gets fired. The value increases with LED current.
  • HI Annamol,

    Sorry, there was a typo in the last register setting.
    It should have been,
    afe4490_register_write(CONTROL1, 0x000100,afe4490);

    Can you check now?

    Regards,
    Prabin

  • Hi,
    It generates ADC_RDY every 1ms.
  • Hi,

    I generated register configurations again from GUI for 950Hz and 25% duty cycle. Still same state. When I acquire for 10 seconds, I am getting nearly around 5000 samples. In code, I have interrupt service routine which sets a flag and ADC reading happens in a while(1) loop. In AFE4404, same implementation I am getting around 950sps from configurations generated using GUI.

    I am attaching the full code also.Please let me know if I am doing something wrong. in GUI mode, it is giving 1000sps but not in my implementation with the same register setting.  

    I tried reading ADC values in ISR as well as in main task.

    afe4490.c
    /******************************************************************************
    * Project Name : Transmittance spo2 platform board
    * File Name    : afe4490.c
    * Written by   : Annamol
    * Date         : 13-12-2016
    * Description  : File contains all functions related with afe4490 hardware 
    *              : initialization for spo2 computation
    *******************************************************************************/
    #include "afe4490_evalkit.h"
    
    #define DELAY_COUNT 2
    
    LWGPIO_STRUCT afe4490_reset;                                                                // GPIO associated with AFE_RST line
    LWGPIO_STRUCT afe4490_adc_rdy;                                                              // GPIO associated with AFE_ADC_RDY line
    LWGPIO_STRUCT afe4490_powerdown;                                                            // GPIO associated with AFE4490_POWERDOWN line
    LWGPIO_STRUCT afe4490_pd_alm;                                                              // GPIO associated with AFE4490_PD_ALM line
    LWGPIO_STRUCT afe4490_led_alm;                                                             // GPIO associated with AFE4490_LED_ALM line
    MQX_FILE_PTR afe4490 = NULL;                                                            // MQX file pointer for AFE4404 to access via I2C
    int sample =0;                                                                          // Variable to indicate array index
    bool afe4490_data_ready_flag = FALSE;                                                   // Variable for AFE4404 data conversion status
    void afe4490_task(uint32_t);                                                       // AFE4490_task
    int count=0;
    
    #define AFE4490_TASK 5
    
    const TASK_TEMPLATE_STRUCT  MQX_template_list[] = 
    { 
        /* Task Index,   Function,   Stack,  Priority, Name,     Attributes,          Param, Time Slice */
        { AFE4490_TASK,   afe4490_task, 1500,   8,        "afe4490_task",  MQX_AUTO_START_TASK, 0,     0 },
        { 0 }
    };
    int afe4490_flag =0;
    signed long return_val;
    unsigned long LED1_ALED1value[4500];                                                 // Variable to hold ADC output of AFE4404
    unsigned long LED2_ALED2value[4500];
    /******************************************************************************
    * Function name : afe4490_gpio_configuration
    * Arguments     : null
    * Return type   : error_code
    * Invoked by    : afe4490_task
    * Description   : Function to 
    *
    *******************************************************************************/
    void afe4490_gpio_configuration()                                                                                                    
    {
      // Configure AFE4490reset line as GPIO
      if (!lwgpio_init(&afe4490_reset, AFE4490_RESETZ, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE))
        printf("Initializing AFE4404 reset as output failed.\n");  
      // switch pin functionality (MUX) to GPIO mode 
      lwgpio_set_functionality(&afe4490_reset, AFE4490_RESETZ_MUX_GPIO);
      // write logical 1 to the pin 
      lwgpio_set_value(&afe4490_reset, LWGPIO_VALUE_HIGH);    
      
    //  // Configure AFE4490 power down line as GPIO
    //  if (!lwgpio_init(&afe4490_powerdown, AFE4490_PWDNZ, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE))
    //    printf("Initializing AFE4404 reset as output failed.\n");  
    //  // switch pin functionality (MUX) to GPIO mode 
    //  lwgpio_set_functionality(&afe4490_powerdown, AFE4490_PWDNZ_MUX_GPIO);
    //  // write logical 1 to the pin 
    //  lwgpio_set_value(&afe4490_powerdown, LWGPIO_VALUE_HIGH);    
    //  
      // Enable interrupt on ADC_RDY line of AFE4404
    //  afe4490_adc_rdy_interrupt_enable();    
    //  // Enable interrupt on LED_ALM line of AFE4490
    //  afe4490_led_alarm_interrupt_enable();
    //  // Enable interrupt on PD_ALM line of AFE4490
    //  afe4490_pd_alarm_interrupt_enable();
    }
    
    /******************************************************************************
    * Function name : afe4490_adc_rdy_interrupt_enable
    * Arguments     : null
    * Return type   : void
    * Invoked by    : afe4490_gpio_configuration
    * Description   : Function to enable interrupt on ADC_RDY line mapped to PTC19
    *               : of AFE4404
    *******************************************************************************/
    void afe4490_adc_rdy_interrupt_enable()
    {
      // Set AFE4490_ADC_RDY  in GPIO mode with falling inetrrupt
      if (!lwgpio_init(&afe4490_adc_rdy, AFE4490_ADC_RDY, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE))
        printf("Initializing AFE4404 adc rdy as input failed.\n");
      else
      {
        // switch pin functionality (MUX) to GPIO mode 
        lwgpio_set_functionality(&afe4490_adc_rdy, AFE4490_ADC_RDY_MUX_GPIO);
        // Enable pull up ADC_RDY line
        lwgpio_set_attribute(&afe4490_adc_rdy, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE);
        // Enable falling interrupt on ADC_RDY line
        if (!lwgpio_int_init(&afe4490_adc_rdy, LWGPIO_INT_MODE_RISING))
        {
          printf("Initializing  GPIO for interrupt failed.\n");
        }
        
        // install interrupt service routine on ADC_RDY line
        _int_install_isr(lwgpio_int_get_vector(&afe4490_adc_rdy), afe4490_adc_ready_isr, (void *) &afe4490_adc_rdy);
        // set the interrupt level, and unmask the interrupt in interrupt controller 
        _bsp_int_init(lwgpio_int_get_vector(&afe4490_adc_rdy), 2, 0, TRUE);
    //      // enable interrupt on button 
    //      lwgpio_int_enable(&afe4490_adc_rdy, TRUE);
      }
    }
    
    ///******************************************************************************
    //* Function name : afe4490_led_alarm_interrupt_enable
    //* Arguments     : null
    //* Return type   : void
    //* Invoked by    : afe4490_gpio_configuration
    //* Description   : Function to enable interrupt on ADC_RDY line mapped to PTC19
    //*               : of AFE4404
    //*******************************************************************************/
    //void afe4490_led_alarm_interrupt_enable()
    //{
    //  // Set AFE4490_ADC_RDY  in GPIO mode with falling inetrrupt
    //  if (!lwgpio_init(&afe4490_led_alm, AFE4490_LED_ALM, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE))
    //    printf("Initializing afe4490_led_alm as input failed.\n");
    //  else
    //  {
    //    // switch pin functionality (MUX) to GPIO mode 
    //    lwgpio_set_functionality(&afe4490_led_alm, AFE4490_LED_ALM_MUX_GPIO);
    //    // Enable pull up ADC_RDY line
    //    lwgpio_set_attribute(&afe4490_led_alm, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);
    //    // Enable falling interrupt on ADC_RDY line
    //    if (!lwgpio_int_init(&afe4490_led_alm, LWGPIO_INT_MODE_FALLING))
    //    {
    //      printf("Initializing  GPIO for interrupt failed.\n");
    //    }
    //    
    //    // install interrupt service routine on ADC_RDY line
    //    _int_install_isr(lwgpio_int_get_vector(&afe4490_led_alm), afe4490_led_alarm_isr, (void *) &afe4490_led_alm);
    //    // set the interrupt level, and unmask the interrupt in interrupt controller 
    //    _bsp_int_init(lwgpio_int_get_vector(&afe4490_led_alm), 2, 0, TRUE);
    //    // enable interrupt on ADC_RDY line 
    //    lwgpio_int_enable(&afe4490_led_alm, TRUE);
    //  }
    //}
    //
    ///******************************************************************************
    //* Function name : afe4490_pd_alarm_interrupt_enable
    //* Arguments     : null
    //* Return type   : void
    //* Invoked by    : afe4490_gpio_configuration
    //* Description   : Function to enable interrupt on ADC_RDY line mapped to PTC19
    //*               : of AFE4404
    //*******************************************************************************/
    //void afe4490_pd_alarm_interrupt_enable()
    //{
    //  // Set AFE4490_ADC_RDY  in GPIO mode with falling inetrrupt
    //  if (!lwgpio_init(&afe4490_pd_alm, AFE4490_PD_ALM, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE))
    //    printf("Initializing AFE4404 adc rdy as input failed.\n");
    //  else
    //  {
    //    // switch pin functionality (MUX) to GPIO mode 
    //    lwgpio_set_functionality(&afe4490_pd_alm, AFE4490_PD_ALM_MUX_GPIO);
    //    // Enable pull up ADC_RDY line
    //    lwgpio_set_attribute(&afe4490_pd_alm, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);
    //    // Enable falling interrupt on ADC_RDY line
    //    if (!lwgpio_int_init(&afe4490_pd_alm, LWGPIO_INT_MODE_FALLING))
    //    {
    //      printf("Initializing  GPIO for interrupt failed.\n");
    //    }
    //    
    //    // install interrupt service routine on ADC_RDY line
    //    _int_install_isr(lwgpio_int_get_vector(&afe4490_pd_alm), afe4490_pd_alarm_isr, (void *) &afe4490_pd_alm);
    //    // set the interrupt level, and unmask the interrupt in interrupt controller 
    //    _bsp_int_init(lwgpio_int_get_vector(&afe4490_pd_alm), 2, 0, TRUE);
    //    // enable interrupt on ADC_RDY line 
    //    lwgpio_int_enable(&afe4490_pd_alm, TRUE);
    //  }
    //}
    
    /******************************************************************************
    * Function name : afe4490_register_write
    * Arguments     : unsigned char reg_address, unsigned long data,MQX_FILE_PTR fd
    * Return type   : void
    * Invoked by    : afe4490_register_configuration, afe4490_task
    * Description   : Function to write data via I2C lines of AFE4404
    *******************************************************************************/
    void afe4490_register_write (unsigned char reg_address, unsigned long data,MQX_FILE_PTR spifd)
    {
      // Local variable to hold values to be written onto adxl
      uint8_t configData[4];
      // Local variable to hold the number of bytes written
      _mqx_int result;    
      
      // Creating data packet for transfer with register address which needs to be updated as first argument, followed by 24 bit data value
      configData[0]=reg_address;
      configData[1]=(unsigned char)(data >>16);
      configData[2]=(unsigned char)(((data & 0x00FFFF) >>8));
      configData[3]=(unsigned char)(((data & 0x0000FF)));
     
      // Sending data via I2C
      if((result = fwrite(configData, 1, 4,spifd))!=0)
      {
        // Flush output
        fflush (spifd);
    //    _time_delay(5);
      }
      
    }
    
    /******************************************************************************
    * Function name : afe4490_register_read
    * Arguments     : unsigned char Reg_address,MQX_FILE_PTR fd,int n
    * Return type   : signed long
    * Invoked by    : afe4490_task
    * Description   : Function to read data from AFE4404 registers via I2C
    *******************************************************************************/
    signed long afe4490_register_read(unsigned char Reg_address,MQX_FILE_PTR fd,int n)
    {
      // Local variable to hold values to be written onto adxl
      uint8_t configData[1];
      uint8_t data[4];
      // Local variable to hold the number of bytes written
      _mqx_int result;
      signed long retVal;
      
      enable_afe4490_spi_read(afe4490);    
      // Creating data packet for transfer with register address which needs to be updated as first argument, followed by 24 bit data value
      configData[0]=Reg_address;
    //  configData[1]=0;
    //  configData[2]=0;
    //  configData[3]=0;
      
       // Write instruction and address 
      result = fwrite (configData, 1, 1, fd);
      // Read '1' byte of data from adxl 364
      // Register content is present in the variable 'data' and 'result' holds the
      // number of bytes read from adxl364. If successful read happens, result will
      // be '1' which indicates '1'byte of data.If failure, result will be '0'
      
      if((result = fread (&data, 1,3, fd)!=0)) 
      {
      // Deactivate CS 
      // Perform fflush on spi lines after every read/write operation to complete the cycle
      fflush (fd);
      
    //  _time_delay(5);
      }
      
    //  printf("%02x %02x %02x %02x \n",data[0],data[1],data[2],data[3]);
       // Creating 24 bit return value
      retVal = data[0];
      retVal = (retVal << 8) | data[1];
      retVal = (retVal << 8) | data[2];
    //  retVal = (retVal << 8) | data[3];
      return retVal;
    }
    
    
    /******************************************************************************
    * Function name : afe4490_register_configuration
    * Arguments     : void
    * Return type   : void
    * Invoked by    : afe4490_task
    * Description   : Function to configure all registers of AFE4404
    *******************************************************************************/
    void afe4490_register_configuration()
    {
      // Configuration from GUI for oscillator mode 500Hz PRF and 25%duty cycle with 20mA current on IR and RED
    //  disable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    //  afe4490_register_write(LED2STC, 0x0017C0,afe4490);         //LED2STC
    //  afe4490_register_write(LED2ENDC, 0x001F3E,afe4490);        //LED2ENDC
    //  afe4490_register_write(LED2LEDSTC, 0x001770,afe4490);     //LED1LEDSTC
    //  afe4490_register_write(LED2LEDENDC,0x001F3F,afe4490);     //LED1LEDENDC
    //  afe4490_register_write(ALED2STC, 0x000050,afe4490);       //ALED2STC
    //  afe4490_register_write(ALED2ENDC, 0x0007CE,afe4490);      //ALED2ENDC
    //  afe4490_register_write(LED1STC, 0x000820,afe4490);        //LED1STC
    //  afe4490_register_write(LED1ENDC, 0x000F9E,afe4490);       //LED1ENDC
    //  afe4490_register_write(LED1LEDSTC, 0x0007D0,afe4490);     //LED2LEDSTC
    //  afe4490_register_write(LED1LEDENDC, 0x000F9F,afe4490);    //LED2LEDENDC
    //  afe4490_register_write(ALED1STC, 0x000FF0,afe4490);       //ALED1STC
    //  afe4490_register_write(ALED1ENDC, 0x00176E,afe4490);     //ALED1ENDC
    //  afe4490_register_write(LED2CONVST, 0x000006,afe4490);    //LED2CONVST
    //  afe4490_register_write(LED2CONVEND, 0x0007CF,afe4490);   //LED2CONVEND
    //  afe4490_register_write(ALED2CONVST, 0x0007D6,afe4490);   //ALED2CONVST
    //  afe4490_register_write(ALED2CONVEND, 0x000F9F,afe4490);  //ALED2CONVEND
    //  afe4490_register_write(LED1CONVST, 0x000FA6,afe4490);    //LED1CONVST
    //  afe4490_register_write(LED1CONVEND, 0x00176F,afe4490);   //LED1CONVEND
    //  afe4490_register_write(ALED1CONVST, 0x001776,afe4490);   //ALED1CONVST
    //  afe4490_register_write(ALED1CONVEND, 0x001F3F,afe4490);  //ALED1CONVEND
    //  afe4490_register_write(ADCRSTSTCT0, 0x000000,afe4490);   //ADCRSTSTCT0
    //  afe4490_register_write(ADCRSTENDCT0,0x000005,afe4490);   //ADCRSTENDCT0
    //  afe4490_register_write(ADCRSTSTCT1, 0x0007D0,afe4490);   //ADCRSTSTCT1
    //  afe4490_register_write(ADCRSTENDCT1, 0x0007D5,afe4490);  //ADCRSTENDCT1
    //  afe4490_register_write(ADCRSTSTCT2, 0x000FA0,afe4490);   //ADCRSTSTCT2
    //  afe4490_register_write(ADCRSTENDCT2, 0x000FA5,afe4490);  //ADCRSTENDCT2
    //  afe4490_register_write(ADCRSTSTCT3, 0x001770,afe4490);   //ADCRSTSTCT3
    //  afe4490_register_write(ADCRSTENDCT3, 0x001775,afe4490);  //ADCRSTENDCT3
    //  afe4490_register_write(PRPCT, 0x001F3F,afe4490);         //PRPCT 0x009C3F  0x00115B
    //  afe4490_register_write(CONTROL1, 0x000101,afe4490);      //CONTROL1
    //  afe4490_register_write(TIA_GAIN, 0x000000,afe4490);      //TIA_GAIN
    //  afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490);  //TIA_AMB_GAIN
    //  afe4490_register_write(LEDCTRL, 0x011414,afe4490);       //LEDCTRL 0x014444 0x011414 0x010D0D
    //  afe4490_register_write(CONTROL2, 0x000000,afe4490);      //CONTROL2 0x124218
    //  enable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    
    //  //950hZ
    //  disable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    //  afe4490_register_write(LED2STC, 0x000CA4,afe4490);         //LED2STC
    //  afe4490_register_write(LED2ENDC, 0x00106E,afe4490);        //LED2ENDC
    //  afe4490_register_write(LED2LEDSTC, 0x000C54,afe4490);     //LED1LEDSTC
    //  afe4490_register_write(LED2LEDENDC,0x00106F,afe4490);     //LED1LEDENDC
    //  afe4490_register_write(ALED2STC, 0x000050,afe4490);       //ALED2STC
    //  afe4490_register_write(ALED2ENDC, 0x00041A,afe4490);      //ALED2ENDC
    //  afe4490_register_write(LED1STC, 0x00046C,afe4490);        //LED1STC
    //  afe4490_register_write(LED1ENDC, 0x000836,afe4490);       //LED1ENDC
    //  afe4490_register_write(LED1LEDSTC, 0x00041C,afe4490);     //LED2LEDSTC
    //  afe4490_register_write(LED1LEDENDC, 0x000837,afe4490);    //LED2LEDENDC
    //  afe4490_register_write(ALED1STC, 0x000888,afe4490);       //ALED1STC
    //  afe4490_register_write(ALED1ENDC, 0x000C52,afe4490);     //ALED1ENDC
    //  afe4490_register_write(LED2CONVST, 0x000006,afe4490);    //LED2CONVST
    //  afe4490_register_write(LED2CONVEND, 0x00041B,afe4490);   //LED2CONVEND
    //  afe4490_register_write(ALED2CONVST, 0x000422,afe4490);   //ALED2CONVST
    //  afe4490_register_write(ALED2CONVEND, 0x000837,afe4490);  //ALED2CONVEND
    //  afe4490_register_write(LED1CONVST, 0x00083E,afe4490);    //LED1CONVST
    //  afe4490_register_write(LED1CONVEND, 0x000C53,afe4490);   //LED1CONVEND
    //  afe4490_register_write(ALED1CONVST, 0x000C5A,afe4490);   //ALED1CONVST
    //  afe4490_register_write(ALED1CONVEND, 0x00106F,afe4490);  //ALED1CONVEND
    //  afe4490_register_write(ADCRSTSTCT0, 0x000000,afe4490);   //ADCRSTSTCT0
    //  afe4490_register_write(ADCRSTENDCT0,0x000005,afe4490);   //ADCRSTENDCT0
    //  afe4490_register_write(ADCRSTSTCT1, 0x00041C,afe4490);   //ADCRSTSTCT1
    //  afe4490_register_write(ADCRSTENDCT1, 0x000421,afe4490);  //ADCRSTENDCT1
    //  afe4490_register_write(ADCRSTSTCT2, 0x000838,afe4490);   //ADCRSTSTCT2
    //  afe4490_register_write(ADCRSTENDCT2, 0x00083D,afe4490);  //ADCRSTENDCT2
    //  afe4490_register_write(ADCRSTSTCT3, 0x000C54,afe4490);   //ADCRSTSTCT3
    //  afe4490_register_write(ADCRSTENDCT3, 0x000C59,afe4490);  //ADCRSTENDCT3
    //  afe4490_register_write(PRPCT, 0x001072,afe4490);         //PRPCT 0x009C3F  0x00115B
    //  afe4490_register_write(CONTROL1, 0x000103,afe4490);      //CONTROL1
    //  afe4490_register_write(TIA_GAIN, 0x000000,afe4490);      //TIA_GAIN
    //  afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490);  //TIA_AMB_GAIN
    //  afe4490_register_write(LEDCTRL, 0x011414,afe4490);       //LEDCTRL 0x014444 0x011414 0x010D0D
    //  afe4490_register_write(CONTROL2, 0x000000,afe4490);      //CONTROL2 0x124218
    //  enable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    //
    //  
    //   disable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    //  afe4490_register_write(LED2STC, 0x000D55,afe4490);         //LED2STC
    //  afe4490_register_write(LED2ENDC, 0x000DE1,afe4490);        //LED2ENDC
    //  afe4490_register_write(LED2LEDSTC, 0x000D05,afe4490);     //LED1LEDSTC
    //  afe4490_register_write(LED2LEDENDC,0x000DE2,afe4490);     //LED1LEDENDC
    //  afe4490_register_write(ALED2STC, 0x000050,afe4490);       //ALED2STC
    //  afe4490_register_write(ALED2ENDC, 0x0000DC,afe4490);      //ALED2ENDC
    //  afe4490_register_write(LED1STC, 0x0004A7,afe4490);        //LED1STC
    //  afe4490_register_write(LED1ENDC, 0x000533,afe4490);       //LED1ENDC
    //  afe4490_register_write(LED1LEDSTC, 0x000457,afe4490);     //LED2LEDSTC
    //  afe4490_register_write(LED1LEDENDC, 0x000534,afe4490);    //LED2LEDENDC
    //  afe4490_register_write(ALED1STC, 0x0008FE,afe4490);       //ALED1STC
    //  afe4490_register_write(ALED1ENDC, 0x00098A,afe4490);     //ALED1ENDC
    //  afe4490_register_write(LED2CONVST, 0x000006,afe4490);    //LED2CONVST
    //  afe4490_register_write(LED2CONVEND, 0x000456,afe4490);   //LED2CONVEND
    //  afe4490_register_write(ALED2CONVST, 0x00045D,afe4490);   //ALED2CONVST
    //  afe4490_register_write(ALED2CONVEND, 0x0008AD,afe4490);  //ALED2CONVEND
    //  afe4490_register_write(LED1CONVST, 0x0008B4,afe4490);    //LED1CONVST
    //  afe4490_register_write(LED1CONVEND, 0x000D04,afe4490);   //LED1CONVEND
    //  afe4490_register_write(ALED1CONVST, 0x000D0B,afe4490);   //ALED1CONVST
    //  afe4490_register_write(ALED1CONVEND, 0x00115B,afe4490);  //ALED1CONVEND
    //  afe4490_register_write(ADCRSTSTCT0, 0x000000,afe4490);   //ADCRSTSTCT0
    //  afe4490_register_write(ADCRSTENDCT0,0x000005,afe4490);   //ADCRSTENDCT0
    //  afe4490_register_write(ADCRSTSTCT1, 0x000457,afe4490);   //ADCRSTSTCT1
    //  afe4490_register_write(ADCRSTENDCT1, 0x00045C,afe4490);  //ADCRSTENDCT1
    //  afe4490_register_write(ADCRSTSTCT2, 0x0008AE,afe4490);   //ADCRSTSTCT2
    //  afe4490_register_write(ADCRSTENDCT2, 0x0008B3,afe4490);  //ADCRSTENDCT2
    //  afe4490_register_write(ADCRSTSTCT3, 0x000D05,afe4490);   //ADCRSTSTCT3
    //  afe4490_register_write(ADCRSTENDCT3, 0x000D0A,afe4490);  //ADCRSTENDCT3
    //  afe4490_register_write(PRPCT, 0x00115B,afe4490);         //PRPCT 0x009C3F  0x00115B
    //  afe4490_register_write(CONTROL1, 0x000101,afe4490);      //CONTROL1
    //  afe4490_register_write(TIA_GAIN, 0x000000,afe4490);      //TIA_GAIN
    //  afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490);  //TIA_AMB_GAIN
    //  afe4490_register_write(LEDCTRL, 0x011414,afe4490);       //LEDCTRL 0x014444 0x011414 0x010D0D
    //  afe4490_register_write(CONTROL2, 0x000000,afe4490);      //CONTROL2 0x124218
    //  enable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    
      // from 4404
    //   disable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    //  afe4490_register_write(LED2STC, 0x00002a,afe4490);         //LED2STC
    //  afe4490_register_write(LED2ENDC, 0x0000d1,afe4490);        //LED2ENDC
    //  afe4490_register_write(LED2LEDSTC, 0x000000,afe4490);     //LED1LEDSTC
    //  afe4490_register_write(LED2LEDENDC,0x0000d1,afe4490);     //LED1LEDENDC
    //  afe4490_register_write(ALED2STC, 0x0000fc,afe4490);       //ALED2STC
    //  afe4490_register_write(ALED2ENDC, 0x0001a3,afe4490);      //ALED2ENDC
    //  afe4490_register_write(LED1STC, 0x0001ce,afe4490);        //LED1STC
    //  afe4490_register_write(LED1ENDC, 0x000275,afe4490);       //LED1ENDC
    //  afe4490_register_write(LED1LEDSTC, 0x0001a4,afe4490);     //LED2LEDSTC
    //  afe4490_register_write(LED1LEDENDC, 0x000275,afe4490);    //LED2LEDENDC
    //  afe4490_register_write(ALED1STC, 0x00029f,afe4490);       //ALED1STC
    //  afe4490_register_write(ALED1ENDC, 0x000346,afe4490);     //ALED1ENDC
    //  afe4490_register_write(LED2CONVST, 0x0000da,afe4490);    //LED2CONVST
    //  afe4490_register_write(LED2CONVEND, 0x0004fd,afe4490);   //LED2CONVEND
    //  afe4490_register_write(ALED2CONVST, 0x000506,afe4490);   //ALED2CONVST
    //  afe4490_register_write(ALED2CONVEND, 0x000929,afe4490);  //ALED2CONVEND
    //  afe4490_register_write(LED1CONVST, 0x000932,afe4490);    //LED1CONVST
    //  afe4490_register_write(LED1CONVEND, 0x000d55,afe4490);   //LED1CONVEND
    //  afe4490_register_write(ALED1CONVST, 0x000D5e,afe4490);   //ALED1CONVST
    //  afe4490_register_write(ALED1CONVEND, 0x001181,afe4490);  //ALED1CONVEND
    //  afe4490_register_write(ADCRSTSTCT0, 0x0000d3,afe4490);   //ADCRSTSTCT0
    //  afe4490_register_write(ADCRSTENDCT0,0x0000d9,afe4490);   //ADCRSTENDCT0
    //  afe4490_register_write(ADCRSTSTCT1, 0x0004ff,afe4490);   //ADCRSTSTCT1
    //  afe4490_register_write(ADCRSTENDCT1, 0x000505,afe4490);  //ADCRSTENDCT1
    //  afe4490_register_write(ADCRSTSTCT2, 0x00092b,afe4490);   //ADCRSTSTCT2
    //  afe4490_register_write(ADCRSTENDCT2, 0x000931,afe4490);  //ADCRSTENDCT2
    //  afe4490_register_write(ADCRSTSTCT3, 0x000D57,afe4490);   //ADCRSTSTCT3
    //  afe4490_register_write(ADCRSTENDCT3, 0x000D5d,afe4490);  //ADCRSTENDCT3
    //  afe4490_register_write(PRPCT, 0x001072,afe4490);         //PRPCT 0x009C3F  0x00115B
    //  afe4490_register_write(CONTROL1, 0x000101,afe4490);      //CONTROL1
    //  afe4490_register_write(TIA_GAIN, 0x000000,afe4490);      //TIA_GAIN
    //  afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490);  //TIA_AMB_GAIN
    //  afe4490_register_write(LEDCTRL, 0x011414,afe4490);       //LEDCTRL 0x014444 0x011414 0x010D0D
    //  afe4490_register_write(CONTROL2, 0x000000,afe4490);      //CONTROL2 0x124218
    //  enable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    
    //100
    //  disable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    //  afe4490_register_write(LED2STC, 0x007580,afe4490);         //LED2STC
    //  afe4490_register_write(LED2ENDC, 0x009C3E,afe4490);        //LED2ENDC
    //  afe4490_register_write(LED2LEDSTC, 0x007530,afe4490);     //LED1LEDSTC
    //  afe4490_register_write(LED2LEDENDC,0x009C3F,afe4490);     //LED1LEDENDC
    //  afe4490_register_write(ALED2STC, 0x000050,afe4490);       //ALED2STC
    //  afe4490_register_write(ALED2ENDC, 0x00270E,afe4490);      //ALED2ENDC
    //  afe4490_register_write(LED1STC, 0x002760,afe4490);        //LED1STC
    //  afe4490_register_write(LED1ENDC, 0x004E1E,afe4490);       //LED1ENDC
    //  afe4490_register_write(LED1LEDSTC, 0x002710,afe4490);     //LED2LEDSTC
    //  afe4490_register_write(LED1LEDENDC, 0x004E1F,afe4490);    //LED2LEDENDC
    //  afe4490_register_write(ALED1STC, 0x004E70,afe4490);       //ALED1STC
    //  afe4490_register_write(ALED1ENDC, 0x00752E,afe4490);     //ALED1ENDC
    //  afe4490_register_write(LED2CONVST, 0x000006,afe4490);    //LED2CONVST
    //  afe4490_register_write(LED2CONVEND, 0x00270F,afe4490);   //LED2CONVEND
    //  afe4490_register_write(ALED2CONVST, 0x002716,afe4490);   //ALED2CONVST
    //  afe4490_register_write(ALED2CONVEND, 0x004E1F,afe4490);  //ALED2CONVEND
    //  afe4490_register_write(LED1CONVST, 0x004E26,afe4490);    //LED1CONVST
    //  afe4490_register_write(LED1CONVEND, 0x00752F,afe4490);   //LED1CONVEND
    //  afe4490_register_write(ALED1CONVST, 0x007536,afe4490);   //ALED1CONVST
    //  afe4490_register_write(ALED1CONVEND, 0x009C3F,afe4490);  //ALED1CONVEND
    //  afe4490_register_write(ADCRSTSTCT0, 0x000000,afe4490);   //ADCRSTSTCT0
    //  afe4490_register_write(ADCRSTENDCT0,0x000005,afe4490);   //ADCRSTENDCT0
    //  afe4490_register_write(ADCRSTSTCT1, 0x002710,afe4490);   //ADCRSTSTCT1
    //  afe4490_register_write(ADCRSTENDCT1, 0x002715,afe4490);  //ADCRSTENDCT1
    //  afe4490_register_write(ADCRSTSTCT2, 0x004E20,afe4490);   //ADCRSTSTCT2
    //  afe4490_register_write(ADCRSTENDCT2, 0x004E25,afe4490);  //ADCRSTENDCT2
    //  afe4490_register_write(ADCRSTSTCT3, 0x007530,afe4490);   //ADCRSTSTCT3
    //  afe4490_register_write(ADCRSTENDCT3, 0x007535,afe4490);  //ADCRSTENDCT3
    //  afe4490_register_write(PRPCT, 0x009C3F,afe4490);         //PRPCT 0x009C3F  0x00115B
    //  afe4490_register_write(CONTROL1, 0x000101,afe4490);      //CONTROL1
    //  afe4490_register_write(TIA_GAIN, 0x000000,afe4490);      //TIA_GAIN
    //  afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490);  //TIA_AMB_GAIN
    //  afe4490_register_write(LEDCTRL, 0x011414,afe4490);       //LEDCTRL 0x014444 0x011414 0x010D0D
    //  afe4490_register_write(CONTROL2, 0x000000,afe4490);      //CONTROL2 0x124218
    //  enable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers 
    //  
    //  //650 25% works around 610
      afe4490_register_write(CONTROL_REGISTER, 0x000002,afe4490);  //ADCRSTENDCT1
      afe4490_register_write(PRPCT, 0x001072,afe4490);   //ADCRSTSTCT2
      afe4490_register_write(CONTROL_REGISTER, 0x000000,afe4490);  //ADCRSTENDCT2
      afe4490_register_write(CONTROL1, 0x000100,afe4490);   //ADCRSTSTCT3
      
    //  950Hz 25%
    //  disable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
      afe4490_register_write(LED2STC, 0x000CA4,afe4490);         //LED2STC
      afe4490_register_write(LED2ENDC, 0x00106E,afe4490);        //LED2ENDC
      afe4490_register_write(LED2LEDSTC, 0x000C54,afe4490);     //LED1LEDSTC
      afe4490_register_write(LED2LEDENDC,0x00106F,afe4490);     //LED1LEDENDC
      afe4490_register_write(ALED2STC, 0x000050,afe4490);       //ALED2STC
      afe4490_register_write(ALED2ENDC, 0x00041A,afe4490);      //ALED2ENDC
      afe4490_register_write(LED1STC, 0x00046C,afe4490);        //LED1STC
      afe4490_register_write(LED1ENDC, 0x000836,afe4490);       //LED1ENDC
      afe4490_register_write(LED1LEDSTC, 0x00041C,afe4490);     //LED2LEDSTC
      afe4490_register_write(LED1LEDENDC, 0x000837,afe4490);    //LED2LEDENDC
      afe4490_register_write(ALED1STC, 0x000888,afe4490);       //ALED1STC
      afe4490_register_write(ALED1ENDC, 0x000C52,afe4490);     //ALED1ENDC
      afe4490_register_write(LED2CONVST, 0x000006,afe4490);    //LED2CONVST
      afe4490_register_write(LED2CONVEND, 0x00041B,afe4490);   //LED2CONVEND
      afe4490_register_write(ALED2CONVST, 0x000422,afe4490);   //ALED2CONVST
      afe4490_register_write(ALED2CONVEND, 0x000837,afe4490);  //ALED2CONVEND
      afe4490_register_write(LED1CONVST, 0x00083E,afe4490);    //LED1CONVST
      afe4490_register_write(LED1CONVEND, 0x000C53,afe4490);   //LED1CONVEND
      afe4490_register_write(ALED1CONVST, 0x000C5A,afe4490);   //ALED1CONVST
      afe4490_register_write(ALED1CONVEND, 0x00106F,afe4490);  //ALED1CONVEND
      afe4490_register_write(ADCRSTSTCT0, 0x000000,afe4490);   //ADCRSTSTCT0
      afe4490_register_write(ADCRSTENDCT0,0x000005,afe4490);   //ADCRSTENDCT0
      afe4490_register_write(ADCRSTSTCT1, 0x00041C,afe4490);   //ADCRSTSTCT1
      afe4490_register_write(ADCRSTENDCT1, 0x000421,afe4490);  //ADCRSTENDCT1
      afe4490_register_write(ADCRSTSTCT2, 0x000838,afe4490);   //ADCRSTSTCT2
      afe4490_register_write(ADCRSTENDCT2, 0x00083D,afe4490);  //ADCRSTENDCT2
      afe4490_register_write(ADCRSTSTCT3, 0x000C54,afe4490);   //ADCRSTSTCT3
      afe4490_register_write(ADCRSTENDCT3, 0x000C59,afe4490);  //ADCRSTENDCT3
      afe4490_register_write(PRPCT, 0x001072,afe4490);         //PRPCT 0x009C3F  0x00115B
      afe4490_register_write(CONTROL1, 0x000100,afe4490);      //CONTROL1
      afe4490_register_write(TIA_GAIN, 0x000000,afe4490);      //TIA_GAIN
      afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490);  //TIA_AMB_GAIN
      afe4490_register_write(LEDCTRL, 0x011414,afe4490);       //LEDCTRL 0x014444 0x011414 0x010D0D
      afe4490_register_write(CONTROL2, 0x000000,afe4490);      //CONTROL2 0x124218
      enable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers  
      
    //  //850 25%
    //    disable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers
    //  afe4490_register_write(LED2STC, 0x000E18,afe4490);         //LED2STC
    //  afe4490_register_write(LED2ENDC, 0x00125E,afe4490);        //LED2ENDC
    //  afe4490_register_write(LED2LEDSTC, 0x000DC8,afe4490);     //LED1LEDSTC
    //  afe4490_register_write(LED2LEDENDC,0x00125F,afe4490);     //LED1LEDENDC
    //  afe4490_register_write(ALED2STC, 0x000050,afe4490);       //ALED2STC
    //  afe4490_register_write(ALED2ENDC, 0x000496,afe4490);      //ALED2ENDC
    //  afe4490_register_write(LED1STC, 0x0004E8,afe4490);        //LED1STC
    //  afe4490_register_write(LED1ENDC, 0x00092E,afe4490);       //LED1ENDC
    //  afe4490_register_write(LED1LEDSTC, 0x000498,afe4490);     //LED2LEDSTC
    //  afe4490_register_write(LED1LEDENDC, 0x00092F,afe4490);    //LED2LEDENDC
    //  afe4490_register_write(ALED1STC, 0x000980,afe4490);       //ALED1STC
    //  afe4490_register_write(ALED1ENDC, 0x000DC6,afe4490);     //ALED1ENDC
    //  afe4490_register_write(LED2CONVST, 0x000006,afe4490);    //LED2CONVST
    //  afe4490_register_write(LED2CONVEND, 0x000497,afe4490);   //LED2CONVEND
    //  afe4490_register_write(ALED2CONVST, 0x00049E,afe4490);   //ALED2CONVST
    //  afe4490_register_write(ALED2CONVEND, 0x00092F,afe4490);  //ALED2CONVEND
    //  afe4490_register_write(LED1CONVST, 0x000936,afe4490);    //LED1CONVST
    //  afe4490_register_write(LED1CONVEND, 0x000DC7,afe4490);   //LED1CONVEND
    //  afe4490_register_write(ALED1CONVST, 0x000DCE,afe4490);   //ALED1CONVST
    //  afe4490_register_write(ALED1CONVEND, 0x00125F,afe4490);  //ALED1CONVEND
    //  afe4490_register_write(ADCRSTSTCT0, 0x000000,afe4490);   //ADCRSTSTCT0
    //  afe4490_register_write(ADCRSTENDCT0,0x000005,afe4490);   //ADCRSTENDCT0
    //  afe4490_register_write(ADCRSTSTCT1, 0x000498,afe4490);   //ADCRSTSTCT1
    //  afe4490_register_write(ADCRSTENDCT1, 0x00049D,afe4490);  //ADCRSTENDCT1
    //  afe4490_register_write(ADCRSTSTCT2, 0x000930,afe4490);   //ADCRSTSTCT2
    //  afe4490_register_write(ADCRSTENDCT2, 0x000935,afe4490);  //ADCRSTENDCT2
    //  afe4490_register_write(ADCRSTSTCT3, 0x000DC8,afe4490);   //ADCRSTSTCT3
    //  afe4490_register_write(ADCRSTENDCT3, 0x000DCD,afe4490);  //ADCRSTENDCT3
    //  afe4490_register_write(PRPCT, 0x001261,afe4490);         //PRPCT 0x009C3F  0x00115B
    //  afe4490_register_write(CONTROL1, 0x000101,afe4490);      //CONTROL1
    //  afe4490_register_write(TIA_GAIN, 0x000000,afe4490);      //TIA_GAIN
    //  afe4490_register_write(TIA_AMB_GAIN, 0x000000,afe4490);  //TIA_AMB_GAIN
    //  afe4490_register_write(LEDCTRL, 0x011414,afe4490);       //LEDCTRL 0x014444 0x011414 0x010D0D
    //  afe4490_register_write(CONTROL2, 0x000000,afe4490);      //CONTROL2 0x124218
    //  enable_afe4490_spi_read(afe4490);                                // Enable modification of AFE4490 registers  
    }
    
    /******************************************************************************
    * Function name : disable_afe4490_spi_read
    * Arguments     : MQX_FILE_PTR spifd
    * Return type   : void
    * Invoked by    : afe4490_register_configuration
    * Description   : Function to disable spi read bit in control register 0x00
    *******************************************************************************/
    void disable_afe4490_spi_read(MQX_FILE_PTR spifd)
    {
       // Local variable to hold values to be written onto adxl
      uint8_t buffer[4];
      // Local variable to hold the number of bytes written
      _mqx_int result;
      
      buffer[0] = 0x00;                                                              // Register address 
      buffer[1] = 0x00;                                                              // Value to be written
      buffer[2] = 0x00;                                                              // Value to be written
      buffer[3] = 0x00;                                                              // Value to be written
      
      // Write onto spi controller using fwrite() instruction
      if((result = fwrite (buffer, 1,sizeof(buffer), spifd))!=0)
      {
        // Deactivate CS after writing and perform fflush operation after every write
        fflush (spifd);
        // There is 5 ms internal write cycle needed for adxl 
    //    _time_delay (5);  
      }
    }
    
    /******************************************************************************
    * Function name : enable_afe4490_spi_read
    * Arguments     : MQX_FILE_PTR spifd
    * Return type   : void
    * Invoked by    :
    * Description   :
    *
    *******************************************************************************/
    void enable_afe4490_spi_read(MQX_FILE_PTR spifd)
    {
      // Local variable to hold values to be written onto adxl
      uint8_t buffer[4];
      // Local variable to hold the number of bytes written
      _mqx_int result;
      
      buffer[0] = 0x00;                                                              // Register address 
      buffer[1] = 0x00;                                                              // Value to be written
      buffer[2] = 0x00;                                                              // Value to be written
      buffer[3] = 0x01;                                                              // Value to be written
      
      // Write onto spi controller using fwrite() instruction
      if((result = fwrite (buffer, 1,sizeof(buffer), spifd))!=0)
      {
        // Deactivate CS after writing and perform fflush operation after every write
        fflush (spifd);
        // There is 5 ms internal write cycle needed for adxl 
    //    _time_delay (5);  
      }
      
    }
    
    /******************************************************************************
    * Task name     : afe4490_task
    * Task ID       : afe4490_TASK
    * Invoked by    : MQX_AUTO_START_TASK
    * Arguments     : uint32_t initial_data
    * Description   : Task which handles afe4490 related configuration
    *******************************************************************************/
    void afe4490_task(uint32_t initial_data)
    {
      int j,Init_i;
      if(afe4490 !=NULL)
      {
        fclose(afe4490);
    //    afe4490_hw_reset();
      }
      
     //  Open I2C1 lines for communicating with AFE4404
      if(afe4490 = fopen("spi1:",NULL))
      {
      // Configure spi lines for afe4490 configuration
        if(success == afe4490_spi_lines_configuration(afe4490))
        {
          // Configure GPIO lines used by afe4490
          afe4490_gpio_configuration();    
          
           // write logical 1 to the pin 
      lwgpio_set_value(&afe4490_reset, LWGPIO_VALUE_LOW);    
      
      // To generate 30us delay
      for(int i=0;i<9800;i++); 
      
      // write logical 1 to the pin 
      lwgpio_set_value(&afe4490_reset, LWGPIO_VALUE_HIGH); 
      
      // to generate 10ms delay
      for(int k=0;k<5;k++)
        for(int i=0;i<55000;i++);   
          
      
          for (j = 0; j < DELAY_COUNT; j++)
          {
            for ( Init_i =0; Init_i < 20000; Init_i++);
            for ( Init_i =0; Init_i < 20000; Init_i++);
            for ( Init_i =0; Init_i < 20000; Init_i++);
          }
     
          // Configure afe4490 registers 
          afe4490_register_configuration();
    //      
    //      afe4490_register_write(CONTROL_REGISTER, 0x000002,afe4490);  //ADCRSTENDCT1
    //  afe4490_register_write(PRPCT, 0x001072,afe4490);   //ADCRSTSTCT2
    //  afe4490_register_write(CONTROL_REGISTER, 0x000000,afe4490);  //ADCRSTENDCT2
    //  afe4490_register_write(CONTROL1, 0x000100,afe4490);   //ADCRSTSTCT3
          
           afe4490_adc_rdy_interrupt_enable();    
           
         // enable interrupt on ADC_RDY line 
        lwgpio_int_enable(&afe4490_adc_rdy, TRUE);
          
          memset(LED1_ALED1value,0x00,sizeof(LED1_ALED1value));
    //      
          while(1)
          {       
            if(afe4490_flag ==1)
            {
              LED1_ALED1value[0]= afe4490_register_read(LED1VAL,afe4490,3);
              LED2_ALED2value[0]= afe4490_register_read(LED2VAL,afe4490,3);
              printf("\n L1%lu L2%lu", LED1_ALED1value[0], LED2_ALED2value[0]);
    //           lwgpio_int_enable(&afe4490_adc_rdy, TRUE);
               afe4490_flag=0;
            }
          }
        }
        else
        {
          printf("\n afe4490 gpio configuration failed");
        }
      }
      else
      {
        printf("\n i2c lines afe4490 failed");
      }
    }
    
    
    error_code afe4490_spi_lines_configuration(MQX_FILE_PTR fd)
    {
      // Local variables to be used for spi master configuration
       uint32_t                param;                                                    // Local variable to hold parameters to be configured
       uint32_t                result;                                                  // Local variable to hold result
       SPI_STATISTICS_STRUCT  stats;                                                    // Local variable to hold statistics
       
      // Display baud rate 
      printf ("Current baud rate ... ");
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_GET_BAUD, &param))
        printf ("%d Hz\n", param);
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
      
      // Set a different baud rate 
      param = 500000;
      printf ("Changing the baud rate to %d Hz ... ", param);
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_SET_BAUD, &param))
        printf ("OK\n");
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
    #ifndef DEBUG_PRINTF
      // Display baud rate 
      printf ("Current baud rate ... ");
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_GET_BAUD, &param))
        printf ("%d Hz\n", param);
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
    #endif
      // Set clock mode 
      param = SPI_CLK_POL_PHA_MODE0;
      printf ("Setting clock mode to %s ... ", clock_mode[param]);
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_SET_MODE, &param))
        printf ("OK\n");  
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
    #ifndef DEBUG_PRINTF
      // Get clock mode 
      printf ("Getting clock mode ... ");
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_GET_MODE, &param))
        printf ("%s\n", clock_mode[param]);
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
    #endif
      // Set big endian 
      param = SPI_DEVICE_BIG_ENDIAN;
      printf ("Setting endian to %s ... ", param == SPI_DEVICE_BIG_ENDIAN ? "SPI_DEVICE_BIG_ENDIAN" : "SPI_DEVICE_LITTLE_ENDIAN");
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_SET_ENDIAN, &param))
        printf ("OK\n");
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
      
    #ifndef DEBUG_PRINTF
      // Get endian 
      printf ("Getting endian ... ");
      if (SPI_OK == ioctl (spifd, IO_IOCTL_SPI_GET_ENDIAN, &param))
        printf ("%s\n", param == SPI_DEVICE_BIG_ENDIAN ? "SPI_DEVICE_BIG_ENDIAN" : "SPI_DEVICE_LITTLE_ENDIAN");
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
    #endif
      // Set transfer mode 
      param = SPI_DEVICE_MASTER_MODE;
      printf ("Setting transfer mode to %s ... ", device_mode[param]);
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_SET_TRANSFER_MODE, &param))
        printf ("OK\n");
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
    #ifndef DEBUG_PRINTF
      // Get transfer mode 
      printf ("Getting transfer mode ... ");
      if (SPI_OK == ioctl (fd, IO_IOCTL_SPI_GET_TRANSFER_MODE, &param))
        printf ("%s\n", device_mode[param]);
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
    #endif
        
      // Clear statistics 
      printf ("Clearing statistics ... ");
      result = ioctl (fd, IO_IOCTL_SPI_CLEAR_STATS, NULL);
      if (SPI_OK == result)
        printf ("OK\n");
      else if (MQX_IO_OPERATION_NOT_AVAILABLE == result)
      {
        printf ("not available, define BSPCFG_ENABLE_SPI_STATS\n");
      }
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
      // Get statistics 
      printf ("Getting statistics: ");
      result = ioctl (fd, IO_IOCTL_SPI_GET_STATS, &stats);
      if (SPI_OK == result)
      {
        printf ("\n");
        printf ("Rx packets:   %d\n", stats.RX_PACKETS);
        printf ("Tx packets:   %d\n", stats.TX_PACKETS);
      }
      else if (MQX_IO_OPERATION_NOT_AVAILABLE == result)
      {
        printf ("not available, define BSPCFG_ENABLE_SPI_STATS\n");
      }
      else
      {
        printf ("ERROR\n");
        return afe4490_spi_config_failure;
      }
      return success;                                                               // if all conditions are satisfied, return success
    }
    
    void afe4490_adc_ready_isr(void *pin)
    {
      
        // Clear ISF flag set on ADC_RDY line mapped to PTC19
       lwgpio_int_clear_flag(&afe4490_adc_rdy);   
    ////   lwgpio_int_clear_flag(&afe4490_adc_rdy);  
    ////   printf("\n hiii");
    //   lwgpio_int_enable(&afe4490_adc_rdy, FALSE);
      afe4490_flag =1;
    //   LED1_ALED1value[0]= afe4490_register_read(LED1VAL,afe4490,3);
    //   LED2_ALED2value[0]= afe4490_register_read(LED2VAL,afe4490,3);
    //   printf("\n L1%lu L2%lu", LED1_ALED1value[0], LED2_ALED2value[0]);
    //    count++;
    //     lwgpio_int_enable(&afe4490_adc_rdy, TRUE);
      
    }
    
    void afe4490_led_alarm_isr(void *pin)
    {
      
        printf("\n gpio");
         // Clear ISF flag set on ADC_RDY line mapped to PTC19
        lwgpio_int_clear_flag(&afe4490_powerdown); 
         printf("\n gpio");
      
    }
    
    void afe4490_pd_alarm_isr(void *pin)
    {
    }

  • Hi Annamol,

    Since you were successful in getting 1KHz ADC_RDY using the sample code given in previous response, I would suggest start writing the other register (block by block) and observe the ADC_RDY. Using this method you can find which register/ block of register is causing the problem.
    You can insert the blocks in following order.
    1) Registers for sampling phases
    2) Registers for LED switching phases
    3) Registers for ADC RST phases
    4) Register for convert phases
    5) Remaining registers.

    Regards,
    Prabin
  • Hi Prabin,

    I will try as you suggested. Between one quick clarification, is there any specific SPI clock frequency needed for AFE4490?
  • Hi Annamol,

    There is limitation on maximum SPI clock supported and that is 16MHz.

    Regards,
    Prabin