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

Software Filtering

Filtering in software is also used for noise reduction. Software filtering acts as a low-pass filter and is implemented simply using the formula in Equation 1.

Equation 1. f i l t e r e d T e m p = p r e v i o u s F i l t e r e d T e m p - ( α × p r e v i o u s F i l t e r e d T e m p - m e a s u r e d T e m p )

With software filtering, the raw data is smoothed according to a smoothing factor, α. An α of 1 indicates no filtering, and an α of 0.99 allows most noise to be passed through, whereas an α of 0.01 eliminates a lot of noise. Figure 4-1 shows the impact of different levels of software filtering on noise reduction.

GUID-20221104-SS0I-HJPX-PDKS-067XQ5Z8GCGB-low.png Figure 4-1 Impact of Software Filters With Alpha Values 0.5, 0.1, 0.05, and 0.01 on Noise

Using the following pseudocode, the α value of the filter can be easily adjusted to meet system requirements.

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 voltage
float alpha = ; // EDIT 0.001 < alpha < 1, adjust as required. Smaller alpha means stronger filter
float TMP6raw; // variable for raw TMP6 temperature reading
float TMP6filtered; // 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 filtered temperature to the initial raw temperature value
rawADC = analogRead(sensorPin);
VTEMP = Vbias / ADC_resolution * rawADC;
TMP6filtered = (THRM_A4 * powf(VTEMP, 4)) + (THRM_A3 * powf(VTEMP, 3)) + (THRM_A2 * powf(VTEMP, 2)) + (THRM_A1 * powf(VTEMP, 1)) + THRM_A0;

/* MAIN code */
rawADC = analogRead(sensorPin); // read ADC value
VTEMP = Vbias / ADC_resolution * rawADC; // convert to voltage
// convert voltage to temperature
TMP6raw = (THRM_A4 * powf(VTEMP, 4)) + (THRM_A3 * powf(VTEMP, 3)) + (THRM_A2 * powf(VTEMP, 2)) + (THRM_A1 * powf(VTEMP, 1)) + THRM_A0;
// calculate filtered temperature using previous filtered temp and raw temp
TMP6filtered = TMP6filtered - (alpha * (TMP6filtered - TMP6raw));