Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified SetSampleTime() to allow PID::Compute() synch to external timing source #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.