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.

CCS/TMS570LS1227: Reading several ADC pins

Part Number: TMS570LS1227
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

Hi all,

I've just finished the 12 bit ADC tutorial that can be found here: https://www.youtube.com/watch?v=YOBWhFE0LZg and now I would like to expand the code so that I can read two ADC pins and send the readings via SCI.

You can see below what my Halcogen settings for ADC Group 1 Configuration is. I am using Pin 15 to monitor a voltage.

I guess the first step will be to select the other pin where I want to monitor the second voltage source (lets say pin 23) , and increase the FiFo Size to 2, right?

And below, my main() as it is, just for 1 pin ADC. The problem is that I don't know how to change the call to adcGetData so that I can get the information from both ADC pins. Any guidance would be greatly appreciated!

/* USER CODE BEGIN (0) */
#include "sci.h"
#include "adc.h"
#include "stdlib.h"
/* USER CODE END */

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
unsigned char command[8];
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */

    adcData_t adc_data; //ADC Data Structure
    adcData_t *adc_data_ptr = &adc_data; //ADC Data Pointer
    unsigned int NumberOfChars, value;

    sciInit();
    adcInit();

    while(1) // Infinite loop to acquire and send ADC sample data via SCI (UART)
    {
        adcStartConversion(adcREG1,adcGROUP1); //Start ADC conversion
        while(!adcIsConversionComplete(adcREG1,adcGROUP1)); //Wait for ADC conversion
        adcGetData(adcREG1,1U,adc_data_ptr); //Store conversion into ADC pointer
        value=(unsigned int)adc_data_ptr->value;
        NumberOfChars = ltoa(value, (char *)command); //Converts "value" to a string and stores it in "command".

        //Transmit over Serial

        sciSend(scilinREG, 2, (unsigned char *) "0x");
        sciSend(scilinREG, NumberOfChars,command);
        sciSend(scilinREG, 2, (unsigned char *) "\r\n");
    }


/* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */

/* USER CODE END */

  • Hello Sofia,

    1. In HALCoGen, select the channels (pin 15 and pin 23) that need to be converted in group 1

    2. In your main() function, do following modifications:

    adcData_t adc_data[2];
    ...
    adcGetData(adcREG1, adcGROUP1,&adc_data[0]);
    The conversion results are stored in adc_data[]:

    adc_data[0] -> should have conversions for Group1 channel1  

    adc_data[1] -> should have conversions for Group1 channel2 

    id[0]       = adc_data[0].id;
    value[0] = adc_data[0].value;

    id[1]       = adc_data[0].id;
    value[1] = adc_data[0].value;

  • Hello Sofia,

    1. In HALCoGen, select the channels (pin 15 and pin 23) that need to be converted in group 1

    2. In your main() function, do following modifications:

    adcData_t adc_data[2];
    ...
    adcGetData(adcREG1, adcGROUP1,&adc_data[0]);

    The conversion results are stored in adc_data[]:
    adc_data[0] -> should have conversions for Group1 channel1

    adc_data[1] -> should have conversions for Group1 channel2

    id[0] = adc_data[0].id;
    value[0] = adc_data[0].value;

    id[1] = adc_data[0].id;
    value[1] = adc_data[0].value;
  • Thanks QJ,

    Just one final clarification, will adc_data[0] store the data from the conversions on PIN 15, and adc_data[1] the data from PIN 23?

    Kind regards,

    Sofia