Hi,
Ik ben met wat PID software bezig voor meerdere oventjes, voor mijn temperatuur sensor kalibrator niet zo van belang, ondanks dat deze ook een Arduino PID oven krijgt.
Deze zal in verhouding nooit lang genoeg aan staan voor een overflow van de millis, daar dat oventje nooit meer dan een paar uur aan zal staan.
Maar voor twee andere oventjes gebruik ik de onderstaande code die als basis wordt gebruikt voor het aansturen van de oventjes.
Dit is de P.I.D. software die je in de Arduino IDE kan vinden.
Ik heb wat extra info bovenaan de code geplaatst betreffende de info van de maker.
In de eerste regel van de setup hieronder staat dit:
c code:
void setup()
{
windowStartTime = millis();
Houd dit nu in dat het mis gaat met de code als deze de limit berijkt van 50 dagen voor millis?
Zo ja, wat zou dan een oplossing zijn voor een meetinstrument dat 24/7/365 aan moet kunnen staan?
c code:
/********************************************************
* PID RelayOutput Example
* Same as basic example, except that this time, the output
* is going to a digital pin which (we presume) is controlling
* a relay. the pid is designed to Output an analog value,
* but the relay can only be On/Off.
*
* to connect them together we use "time proportioning
* control" it's essentially a really slow version of PWM.
* first we decide on a window size (5000mS say.) we then
* set the pid to adjust its output between 0 and that window
* size. lastly, we add some logic that translates the PID
* output into "Relay On Time" with the remainder of the
* window being "Relay Off Time"
***************************************************************
* Arduino PID Library - Version 1.2.0
* by Brett Beauregard <br3ttb@gmail.com> brettbeauregard.com
*
* This Library is licensed under the MIT License
***************************************************************
- For an ultra-detailed explanation of why the code is the way it is, please visit:
http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/
- For function documentation see: http://playground.arduino.cc/Code/PIDLibrary
********************************************************/
#include <PID_v1.h>
#define PIN_INPUT 0
#define RELAY_PIN 6
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
int WindowSize = 5000;
unsigned long windowStartTime;
void setup()
{
windowStartTime = millis();
//initialize the variables we're linked to
Setpoint = 100;
//tell the PID to range between 0 and the full window size
myPID.SetOutputLimits(0, WindowSize);
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
Input = analogRead(PIN_INPUT);
myPID.Compute();
/************************************************
* turn the output pin on/off based on pid output
************************************************/
if (millis() - windowStartTime > WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if (Output < millis() - windowStartTime) digitalWrite(RELAY_PIN, HIGH);
else digitalWrite(RELAY_PIN, LOW);
}
Hartelijk dank vast,
Bram