Here is the code. This is not exactly "my code", but straight from the SDK example.
float DEMO_MeasureTemperature(ADC_Type *base, uint32_t commandId, uint32_t index)
{
g_LpadcConversionCompletedFlag = false;
lpadc_conv_result_t convResultStruct;
uint16_t Vbe1 = 0U;
uint16_t Vbe8 = 0U;
uint32_t convResultShift = 3U;
float parameterSlope = DEMO_LPADC_TEMP_PARAMETER_A;
float parameterOffset = DEMO_LPADC_TEMP_PARAMETER_B;
float parameterAlpha = DEMO_LPADC_TEMP_PARAMETER_ALPHA;
float temperature = -273.15f; /* Absolute zero degree as the incorrect return value. */
#if defined(FSL_FEATURE_LPADC_TEMP_SENS_BUFFER_SIZE) && (FSL_FEATURE_LPADC_TEMP_SENS_BUFFER_SIZE == 4U)
/* For best temperature measure performance, the recommended LOOP Count should be 4, but the first two results is
* useless. */
/* Drop the useless result. */
(void)LPADC_GetConvResult(base, &convResultStruct, (uint8_t)index);
(void)LPADC_GetConvResult(base, &convResultStruct, (uint8_t)index);
#endif /* FSL_FEATURE_LPADC_TEMP_SENS_BUFFER_SIZE */
/* Read the 2 temperature sensor result. */
if (true == LPADC_GetConvResult(base, &convResultStruct, (uint8_t)index))
{
Vbe1 = convResultStruct.convValue >> convResultShift;
//PRINTF("0x%02X(%u) Shifted:0x%02X\r\n", convResultStruct.convValue, convResultStruct.convValue, Vbe1);
if (true == LPADC_GetConvResult(base, &convResultStruct, (uint8_t)index))
{
Vbe8 = convResultStruct.convValue >> convResultShift;
//PRINTF("0x%02X(%u) Shifted:0x%02X\r\n", convResultStruct.convValue, convResultStruct.convValue, Vbe8);
/* Final temperature = A*[alpha*(Vbe8-Vbe1)/(Vbe8 + alpha*(Vbe8-Vbe1))] - B. */
temperature = parameterSlope * (parameterAlpha * ((float)Vbe8 - (float)Vbe1) /
((float)Vbe8 + parameterAlpha * ((float)Vbe8 - (float)Vbe1))) -
parameterOffset;
}
}
//PRINTF("Temp: %6.3f\r\n", temperature);
return temperature;
}
Now I did notice from LPC55S69 manual, chapter 39.7.6 Temperature sensor:
4. Depending on the device revision, following Alpha., A and B values are needed to
achieve +/- 4 C temperature accuracy. For device revision 0A: Alpha=9.5, A=770 and
B = 289.4. For device revision 1B: Alpha= 8.5, A=804 and B = 280.
So maybe it indeed is normal that you get +-4C difference while the actual temperature remains the same. SDK given values are something different though.
/* @brief Temperature sensor parameter A (slope). */
#define FSL_FEATURE_LPADC_TEMP_PARAMETER_A (744.6f)
/* @brief Temperature sensor parameter B (offset). */
#define FSL_FEATURE_LPADC_TEMP_PARAMETER_B (313.7f)
/* @brief Temperature sensor parameter Alpha. */
#define FSL_FEATURE_LPADC_TEMP_PARAMETER_ALPHA (11.5f)
I must say that this is the most unclear temperature measurement that I have ever seen