SNIA049 November   2022 TMP61 , TMP61-Q1 , TMP63 , TMP63-Q1 , TMP64 , TMP64-Q1

 

  1.   Abstract
  2.   Trademarks
  3. 1Introduction
  4. 2Single-Point Offset Correction
  5. 3Oversampling
  6. 4Software Filtering
  7. 5Noise Reduction With Oversampling and Software Filtering
  8. 6Summary

Noise Reduction With Oversampling and Software Filtering

Oversampling and software filtering can be implemented together to increase precision of temperature measurements. In Figure 5-1, each data point represents a different combination of oversampling and filtering, while the color of each point indicates the amount of noise reduction to compare the different combinations. Lighter dots indicate lower precision, whereas darker dots indicate a higher level of precision.

GUID-20221017-SS0I-B8HQ-SLTC-Q30LD78BBDGW-low.png Figure 5-1 Combined Impact of Oversampling and Software Filtering on Noise Reduction

Start with 16 oversamples and a software filter with an α of 0.1 (inside the green oval in Figure 5-1), then adjust the number of oversamples and α value to meet your system needs. Use the following pseudocode to easily test different levels of oversampling and software filtering.

int sensorPin = ; // EDIT indicate pin # for analog input to read VTEMP from TMP6
float Vbias = ; // EDIT indicate Vref voltage for ADC
int ADC_bits = ; // EDIT number of bits of resolution for ADC
int ADC_resolution = pow(2, ADC_bits) - 1; // number of ADC steps

int rawADC; // variable for measured ADC value
float VTEMP; // variable for measured ADC voltagefloat VTEMP_averaged; // variable for averaged ADC voltage
int oversamples = ; // EDIT number of oversamples
float alpha = ; // EDIT 0.001 < alpha < 1, adjust as required. Smaller alpha means stronger filter
float TMP6oversampled; // variable for oversampled TMP6 temperature reading
float TMP6oversampled_filtered; // variable for filtered temperature reading

/* EDIT 4th order polynomial coefficients from Thermistor Design Tool */
float THRM_A0 = ;
float THRM_A1 = ;
float THRM_A2 = ;
float THRM_A3 = ;
float THRM_A4 = ;

/* place in SETUP or INITIALIZATION code */
// this code initializes the oversampled_filtered temperature to the initial raw temperature value
rawADC = analogRead(sensorPin);
VTEMP = Vbias / ADC_resolution * rawADC;
TMP6oversampled_filtered = (THRM_A4 * powf(VTEMP, 4)) + (THRM_A3 * powf(VTEMP, 3)) + (THRM_A2 * powf(VTEMP, 2)) + (THRM_A1 * powf(VTEMP, 1)) + THRM_A0;

/* MAIN code */
for(int i = 0; 1 < oversamples; i++){
	rawADC = analogRead(sensorPin); // read ADC value
	VTEMP += Vbias / ADC_resolution * rawADC; // convert to voltage and sum for desired number of oversamples
}

VTEMP_averaged = VTEMP / oversamples; // average the summed VTEMP
// convert voltage to temperature
TMP6oversampled = (THRM_A4 * powf(VTEMP_averaged, 4)) + (THRM_A3 * powf(VTEMP_averaged, 3)) + (THRM_A2 * powf(VTEMP_averaged, 2)) + (THRM_A1 * powf(VTEMP_averaged, 1)) + THRM_A0;
// calculate oversampled_filtered temperature using previous oversampled_filtered temp and oversampled temp
TMP6oversampled_filtered = TMP6oversampled_filtered - (alpha * (TMP6oversampled_filtered - TMP6oversampled));
VTEMP = 0; // reset VTEMP to 0 for next sample to be taken