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参考文献

方法 2 示例代码

// (2) Method two will read the ADC and insert that value into the FIFO N times as set in "#define Tmp_1_length" then average the values
// 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 for the array position counter
float sum_array_1 = 0;     // set to 0
int j = 0;     // set to 0 for the sample counter

void FIFO_AVG(void)
{
     // FIFO to average thermistor temperature
     i = 0;     // reset to 0
     j = 0;     // reset to 0
     sum_array_1 = 0;     // reset to 0
     for (j = 0; j < Tmp_1_Length - 1; i++)     // shift the array as a FIFO and drop the last data value, add the new value to the array for (x) samples
     {
          // read the ADC and put the new value into the ADC_Value register
          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 array 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

// Call the FIFO_AVG routine to get N ADC values averaged
FIFO_AVG();
// The ADC average value will be placed into ADC_AVG register