Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. /*This file has been prepared for Doxygen automatic documentation generation.*/
  2. /*! \file *********************************************************************
  3.  *
  4.  * \brief Header file for pid.c.
  5.  *
  6.  * - File:               pid.h
  7.  * - Compiler:           IAR EWAAVR 4.11A
  8.  * - Supported devices:  All AVR devices can be used.
  9.  * - AppNote:            AVR221 - Discrete PID controller
  10.  *
  11.  * \author               Atmel Corporation: http://www.atmel.com \n
  12.  *                       Support email: avr@atmel.com
  13.  *
  14.  * $Name$
  15.  * $Revision: 456 $
  16.  * $RCSfile$
  17.  * $Date: 2006-02-16 12:46:13 +0100 (to, 16 feb 2006) $
  18.  *****************************************************************************/
  19.  
  20. #ifndef PID_H
  21. #define PID_H
  22.  
  23. #include <inttypes.h>
  24. #define SCALING_FACTOR  128
  25.  
  26. /*! \brief PID Status
  27.  *
  28.  * Setpoints and data used by the PID control algorithm
  29.  */
  30. typedef struct PID_DATA{
  31.   //! Last process value, used to find derivative of process value.
  32.   float lastProcessValue;
  33.   //! Summation of errors, used for integrate calculations
  34.   float sumError;
  35.   //! The Proportional tuning constant, multiplied with SCALING_FACTOR
  36.   float P_Factor;
  37.   //! The Integral tuning constant, multiplied with SCALING_FACTOR
  38.   float I_Factor;
  39.   //! The Derivative tuning constant, multiplied with SCALING_FACTOR
  40.   float D_Factor;
  41.   //! Maximum allowed error, avoid overflow
  42.   float maxError;
  43.   //! Maximum allowed sumerror, avoid overflow
  44.   float maxSumError;
  45. } pidData_t;
  46.  
  47.  
  48. typedef struct PID_DEBUG_DATA{
  49.   //! Last process value, used to find derivative of process value.
  50.   float I_term;
  51.   //! Summation of errors, used for integrate calculations
  52.   float P_term;
  53.   //! The Proportional tuning constant, multiplied with SCALING_FACTOR
  54.   float D_term;
  55.   //! The Integral tuning constant, multiplied with SCALING_FACTOR
  56.   float Sum;
  57.   //! The Derivative tuning constant, multiplied with SCALING_FACTOR
  58. } pidDebugData_t;
  59.  
  60. /*! \brief Maximum values
  61.  *
  62.  * Needed to avoid sign/overflow problems
  63.  */
  64. // Maximum value of variables
  65. #define MAX_INT         INT16_MAX
  66. #define MAX_LONG        INT32_MAX
  67. #define MAX_I_TERM      2.0
  68.  
  69. // Boolean values
  70. #define FALSE           0
  71. #define TRUE            1
  72.  
  73. void pid_Init(float p_factor, float i_factor, float d_factor, struct PID_DATA *pid);
  74. float pid_Controller(float setPoint, float processValue, struct PID_DATA *pid_st, struct PID_DEBUG_DATA *pidDebugData );
  75. void pid_Reset_Integrator(pidData_t *pid_st);
  76.  
  77. #endif
  78.