Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion PID_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ void PID::SetTunings(double Kp, double Ki, double Kd){

/* SetSampleTime(...) *********************************************************
* sets the period, in Milliseconds, at which the calculation is performed
* 15 May 2021 gfp - a value of zero will force Compute() to generate a new output every time it is called
* but avoids the 'divide-by-zero' problem
******************************************************************************/
void PID::SetSampleTime(int NewSampleTime)
{
Expand All @@ -139,7 +141,11 @@ void PID::SetSampleTime(int NewSampleTime)
/ (double)SampleTime;
ki *= ratio;
kd /= ratio;
SampleTime = (unsigned long)NewSampleTime;
//SampleTime = (unsigned long)NewSampleTime;
}
else if (NewSampleTime == 0)
{
SampleTime = (unsigned long)NewSampleTime;
}
}

Expand Down
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

- For function documentation see: http://playground.arduino.cc/Code/PIDLibrary

- To synchronize PID::Compute with an external timing source such as a TIMER ISR,
call SetSampleTime() with an argument of zero. This will force Compute to generate a
new output value each time it is called.