PID ramp soak question

Hi everyone,
I have been working on a PID project for a while that is now working pretty well (home espresso). Now I want to build a roast controller, but am unsure how to approach the moving setpoint part.

Would I need a RTC to keep track of time, or is it sufficient to use millis() ?

If millis() is sufficient would I need to figure out the time taken for a single loop to be executed and then calculate how much the setpoint needs to shift each loop?

Thanks in advance for any advice, I'm having quite a bit of difficulty getting my head around this :slight_smile:

Hello,

Rosscopico0:
Would I need a RTC to keep track of time, or is it sufficient to use millis() ?

There are two reasons to use a real-time clock: 1. Accuracy; 2. Recover from a power loss.

I assume a "roast controller" involves a temperature sensor accurate to two decimals and heating element larger than a pin head in which case millis is more than accurate enough.

Which just leaves #2. Do you expect the Arduino to have to recover from a power loss?

Rosscopico0:
If millis() is sufficient would I need to figure out the time taken for a single loop to be executed and then calculate how much the setpoint needs to shift each loop?

Huh?

Which just leaves #2. Do you expect the Arduino to have to recover from a power loss?

No as I will be there monitoring the process.

Huh?

My current understanding of a ramp soak controller is a PID controller with a moving setpoint. So if the setpoint is moving (at a desired rate) would I need to know the time taken for a loop to be executed, in order to work out what the increment would need to be each time the loop function is executed to stay at the desired ramp rate?

would I need to know the time taken for a loop to be executed, in order to work out what the increment would need to be each time the loop function is executed to stay at the desired ramp rate?

Not really. You can use millis to keep track of time, so there's no need to know how long each iteration of loop takes. The blink without delay example shows use of millis to handle timing. You can decide what your ramp rate should be and pick another interval where you check the actual temp. You might for example check every second, but increase the setpoint every ten.

Is it actually necessary to ramp when toasting coffee? I'd expect that you would heat the roaster to the desired temperature, then add the beans and hold it at temp for the roasting time. Is there some advantage to a gradual rise?

wildbill:
The blink without delay example shows use of millis to handle timing.

The typical version can "drift". If the drift is large enough it will cause problems with PID. This eliminates the problem...

unsigned long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
const unsigned long interval = 1000;           // interval at which to blink (milliseconds)

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  // Greater than OR EQUALS
  if ( currentMillis - previousMillis >= interval ) 
  {
    // Your code goes here.

    // Adjust the mark
    previousMillis += interval;  
  }
}

Is it actually necessary to ramp when toasting coffee? I'd expect that you would heat the roaster to the desired temperature, then add the beans and hold it at temp for the roasting time. Is there some advantage to a gradual rise?

Yes, the roaster needs to be preheated, then when the beans are added the roaster temp drops. Then the temp needs to be gradually ramped up until first crack occurs and dependent on the roast level required, ramped up to 2nd crack.

Ok, I think I am understanding it now. Say for example I wanted the setpoint to shift once each second as a standard thing. By looking at the desired ramp rate, I could easily calculate the size of the setpoint shift each second and tell the Arduino to do that.

Am I on the right track now? Btw thank you all for your help! :slight_smile:

Rosscopico0:
Am I on the right track now?

Certainly a good place to start.