ZHCAAU5 October   2020 TMP61 , TMP61-Q1 , TMP63 , TMP63-Q1 , TMP64 , TMP64-Q1

 

  1.   商标
  2. 1引言
  3. 2过采样
    1. 2.1 方法 1
      1. 2.1.1 方法 1 示例代码
    2. 2.2 方法 2
      1. 2.2.1 方法 2 示例代码
    3. 2.3 奈奎斯特速率
    4. 2.4 抖动
    5. 2.5 分辨率
  4. 3参考文献

方法 1 示例代码

// (1) Method one will read the ADC and average the last N values as set in "#define Tmp_1_length"
// FIFO setup of the temporary arrays and define the filter depth (samples to average)
#define Tmp_1_length 16     // Sample length for the averaging filter for oversampling
Float Tmp_1_array[Tmp_1_length];     // The FIFO arrays for averaging the ADC value

float ADC_AVG = 0;     // This is the averaged ADC value over (x) samples
float ADC_Value = 0;     // This is the most recent ADC value captured
int i = 0;     // set to 0
float sum_array_1 = 0;     // set to 0

void FIFO_AVG(void)
{
     // FIFO to average thermistor temperature
     i = 0;     // reset to 0
     sum_array_1 = 0;     // reset to 0
     for (i = 0; i < Tmp_1_Length - 1; i++)     // shift the array as a FIFO and drop the last data value
     {
          Tmp_1_array[i] = Tmp_1_array[i+1];     // makes all the arra indexes equal to the number after them
     }
     Tmp_1_array[Tmp_1_length - 1] = ADC_Value;     // add the new value to the beginning of the array
     for (i = 0; i < Tmp_1_length; i++)     // sum the array
     {
          sum_array_1 += Tmp_1_array[i];      // add all of the array elements
     }
     ADC_AVG = sum_array_1 / Tmp_1_length;     // divide the sum of the array to get an average
}

// Read the ADC and place the bit value into ACD_Value
// Call the ADC_AVG function to get the last ADC value added and averaged into the array 
FIFO_AVG();
// The ADC average value will be placed into ADC_AVG register