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.

CC2541 ADC differential conversion

Other Parts Discussed in Thread: CC2541

Hi,

I'm trying to read an uncompensated, unamplified pressure sensor whose output is connected to AIN0 and AIN1 pins on a CC2541 board based on reference designs. The sensor is connected to VCC and GND and should behave pretty much like a Wheatstone bridge, outputing a voltage proportional to VCC depending on the pressure it is sensing.

The board is being powered by the CC Debugger. I've attached the relevant part of the schematic.

I've searched but I haven't been able to find an example or documentation on how to read a differential ADC value.

The HAL API has this function:

uint16 HalAdcRead (uint8 channel, uint8 resolution)

So I use that in my program attempting to read  in a function called during the performPeriodicTask() function like this:

static void readPressure( void )
{
  pressureReading = 0; // Global variable to keep the pressure reading
  
  // Read from ADC using channels 0 and 1 as differential input
  pressureReading = HalAdcRead( HAL_ADC_CHN_A0A1 , HAL_ADC_RESOLUTION_8 );
  pressureReading++;
  
}

I use HAL_ADC_CHN_A0A1 since I think it is the differential channel, and I use HAL_ADC_RESOLUTION_8 since the sensor's readings span from 0 to 150 psi.

However, I always get zero returned from HalAdcRead().

While debugging HalAdcRead() I watch the reading variable to be some value that then gets turned into zero because of this right-shifting code:

switch (resolution)
  {
    case HAL_ADC_RESOLUTION_8:
      reading >>= 8;
      break;
  // and so on for different resolutions

What could I be doing wrong? Could it be that I'm not using the right resolution? or do I need to configure the ADC differently?

Any leads would be greatly appreciated.


Thanks in advance,

  • Hello Francisco,

    Test your ADC using the example found in the swrc257.zip. http://www.ti.com/litv/zip/swrc257 It has three different methods for doing single ended conversions.  Once it is confirmed that you can read varying input voltages then you can change the HalAdcRead  to differential inputs.

    For the resolution, you may still want to go with the highest resolution 12 or 14 since the 0 to 150 PSI produces a 0 to VCC output.

    Thanks,

  • Fransisco.

    You also need to define HAL_ADC = TRUE in your compiler preprocessor due to the HalAdcRead code containing:

    int16  reading = 0;
    
    #if (HAL_ADC == TRUE)

    You should also call HalAdcSetReference(HAL_ADC_REF_AVDD) first to set the reference to the supply voltage first.

    Regards,
    Svend

  • Svend, Greenja

    Thanks for your reply and sorry it took me a while to write back.


    The define mentioned, was already in the board configuration header and the reference was already set in HalAdcInit, I think, but I was definitely set to VDD.

    I'm glad to say that we are reading the pressure now pretty much on Greenja's suggestion to increase the resolution. Now we just have to do some temperature compensation and we'll be done.

    Thanks a lot