Other Parts Discussed in Thread: LM35, HALCOGEN, , RM57L843, LMT86
Tool/software: Code Composer Studio
How to convert the result received from ADC into degrees celsius.
ADC in configured on 12 bits with INTERNAL referince.
I use LM35 DZ temperature sensor.
int main(void)
{
//uint32 voltage_const;
//uint32 temperature;
unsigned int voltage_const;
unsigned int temperature;
unsigned int NumberOfChars2;
unsigned int NumberOfChars3;
unsigned int NumberOfChars1;
unsigned int NumberOfChars4;
unsigned int value1;
canInit();
sciInit();
adcInit();
adcData_t adc_data; //adc data structure
adcData_t *adc_data_ptr = &adc_data; //adc data pointer
while(1)
{
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
value1 = (unsigned int) adc_data_ptr->value;
NumberOfChars1 = ltoa(value1,(char *) adcread);
voltage_const = (value1*3.3)/4096*1000;
temperature = voltage_const/10;
NumberOfChars2=ltoa(voltage_const,(char *) voltage);
NumberOfChars3=ltoa(temperature,(char *) temp);
NumberOfChars4=getNumberOfDigit((int)value1);
/*can*/
canTransmit(canREG1, canMESSAGE_BOX1,(const uint8 *) & temp);
canTransmit(canREG2, canMESSAGE_BOX2,(const uint8 *) & voltage);
canTransmit(canREG3, canMESSAGE_BOX3,(const uint8 *) & adcread);
{
//sciSend(sciREG1, NumberOfChars1,( uint8 *) &adcread);
sciSend(sciREG1, NumberOfChars1,( uint8 *) adcread);
sciSend(sciREG1, 1, " ");
sciSend(sciREG1, 12, "Temperature:");
printf("");
sciSend(sciREG1, NumberOfChars3,( uint8 *) &temp);
sciSend(sciREG1, 3,"°C");
sciSend(sciREG1, 1, " ");
sciSend(sciREG1, 8, "Voltage:");
sciSend(sciREG1, NumberOfChars2,( uint8 *) &voltage);
printf("");
sciSend(sciREG1, 4,"[mV]");
sciSend(sciREG1, 2,"\n\r");
printf("");
sciSend(sciREG1, 1, " ");
sciSend(sciREG1, NumberOfChars4 ,( uint8 *) &value1);
sciSend(sciREG1, 7, "value1:");
}
}
}
From ADC receive for example 252 and dont know which is the equivalent in degrees celsius.
I try this formula : " voltage_const = (value1*3.3)/4096*1000; " and the answer is not correct.