beautypg.com

3 adc code examples, 6 .3 adc code examples -12, 3adccodeexamples – Maxim Integrated MAX31782 User Manual

Page 55

background image

MaximIntegrated 6-12

MAX31782 User’s Guide

Revision 0; 8/11

6.3ADCCodeExamples

6.3.1OneSequenceofFourTemperatureandVoltageConversions

ADCN_bit.IREFEN = 1;

//enable the internal reference

ADCN_bit.ADCONT = 0;

//run a single conversion sequence

ADST_bit.ADCFG = 1;

//set ADDATA as ADCFG

ADST_bit.ADIDX = 0;

//ADIDX = 0, set to ADCFG[0]

ADDATA = 0x08;

//ADCFG[0]: Differential voltage CH0, 1.225V FS, Right Aligned

ADDATA = 0x41;

//ADCFG[1]: Single ended voltage CH1, 5.5V FS, Right Aligned

ADDATA = 0x85;

//ADCFG[2]: External temperature CH5, right aligned

ADDATA = 0x86;

//ADCFG[3]: Internal temperature, CH6, right aligned

ADADDR_bit.ADSTART = 0; //start sequence with ADCFG[0]
ADADDR_bit.ADEND = 3; //end sequence with ADCFG[3]

ADST_bit.ADCONV = 1;

//start the conversions

while(ADST_bit.ADCONV) //wait for conversions to complete

;

ADST_bit.ADCFG = 0;

//set ADDATA to data buffer

ADST_bit.ADIDX = 0;

//set ADDATA to data buffer[0]

ch0_volt = ADDATA;

//read and store ch0 voltage to variable

ch1_volt = ADDATA;

//read and store ch1 voltage to variable

ch5_temp = ADDATA;

//read and store ch5 temperature to variable

int_temp = ADDATA;

//read and store internal temperature to variable