Where knowledge empowers you to understand your world

RM57L ADC Example: Analog To Digital Conversion

Texas Instruments Launchpad RM57L microcontroller kit.
Texas Instruments Launchpad RM57L microcontroller kit. Image credit: Kompulsa.

This RM57L ADC code sample demonstrates how to use the TI RM57L843 MCU (from the RM57L Launchpad kit) to measure temperature using a 3435B thermistor.

Texas Instruments Launchpad RM57L microcontroller kit.
Texas Instruments Launchpad RM57L microcontroller kit.
/* USER CODE BEGIN (1) */
#include "HL_adc.h" //The ADC library we'll use to read the sensor.
/* USER CODE END */

void 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 value; //The ADC value is stored in this variable.
float resistance; //The resistance of the thermistor at the current temperature reading;
float degperohm = 0.003267974; //Degrees per ohm of resistance.
unsigned int temperature; //The temperature in degrees Celsius.
adcInit(); //Initialize the ADC module.

while(1) //ADC conversion loop.
{
    adcStartConversion(adcREG1, 1U); //Start conversion on ADC 1.
    while(!adcIsConversionComplete(adcREG1, 1U)); //Keep looping until the conversion is complete.
    adcGetData(adcREG1, 1U, adc_data_ptr); //Store conversion into ADC pointer
    value = (unsigned int)adc_data_ptr->value;
    resistance = 1000 * (4096 / value);
    temperature = degperohm * resistance;
} //End of ADC conversion loop.

/* USER CODE END */
}