Repeated ADC read, Wake up from flexi, Aducm3029

Hi there,

I am trying to read repeated continuous analog signal at ADC0 pin. when there is no analog signal, the controller should be in flexi mode.

I am able to keep controller in flexi mode, and waking up when thershold is crossed as well (comparator mode). but I am unable to read the results (digital values) now.  

Can anyone give sample code for this?

Thanks,

Gopal

  • Hello ,

    Here is an example of how you can implement the main loop for that application.

    // Loop
    while(1)
    {
        // Wait for the signal to cross the threshold
        adi_adc_RegisterCallback(hDevice, comparatorCallback, NULL);
        *pREG_ADC0_IRQ_EN = 0x1000;
        adi_adc_SetHighLimit(hDevice, ADI_ADC_CHANNEL_0, true, 1024);
        adi_adc_EnableDigitalComparator(hDevice, true);
        
        adi_pwr_EnterLowPowerMode(ADI_PWR_MODE_FLEXI, NULL, 0);
    
        
        // After it crosses, setup and submit the ADC buffer
        Buffer.nBuffSize = sizeof(ADC_DataBuffer);
        Buffer.nChannels = ADI_ADC_CHANNEL_0;
        Buffer.nNumConversionPasses = ADC_NUM_SAMPLES;
        Buffer.pDataBuffer = ADC_DataBuffer;
        
        adi_adc_SubmitBuffer (hDevice, &Buffer);
    
        adi_adc_Enable(hDevice, true);
        
        ADI_ADC_BUFFER* pAdcBuffer;
        adi_adc_GetBuffer (hDevice, &pAdcBuffer);
        
        // At this point, you can get the readings in ADC_DataBuffer
    }

    The callback function

    static void comparatorCallback(void *pCBParam, uint32_t Event, void *EventArg)
    {
      if(Event == ADI_ADC_EVENT_HIGH_LIMIT_CROSSED)
      {
        // Unregister Callback
        adi_adc_RegisterCallback(hDevice, NULL, NULL);
    
        // Disable comparator
        adi_adc_EnableDigitalComparator(hDevice, false);
    
        // Exit flexi mode
        adi_pwr_ExitLowPowerMode(NULL);
      }
    }

    Regards

  • Hi ,

    Thanks for the reply. But the program is stuck at this line shown below.

      adi_adc_GetBuffer (hDevice, &pAdcBuffer);

    Even debugging couldn't help me. Please see below code of mine.

    1.

    2.

    3.

    4.

    Please let me know. 

    Thanks,

    Gopal

  • Hello ,

    Did you wait for the crossing to happen by putting enterlowpowermode function after enabling the comparator? You can only use the getbuffer function if you dont have a registered callback, otherwise it will block. So before getting there you should have already unregistered the callback in your adc_int_handler.

    Regards

  • Hi ,

    Thanks for the great support. 

    I already unregistered callback in handler as well as in the main function. Please see attached file. It is getting stuck at getBuffer function. Waiting for the reply.

    Aducm3029_ADC_wakeup.zip

    Thanks,

    Gopal

  • Hello ,

    Why are you using a different handle (hADC) in disabling the comparator? Use only one ADI_ADC_HANDLE, preferably hDevice.

    Edit:

    I have seen that you also use hDevice in disabling the comparator. What you've done after using adc_enable is you disabled the comparator which in the end disabled the ADC. Try to follow my suggested sequence and do the disabling of the comparator and callback unregister before the submitbuffer and adc_enable functions. 

    Regards