Exemplo n.º 1
0
void TempProbe::calcTemp(void)
{
  const float ADCmax = (1 << (10+TEMP_OVERSAMPLE_BITS)) - 1;
  if (_accumulatedCount != 0)
  {
    unsigned int ADCval = _accumulator / _accumulatedCount;
    _accumulatedCount = 0;

    // Units 'A' = ADC value
    if (pid.getUnits() == 'A')
    {
      Temperature = ADCval;
      return;
    }

    if (ADCval != 0)  // Vout >= MAX is reduced in readTemp()
    {
      float R, T;
      // If you put the fixed resistor on the Vcc side of the thermistor, use the following
      R = Steinhart[3] / ((ADCmax / (float)ADCval) - 1.0f);
      // If you put the thermistor on the Vcc side of the fixed resistor use the following
      //R = Steinhart[3] * ADCmax / (float)Vout - Steinhart[3];

      // Units 'R' = resistance, unless this is the pit probe (which should spit out Celsius)
      if (pid.getUnits() == 'R' && this != pid.Probes[TEMP_PIT])
      {
        Temperature = R;
        return;
      };

      // Compute degrees K
      R = log(R);
      T = 1.0f / ((Steinhart[2] * R * R + Steinhart[1]) * R + Steinhart[0]);

      setTemperatureC(T - 273.15f);
    } /* if ADCval */
    else
      Temperature = NAN;
  } /* if accumulatedcount */

  if (hasTemperature())
  {
    calcExpMovingAverage(TEMPPROBE_AVG_SMOOTH, &TemperatureAvg, Temperature);
    Alarms.updateStatus(Temperature);
  }
  else
    Alarms.silenceAll();
}
Exemplo n.º 2
0
void TempProbe::calcTemp(void)
{
  const float ADCmax = (1 << (10+TEMP_OVERSAMPLE_BITS)) - 1;
  if (_accumulatedCount != 0)
  {
    unsigned int ADCval = _accumulator / _accumulatedCount;
    _accumulatedCount = 0;

    // Units 'A' = ADC value
    if (pid.getUnits() == 'A')
    {
      Temperature = ADCval;
      return;
    }

    if (ADCval != 0)  // Vout >= MAX is reduced in readTemp()
    {
      if (_probeType == PROBETYPE_TC_ANALOG)
      {
        float mvScale = Steinhart[3];
        // Commented out because there's no "divide by zero" exception so
        // just allow undefined results to save prog space
        //if (mvScale == 0.0f)
        //  mvScale = 1.0f;
        // If scale is <100 it is assumed to be mV/C with a 3.3V reference
        if (mvScale < 100.0f)
          mvScale = 3300.0f / mvScale;
        setTemperatureC(ADCval / ADCmax * mvScale);
      }
      else {
        float R, T;
        // If you put the fixed resistor on the Vcc side of the thermistor, use the following
        R = Steinhart[3] / ((ADCmax / (float)ADCval) - 1.0f);
        // If you put the thermistor on the Vcc side of the fixed resistor use the following
        //R = Steinhart[3] * ADCmax / (float)Vout - Steinhart[3];

        // Units 'R' = resistance, unless this is the pit probe (which should spit out Celsius)
        if (pid.getUnits() == 'R' && this != pid.Probes[TEMP_PIT])
        {
          Temperature = R;
          return;
        };

        // Compute degrees K
        R = log(R);
        T = 1.0f / ((Steinhart[2] * R * R + Steinhart[1]) * R + Steinhart[0]);

        setTemperatureC(T - 273.15f);
      } /* if PROBETYPE_INTERNAL */
    } /* if ADCval */
    else
      Temperature = NAN;
  } /* if accumulatedcount */

  if (hasTemperature())
  {
    calcExpMovingAverage(TEMPPROBE_AVG_SMOOTH, &TemperatureAvg, Temperature);
    Alarms.updateStatus(Temperature);
  }
  else
    Alarms.silenceAll();
}