Exemple #1
0
inline void GrillPid::commitFanOutput(void)
{
  /* Long PWM period is 10 sec */
  const unsigned int LONG_PWM_PERIOD = 10000;
  const unsigned int PERIOD_SCALE = (LONG_PWM_PERIOD / TEMP_MEASURE_PERIOD);

  unsigned char fanSpeed = getFanSpeed();
  /* For anything above _minFanSpeed, do a nomal PWM write.
     For below _minFanSpeed we use a "long pulse PWM", where
     the pulse is 10 seconds in length.  For each percent we are
     emulating, run the fan for one interval. */
  if (fanSpeed >= _minFanSpeed)
    _longPwmTmr = 0;
  else
  {
    // Simple PWM, ON for first [FanSpeed] intervals then OFF
    // for the remainder of the period
    if (((PERIOD_SCALE * fanSpeed / _minFanSpeed) > _longPwmTmr))
      fanSpeed = _minFanSpeed;
    else
      fanSpeed = 0;

    if (++_longPwmTmr > (PERIOD_SCALE - 1))
      _longPwmTmr = 0;
  }  /* long PWM */

  if (bit_is_set(_outputFlags, PIDFLAG_INVERT_FAN))
    fanSpeed = _maxFanSpeed - fanSpeed;

  analogWrite(_fanPin, mappct(fanSpeed, 0, 255));
}
Exemple #2
0
inline void GrillPid::commitServoOutput(void)
{
#if defined(GRILLPID_SERVO_ENABLED)
  unsigned char output;
  if (bit_is_set(_outputFlags, PIDFLAG_SERVO_ANY_MAX) && _pidOutput > 0)
    output = 100;
  else
    output = _pidOutput;

  if (bit_is_set(_outputFlags, PIDFLAG_INVERT_SERVO))
    output = 100 - output;

  // Get the output speed in 10x usec by LERPing between min and max
  output = mappct(output, _minServoPos, _maxServoPos);
  // Servo output is actually set on the next interrupt cycle
  _servoOutput = uSecToTicks(10U * output);
#endif
}
Exemple #3
0
inline void GrillPid::commitFanOutput(void)
{
  /* Long PWM period is 10 sec */
  const unsigned int LONG_PWM_PERIOD = 10000;
  const unsigned int PERIOD_SCALE = (LONG_PWM_PERIOD / TEMP_MEASURE_PERIOD);

  unsigned char fanSpeed = getFanSpeed();
  /* For anything above _minFanSpeed, do a nomal PWM write.
     For below _minFanSpeed we use a "long pulse PWM", where
     the pulse is 10 seconds in length.  For each percent we are
     emulating, run the fan for one interval. */
  if (fanSpeed >= _minFanSpeed)
    _longPwmTmr = 0;
  else
  {
    // Simple PWM, ON for first [FanSpeed] intervals then OFF
    // for the remainder of the period
    if (((PERIOD_SCALE * fanSpeed / _minFanSpeed) > _longPwmTmr))
      fanSpeed = _minFanSpeed;
    else
      fanSpeed = 0;

    if (++_longPwmTmr > (PERIOD_SCALE - 1))
      _longPwmTmr = 0;
  }  /* long PWM */

  if (bit_is_set(_outputFlags, PIDFLAG_INVERT_FAN))
    fanSpeed = _maxFanSpeed - fanSpeed;

  unsigned char newBlowerOutput = mappct(fanSpeed, 0, 255);
  analogWrite(_fanPin, newBlowerOutput);

#if defined(GRILLPID_FAN_BOOST_ENABLED)
  // If going from 0% to non-0%, turn the blower fully on for one period
  // to get it moving
  if (_lastBlowerOutput == 0 && newBlowerOutput != 0)
  {
    digitalWrite(_fanPin, HIGH);
    _fanBoostActive = true;
  }

  _lastBlowerOutput = newBlowerOutput;
#endif
}