From 2537498c60e85657987f3839f828cc80df30924e Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Sat, 12 Oct 2013 06:49:40 +0000 Subject: many more features for pcr controller git-svn-id: https://svn.spreadspace.org/avr/trunk@243 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- pcr-controller/pid_control.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'pcr-controller/pid_control.c') diff --git a/pcr-controller/pid_control.c b/pcr-controller/pid_control.c index 4ab3a99..18b2bc6 100644 --- a/pcr-controller/pid_control.c +++ b/pcr-controller/pid_control.c @@ -1,8 +1,21 @@ /* - * OpenPCR Teensy Controller Code + * r3PCR Teensy Controller Code * * * Copyright (C) 2013 Bernhard Tittelbach + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see . */ #include "pid_control.h" @@ -53,7 +66,7 @@ void pid_printVars(void) void pid_setTargetValue(int16_t v) { - pid_target_value_ = v; + pid_target_value_ = v; } int16_t pid_getTargetValue(void) @@ -75,13 +88,13 @@ int16_t pid_calc(int16_t current_value) int32_t error = pid_target_value_ - current_value; // derivative // instead of derivative of error we take derivative on measurement - // since dError/dt = - dInput/dt (note the - ) + // since dError/dt = - dInput/dt (note the - ) int32_t d_measure = current_value - pid_last_input_; pid_last_input_ = current_value; // integral (bring pid_i_ into integral, so we get smooth transfer if pid_i_ suddenly changes) pid_i_integralsum_ += pid_i_ * error; - + // prevent integrator wind-up if (pid_i_integralsum_ > pid_outlimit_max_) pid_i_integralsum_ = pid_outlimit_max_; @@ -92,7 +105,7 @@ int16_t pid_calc(int16_t current_value) int32_t pid_output_preclamp = ( (error * pid_p_) + (pid_i_integralsum_) - (d_measure * pid_d_) ); - + // limit output if (pid_output_preclamp > pid_outlimit_max_) return (int16_t) (pid_outlimit_max_ / PID_SCALE); -- cgit v1.2.3