Skip to content

Examples_MAX31856_PTC_SSR

Dlloydev edited this page Feb 13, 2022 · 5 revisions

Examples_MAX31856_PTC_SSR

image

Hardware

Circuit Connections

  • A series 330Ω resistor was connected from UNO pin 3 to pin 3 of the SSR (LED+)
  • SSR Pin 4 (LED-) was connected to GND
  • The PTC black wire was connected to AC Neutral
  • SSR load pin 2 connected to the PTC red wire
  • SSR load pin 1 connected to 120VAC power
  • To connect the MAX31856 board, follow instructions here

Code Description

Examples

Initialize sTune

sTune tuner = sTune(&Input, &Output, tuner.ZN_PID, tuner.directIP, tuner.printOFF);

In this example, sTune is initialized usin the ZN_PID tuning method. The inflection point directIP test is run and the serial print results is turned off to allow the plotter function to plot the complete sTune test and PID run.

User Settings

// user settings
uint32_t settleTimeSec = 10;
uint32_t testTimeSec = 500;  // runPid interval = testTimeSec / samples
const uint16_t samples = 500;
const float inputSpan = 200;
const float outputSpan = 1000;
float outputStart = 0;
float outputStep = 50;
float tempLimit = 150;
uint8_t debounce = 1;
  • settleTimeSec is used to provide additional settling time prior to starting the test.
  • testTimeSec at minimum, should be set to one time constant (the time it takes for the input to reach 63% of the max value after a step change of the controller output.
  • samples is the number of samples used to perform the test. To get an accurate representation of the reaction curve, the suggested range is 200-500.
  • testTimeSec / samples determines the sample period
  • inputSpan represents the maximum operating range of input
  • outputSpan represents the maximum operating range of output. This also specifies the softPWM windowSize, the PID output max limit, the PID sample time and is also used in gain calculations in various tuning methods.
  • outputStart is the initial control output value which is used for the settleTimeSec duration and sample 0
  • outputStep is the stepped output value used for sample 1 to test completion
  • tempLimit is used to specify the emergency stop value at which the test aborts (reset) and the output is set to zero
  • debounce controls several features in the softPWM() function.
// variables
float Input, Output, Setpoint = 80, Kp, Ki, Kd;
  • These variables are linked to sTune and QuickPID

void loop()

void loop() {
  float optimumOutput = tuner.softPwm(relayPin, Input, Output, Setpoint, outputSpan, debounce);

  switch (tuner.Run()) {
    case tuner.sample: // active once per sample during test
      if (!digitalRead(drdyPin)) Input = maxthermo.readThermocoupleTemperature();
      tuner.plotter(Input, Output, Setpoint, 0.5f, 3); // output scale 0.5, plot every 3rd sample
      break;

    case tuner.tunings: // active just once when sTune is done
      tuner.GetAutoTunings(&Kp, &Ki, &Kd); // sketch variables updated by sTune
      myPID.SetOutputLimits(0, outputSpan * 0.1);
      myPID.SetSampleTimeUs((outputSpan - 1) * 1000);
      debounce = 0; // ssr mode
      Output = outputStep;
      myPID.SetMode(myPID.Control::automatic); // the PID is turned on
      myPID.SetProportionalMode(myPID.pMode::pOnMeas);
      myPID.SetAntiWindupMode(myPID.iAwMode::iAwClamp);
      myPID.SetTunings(Kp, Ki, Kd); // update PID with the new tunings
      break;

    case tuner.runPid: // active once per sample after tunings
      if (!digitalRead(drdyPin)) Input = maxthermo.readThermocoupleTemperature();
      myPID.Compute();
      tuner.plotter(Input, optimumOutput, Setpoint, 0.5f, 3);
      break;
  }
}

In the loop(), the softPWM function runs continuously and drives a time proportioned output on relayPin 3. The function returns the internaloptimumOutput signal used for SSRs. This allows plotting and diagnostic use.

The switch case controlled by sTune has 3 main states - sample, tunings and runPid.

case tuner.sample:

  • Active once per sample during sTune inflection or full test. Here, the Input reading is updated and the plotter function is run

case tuner.tunings:

  • active just once when sTune is done

  • tuner.GetAutoTuningsupdates the Kp, Ki and Kd sketch variables with the new gains

  • myPID.SetOutputLimits(0, outputSpan * 0.1); Here, the max limit is set to 10% of the outputSpan because this is the minimum output value needed to drive the temperature of the PTC heater to maximum.

  • myPID.SetSampleTimeUs((outputSpan - 1) * 1000); The PID sample time is regulated at 1 second in the runPid case. We use outputSpan * 1000 - 1 just to convert to µs and ensure that there's a computation at each 1-second sample.

  • debounce = 0; When debounce is set to 0, software PWM uses SSR optimum cycle mode

  • The PID is set to automatic, pOnMeas and iAwClamp. Note that pOnError mode isn't used because the output won't react in advance as the input approaches setpoint. Also,iAwCondition mode isn't used as it counteracts the beneficial effect of the optimumOutput software PWM mode.

case tuner.runPid:

This case is active once per sample period (1-sec intervals) after tunings. Here, the temperature is read, PID compute is run and the plotter function is run.