Power Control Library - NXP...
Transcript of Power Control Library - NXP...
Freescale SemiconductorReference Manual
© 2014 Freescale Semiconductor, Inc. All rights reserved.
1 Introduction
1.1 OverviewThis reference manual describes the Power Control Library for Freescale and the 56800E(X) family of Digital Signal Controllers. The library is supplied in a binary form, which is unique in its simplicity to integrate with user application.
1.2 Supported compilersThe Power Control Library (PCLIB) is written in assembly language with a C-callable interface. The library was built and tested using CodeWarrior™ Development Studio version 10.3. The library is delivered in the 56800Ex_PCLIB.lib library module and is intended for use in small data memory model projects. The interfaces to the algorithms included in this library have been combined into a single public interface include file, the pclib.h, to reduce the number of files required for inclusion by the application programs. Refer to the specific algorithm sections of this document for details on the software application programming interface (API), defined and functionality provided for the individual algorithms.
Doc Number: 56800Ex_PCLIBRev. 0, 04/2014
Contents1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2. Supported compilers . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3. Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4. Library integration . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.5. API definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.6. Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.7. User common types . . . . . . . . . . . . . . . . . . . . . . . . . . 51.8. Special issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2. Function API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.1. API summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2. PCLIB_ControllerPI . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2.6.Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.3. PCLIB_ControllerPI plus low pass filter . . . . . . . . . 112.4. PCLIB_ControllerPID . . . . . . . . . . . . . . . . . . . . . . . 162.5. PCLIB_Controller2P2Z . . . . . . . . . . . . . . . . . . . . . . 212.5.2.Prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.6. PCLIB_Controller3P3Z . . . . . . . . . . . . . . . . . . . . . . 25
3. Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Power Control Library5600E, 56800EXDigital Signal Controllerby Freescale Semiconductor, Inc.
Power Control Library, Rev. 0
2 Freescale Semiconductor
Introduction
1.3 InstallationIf the user wants to fully use this library, the CodeWarriorTM Development Studio should be installed prior to the Power Control Library. In case that the Power Control Library tool is installed while CodeWarriorTM Development Studio is not present, users can only browse the installed software package, but will not be able to build, download, and run the code. The installation itself consists of copying the required files to the destination hard drive, checking the presence of CodeWarriorTM Development Studio, and creating the shortcut under the Start->Programs menu.
The Power Control Library release is installed in its own folder named 56800Ex _PCLIB.
To start the installation process, follow the following steps:1. Execute the 56800Ex_PCLIB_rXX.exe file.2. Follow the software installation instructions on your screen.
1.4 Library integration The library integration is described in AN4586 which can be downloaded from www.freescale.com.
1.5 API definitionThe description of each function described in this Power Control Library user reference manual consists of a number of subsections:
Synopsis
This subsection gives the header files that should be included within a source file that references the function or macro. It also shows an appropriate declaration for the function, or for a function that can be substituted by a macro. This declaration is not included in your program; only the header file(s) should be included.
Prototype
This subsection shows the original function prototype declaration with all its arguments.
Arguments
This optional subsection describes input arguments to a function or macro.
Description
This subsection is a description of the function or macro. It explains algorithms being used by functions or macros.
Return
This optional subsection describes the return value (if any) of the function or macro.
Range Issues
This optional subsection specifies the ranges of input variables.
Power Control Library, Rev. 0
Freescale Semiconductor 3
Introduction
Special Issues
This optional subsection specifies special assumptions that are mandatory for correct function calculation; for example saturation, rounding, and so on.
Implementation
This optional subsection specifies, whether a call of the function generates a library function call or a macro expansion.
This subsection also consists of one or more examples of the use of the function. The examples are often fragments of code (not completed programs) for illustration purposes.
See Also
This optional subsection provides a list of related functions or macros.
Performance
This section specifies the actual requirements of the function or macro in terms of required code memory, data memory, and number of clock cycles to execute.
1.6 Data typesThe 16-bit DSC core supports four types of two’s-complement data formats:
• Signed integer• Unsigned integer• Signed fractional• Unsigned fractional
Signed and unsigned integer data types are useful for general-purpose computation; they are familiar with the microprocessor and microcontroller programmers. Fractional data types allow powerful numeric and digital-signal-processing algorithms to be implemented.
1.6.1 Signed integer (SI)This format is used for processing data as integers. In this format, the N-bit operand is represented using the N.0 format (N integer bits). The signed integer numbers lie in the following range:
Eqn. 1
This data format is available for bytes, words, and longs. The most negative, signed word that can be represented is –32,768 ($8000), and the most negative, signed long word is –2,147,483,648 ($80000000).
The most positive, signed word is 32,767 ($7FFF), and the most positive signed long word is 2,147,483,647 ($7FFFFFFF).
2 N 1–( ) SI 2 N 1–( ) 1–( )≤≤–
Power Control Library, Rev. 0
4 Freescale Semiconductor
Introduction
1.6.2 Unsigned integer (UI)The unsigned integer numbers are positive only, and they have nearly twice the magnitude of a signed number of the same size. The unsigned integer numbers lie in the following range:
Eqn. 2
The binary word is interpreted as having a binary point immediately to the right of the integer’s least significant bit. This data format is available for bytes, words, and long words. The most positive, 16-bit, unsigned integer is 65,535 ($FFFF), and the most positive, 32-bit, unsigned integer is 4,294,967,295 ($FFFFFFFF). The smallest unsigned integer number is zero ($0000), regardless of size.
1.6.3 Signed fractional (SF)In this format, the N-bit operand is represented using the 1. [N–1] format (one sign bit, N–1 fractional bits). The signed fractional numbers lie in the following range:
Eqn. 3
This data format is available for words and long words. For both word and long-word signed fractions, the most negative number that can be represented is –1.0; its internal representation is $8000 (word) or $80000000 (long word).
The most positive word is $7FFF (1.0 – 2–15); its most positive long word is $7FFFFFFF (1.0 – 2–31).
1.6.4 Unsigned fractional (UF)The unsigned fractional numbers can be positive only, and they have nearly twice the magnitude of a signed number with the same number of bits. The unsigned fractional numbers lie in the following range:
Eqn. 4
The binary word is interpreted as having a binary point after the MSB. This data format is available for words and longs. The most positive, 16-bit, unsigned number is $FFFF, or {1.0 + (1.0 – 2–[N–1])} = 1.99997. The smallest unsigned fractional number is zero ($0000).
0 UI 2 N 1–( ) 1–( )≤ ≤
1.0 SF 1.0 2 N 1–( )––≤≤–
0.0 UF 2.0 2 N 1–( )––≤≤
Power Control Library, Rev. 0
Freescale Semiconductor 5
Introduction
1.7 User common types
1.8 Special issuesAll functions in the Power Control Library are implemented without storing any of the volatile registers (refer to the compiler manual) used by the respective routine. Only non-volatile registers (C10, D10, R5) are saved by pushing the registers on the stack. Therefore, if the particular registers initialized before the library function call are to be used after the function call, it is necessary to save them manually.
Table 1. User-defined typedefs in 56800E_types.h
Mnemonics Size — bits Description
Word8 8 To represent 8-bit signed variable/value.
UWord8 8 To represent 8-bit unsigned variable/value.
Word16 16 To represent 16-bit signed variable/value.
UWord16 16 To represent 16-bit unsigned variable/value.
Word32 32 To represent 32-bit signed variable/value.
UWord32 32 To represent 32-bit unsigned variable/value.
Int8 8 To represent 8-bit signed variable/value.
UInt8 8 To represent 8-bit unsigned variable/value.
Int16 16 To represent 16-bit signed variable/value.
UInt16 16 To represent 16-bit unsigned variable/value.
Int32 32 To represent 32-bit signed variable/value.
UInt32 32 To represent 32-bit unsigned variable/value.
Frac16 16 To represent 16-bit signed variable/value.
Frac32 32 To represent 32-bit signed variable/value.
NULL constant Represents NULL pointer.
bool 16 Boolean variable.
false constant Represents false value.
true constant Represents true value.
FRAC16() macro Transforms float value from <–1, 1) range into fractional representation <–32768, 32767>.
FRAC32() macro Transforms float value from <–1, 1) range into fractional representation <–2147483648, 2147483648>.
Power Control Library, Rev. 0
6 Freescale Semiconductor
Function API
2 Function API
2.1 API summary
2.2 PCLIB_ControllerPIThe function calculates Proportional and Integral (PI) algorithm.
2.2.1 Synopsis#include ”pclib.h”
Frac16 PCLIB_ControllerPI(Frac16 f16Error, PCLIB_CONTROL_PI_PARAMS_T * const pudtControlStruct)
2.2.2 Prototypeasm Frac16 PCLIB_ControllerPIFAsm(Frac16 f16Error, PCLIB_CONTROL_PI_PARAMS_T * const pudtControlStruct)
Table 2. API Functions summary
Name Arguments Output Description
PCLIB_ControllerPI • Frac16 f16Error • PCLIB_CONTROL_PI_PARAMS_T * const
pudtControlSturct
Frac16 The function calculates Proportional and Integral (PI) algorithm.
PCLIB_ControllerPI plus low pass filter
• Frac16 f16Error • PCLIB_CONTROL_PIANDLPFILTER_PARAMS_
T * const pudtControlStruct
Frac16 The function calculates Proportional and Integral with Low pass Filter algorithm.
PCLIB_ControllerPID • Frac16 f16Error • PCLIB_CONTROL_PID_PARAMS_T * const
pudtControlStruct
Frac16 The function calculates Proportional, Integral and Differential (PID) algorithm.
PCLIB_Controller2P2Z • Frac16 f16Error • PCLIB_CONTROL_2P2Z_PARAMS_T * const
pudtControlStruct
Frac16 The function calculates 2pole2zero (2P2Z) algorithm.
PCLIB_Controller3P3Z • Frac16 f16Error • PCLIB_CONTROL_3P3Z_PARAMS_T * const
pudtControlStruct
Frac16 The function calculates 3pole3zero (3P3Z) algorithm.
Power Control Library, Rev. 0
Freescale Semiconductor 7
Function API
2.2.3 Arguments
2.2.4 AvailabilityThis library module is available in the C-callable interface assembly format. This library module is targeted for 56800E and 56800Ex platform.
2.2.5 DependenciesList of all dependent files:
• PCLIB_ControllerPIAsm.h
Table 3. Function arguments
Name Type Format Range Description
f16Error In SF16 0x8000...0x7FFF Input error at step ‘n’ processed by Proportional and Integral terms of the PI algorithm
*const pudtControlStruct In/Out struct N/A Constant Pointer to a structure of PI controller parameters; the PCLIB_CONTROL_PI_ PARAMS_T data type is defined in the header file PCLIB_ControllerPIAsm.h
Table 4. User Type definitions
Typedef Name In/Out Format Range Description
PCLIB_CONTROL_PI_PARAMS_T f16PropGain In SF16 0x0...0x7FFF Proportional gain
f16IntegGain In SF16 0x0...0x7FFF Integral gain
f16IntegUpperLimit In SF16 0x8000...0x7FFF Upper limit of Integral component;f16IntegUpperLimit >f16IntegLowerLimit
f16IntegLowerLimit In SF16 0x8000...0x7FFF Lower limit of Integral component;f16IntegUpperLimit >f16IntegLowerLimit
f16IntegOutputN_1 In/Out SF16 0x8000...0x7FFF State variable; integral part at step (n-1); can be modified outside of the function
f16UpperLimit In SF16 0x8000...0x7FFF Upper limit of the controller; f16UpperLimit > f16LowerLimit
f16LowerLimit In SF16 0x8000...0x7FFF Lower limit of the controller; f16UpperLimit > f16LowerLimit
Power Control Library, Rev. 0
8 Freescale Semiconductor
Function API
• 56800E_types.h
2.2.6 DescriptionThe PCLIB_ControllerPI function calculates the Proportional-Integral (PI) algorithm according to the equations below. The integral output of the controller is also limited and the limit values (f16IntegUpperLimit and f16IntegLowerLimit) are defined by the user. The controller output is also limited and the limit values (f16UpperLimit and f16LowerLimit) are defined by the user.
The integral state is limited by the controller limits, in the same way as the controller output.
The PI controller algorithm can be shown as:
e(n) - input errory(n)- controller output
The PI algorithm in the continuous time domain:
Eqn. 5
Equation 5 can be rewritten into the discrete time domain by approximating the integral term.
The integral term is approximated by the Backward Euler method, also known as backward rectangular or right - hand approximation as follows.
Eqn. 6
y t( ) Kp e t( ) Ki e t( )× dt×
0
t
∫+×=
yI n( ) yI n 1–( ) Ki Ts e n( )××+=
Power Control Library, Rev. 0
Freescale Semiconductor 9
Function API
The discrete time domain representation of the PI algorithms:
Eqn. 7
where,e(n)—Input errory(n)—Controller outputKp—Proportional gainKi—Integral gainyI(n-1)—Previous Integral OutputTs— Sampling Time
Rewriting,
2.2.7 ReturnsThe function PCLIB_ControllerPI returns a fractional value as a result of the PI algorithm. The value returned by the algorithm is in the following range:
ƒ16LowerLimit ≤ PIresult ≤ ƒ16UpperLimit
2.2.8 Range issuesThe PI controller parameters are in the following range
0 ≤ ƒ16PropGain < 10 ≤ ƒ16IntegGain < 1 -1 ≤ ƒ16IntegUpperLimit < 1 -1 ≤ ƒ16IntegLowerLimit < 1 -1 ≤ ƒ16UpperLimit < 1 -1 ≤ ƒ16UpperLimit < 1
2.2.9 Special issuesThe function PCLIB_ControllerPI is saturation mode independent.
y n( ) Kp e n( )× yI+ n 1–( ) Ki Ts e n( )××+=
y n( ) Kp e n( )× yI+ n 1–( ) KI+ e n( )×=
KI Ki Ts×=
Power Control Library, Rev. 0
10 Freescale Semiconductor
Function API
2.2.10 ImplementationExample 1. Implementation Code
#include "pclib.h"
static Frac16 pf16DesiredValue; static Frac16 pf16MeasuredValue; static Frac16 pf16Error;
static Frac16 pf16ControllerOutput;
/* Controller parameters */
static PCLIB_CONTROL_PI_PARAMS_T pudtControllerParam;
void Isr(void);
void main(void)
{
/* Controller parameters initialization */ pudtControllerParam.f16PropGain = FRAC16(0.5); pudtControllerParam.f16IntegGain = FRAC16(0.032);
pudtControllerParam.f16IntegUpperLimit = FRAC16(0.9);
pudtControllerParam.f16IntegLowerLimit = FRAC16(-0.1);
pudtControllerParam.f16IntegOutputN_1 = 0; pudtControllerParam.f16UpperLimit = FRAC16(0.8); pudtControllerParam.f16LowerLimit = FRAC16(-0.7);
/* Desired value initialization */
pf16DesiredValue = FRAC16(0.5);
/* Measured value initialization */
pf16MeasuredValue = 0;
/* Error value initialization */
pf16Error = 0;
/* Controller Output value initialization */
pf16ControllerOutput = 0;
}
/* Periodical function or interrupt */
void Isr(void)
{
/* Error calculation */
Power Control Library, Rev. 0
Freescale Semiconductor 11
Function API
pf16Error = pf16DesiredValue - pf16MeasuredValue;
/* Controller calculation */
pf16ControllerOutput = PCLIB_ControllerPI(pf16Error,
&pudtControllerParam);
}
2.2.11 Performance
2.3 PCLIB_ControllerPI plus low pass filterThe function calculates the Proportional Integral with low pass filter algorithm.
2.3.1 Synopsis#include ”pclib.h”
Frac16 PCLIB_ControllerPIANDLPFILTER(Frac16 f16Error, PCLIB_CONTROL_PIANFLPFILTER_PARAMS_T * const pudtCtrl)
2.3.2 Prototypeasm Frac16 PCLIB_ControllerPIANDLPFILTER (Frac16 f16Error, PCLIB_CONTROL_PIANDLPFILTER_PARAMS_T * const pudtControlStruct)
Table 5. Performance of PCLIB_ControllerPI function
Code Size (words) 21
Data Size (words) 0
Execution ClockMin 42 cycles
Max 42 cycles
Power Control Library, Rev. 0
12 Freescale Semiconductor
Function API
2.3.3 Arguments
2.3.4 AvailabilityThis library module is available in the C-callable interface assembly format. This library module is targeted for 56800E and 56800Ex platform.
Table 6. Function arguments
Name In/Out Format Range Description
f16Error In SF16 0x8000...0x7FFF Error as input argument; the Frac16 data type is defined in header file 56800E_types.h
* const pudtControlStruct
In/Out struct N/A Pointer to a structure of PI controller parameters; the PCLIB_CONTROL_PIANDLPFILTER_ PARAMS_T data type is defined in the header file PCLIB_ControllerPIandLPfilterAsm.h
Table 7. User type definitions
Typedef Name In/Out Format Range Description
PCLIB_CONTROL_PIANDLPFILTER_PARAMS_T
f16Coeff_b0 In SF16 0x8000...0x7FFF Control coefficients for present error
f16Coeff_b1 In SF16 0x8000...0x7FFF Control coefficients for past error
f16Coeff_b2 In SF16 0x8000...0x7FFF Control coefficients for past to past error
f16Coeff_a1 In SF16 0x8000...0x7FFF Control coefficients for past outputs
f16Coeff_a2 In SF16 0x8000...0x7FFF Control coefficients for past to past outputs
f16Delay_x1 In/Out SF16 0x8000...0x7FFF Controller delay parameter, past error
f16Delay_x2 In/Out SF16 0x8000...0x7FFF Controller delay parameter, past to past error
f16Delay_y1 In/Out SF16 0x8000...0x7FFF Controller delay parameter, past result
f16Delay_y2 In/Out SF16 0x8000...0x7FFF Controller delay parameter, past to past result
Power Control Library, Rev. 0
Freescale Semiconductor 13
Function API
2.3.5 DependenciesList of all dependent files:
• PCLIB_ControllerPIandLPfilterAsm.h• 56800E_types.h
2.3.6 DescriptionFor PI with low pass filter,
Eqn. 8
It increases the system performance even at the high frequency (in bode plot frequency domain) of system operations.
This is equivalent to:
Eqn. 9
y(s) is output and x(s) is input to the system. This control law has two pole P1, and P2 and two zero Z1 and Z2. The value or the placement of these poles and zeros in the bode plot decide the stability and performance of the control loop and system.
z-domain controller Gc(z) at Ts sampling frequency using Tustin method:
Eqn. 10
Where, y(t) = y(n)—Present outputy(t) * z-1 = y(n-1)—Previous outputy(t) * z-2 = y(n-2)—Previous to previous outputx(t) = x(n)—Present error
Output KpKis
------+⎝ ⎠⎛ ⎞ s a+
s b+-----------⎝ ⎠
⎛ ⎞×=
y s( )x s( )---------- s Z1–( ) s Z2–( )×
s P1–( ) s P2–( )×----------------------------------------------=
y t( )x t( )--------- b2 z 2–× b1 z 1–× b0+ +( )
1 a2 z 2– a1 z 1–×–×–( )---------------------------------------------------------------=
y t( ) a1 y t( )× z 1–×– a2 y t( ) z 2–××– b0 x t( ) b1 x t( ) z 1–××+× b2 x t( ) z 2–××+=
Power Control Library, Rev. 0
14 Freescale Semiconductor
Function API
x(t) * z-1=x(n-1)—Previous errorx(t) * z-2 = x(n-2)—Previous to previous error
b0, b1, b2, a1, and a2 are the control coefficients and are function of Z1, Z2, P1, P2 and sampling time Ts.
Eqn. 11
2.3.7 ReturnsThe function returns a 16-bit fractional value as a result of the calculation of PI with low pass filter Algorithm.
2.3.8 Range IssuesThe PI with low pass filter controller parameters are in the following range:
-1≤ ƒ16Coeff_b0 ≤ 1-1≤ ƒ16Coeff_b1 ≤ 1 -1 ≤ ƒ16Coeff_b2 ≤ 1 -1 ≤ ƒ16Coeff_a1 ≤ 1 -1 ≤ ƒ16Coeff_a2 ≤ 1
2.3.9 Special IssuesThe function PCLIB_ControllerPIandLPfilter is saturation mode dependent.
2.3.10 ImplementationExample 2. Implementation Code
#include "pclib.h"
static Frac16 pf16DesiredValue; static Frac16 pf16MeasuredValue; static Frac16 pf16Error;
static Frac16 pf16OutControlLoop;
/* Controller parameters */
static PCLIB_CONTROL_PIANDLPFILTER_PARAMS_T pudtControllerParam;
void Isr(void);
y n( ) a1 y n 1–( )× a2 y n 2–( )× b0 x n( )× b1 x n 1–( )× b2 x n 2–( )×+ + + +=
Power Control Library, Rev. 0
Freescale Semiconductor 15
Function API
void main(void)
{
/* Controller parameters initialization */ pudtControllerParam.f16Coeff_b0 = FRAC16(0.5); pudtControllerParam.f16Coeff_b1 = FRAC16(0.032);
pudtControllerParam.f16Coeff_b2 = FRAC16(0.3);
pudtControllerParam.f16Coeff_a1 = FRAC16(-0.1);
pudtControllerParam.f16Coeff_a2 = FRAC16(0.2);
pudtControllerParam.f16Delay_x1 = 0; pudtControllerParam.f16Delay_x2 = 0;
pudtControllerParam.f16Delay_y1 = 0; pudtControllerParam.f16Delay_y2 = 0;
/* Initializing Error */
pf16Error = 0;
/* Initialization of control loop output */
pf16OutControlLoop = 0;
/* Desired value initialization */
pf16DesiredValue = FRAC16(0.5);
/* Measured value initialization */
pf16MeasuredValue = 0;
}
/* Periodical function or interrupt */
void Isr(void)
{
/* Error calculation */
pf16ErrorK = pf16DesiredValue - pf16MeasuredValue;
/* Ramp generation */
pf16OutControlLoop = PCLIB_ControllerPIANDLPFILTERAsm(pf16Error, &pudtControllerParam);
}
Power Control Library, Rev. 0
16 Freescale Semiconductor
Function API
2.3.11 Performance
2.4 PCLIB_ControllerPIDThe function calculates the recurrent form of the Proportional-Integral-Derivative (PID) algorithm.
2.4.1 Synopsis#include ”pclib.h”
Frac16 PCLIB_ControllerPID(Frac16 f16Error, PCLIB_CONTROL_PID_PARAMS_T * const pudtControlStruct)
2.4.2 Prototypeasm Frac16 PCLIB_ControllerPIDFAsm(Frac16 f16Error, PCLIB_CONTROL_PID_RECURRENT_T * const pudtControlStruct)
2.4.3 Arguments
Table 8. Performance of PCLIB_ControllerPIANDLPFILTER function
Code Size (words) 25
Data Size (words) 0
Execution ClockMin 49 cycles
Max 51 cycles
Table 9. Function arguments
Name In/Out Format Range Description
f16Error In SF16 0x8000 ...0x7FFF Error as input argument; the Frac16 data type is defined in header file 56800E_types.h
* const pudtControlStruct
In/Out struct N/A Pointer to a controller structure, which contains controller coefficients and delay lines; the PCLIB_CONTROL_PID_PARAMS_T data type is defined in header file PCLIB_ControllerPIDAsm.h
Power Control Library, Rev. 0
Freescale Semiconductor 17
Function API
2.4.4 AvailabilityThis library module is available in the C-callable interface assembly format. This library module is targeted for 56800E and 56800Ex platform.
2.4.5 DependenciesList of all dependent files:
• PCLIB_ControllerPIDAsm.h• 56800E_types.h
2.4.6 DescriptionPID controller can be shown as:
Table 10. User type definitions
Typedef Name In/Out For-mat
Range Description
PCLIB_CONTROL_PID_PARAMS_T F16ControlOutN_1
In/Out SF16 0x8000...0x7FFF Internal controller accu-mulator
f16KA In SF16 0x8000 ...0x7FFF Control coefficient for present error
f16KB In SF16 0x8000 ...0x7FFF Control coefficient for past error
f16KC In SF16 0x8000 ...0x7FFF Control coefficient for past to past error
f16UpperLimit In SF16 0x8000 ...0x7FFF Control output upper limit
f16LowerLimit In SF16 0x8000 ...0x7FFF Control output lower limit
f16Delay_x1 In/Out SF16 0x8000...0x7FFF Controller delay parame-ter, past error
f16Delay_x2 In/Out SF16 0x8000...0x7FFF Controller delay parame-ter, past to past error
Power Control Library, Rev. 0
18 Freescale Semiconductor
Function API
PID controller has Proportional(Kp), Integral(Ki), and Differential(Kd) coefficients.
The PID controller algorithm in continuous time domain:
Eqn. 12
e(t)—Input error in continuous time domain
y(t)—Control output in continuous time domain
Eqn. 13
It can be futher simplified as:
Eqn. 14
y t( ) Kp e t( )× Ki e t( )× dt( ) Kd de t( )dt
------------×+
0
t
∫+=
Kp e t( )× Kp x t( )×=
Ki e t( ) td
0
t
∫ Ki1 z 1––---------------- x t( )×=
Kd de t( )dt
------------× Kd 1 z 1––( )× x t( )×=
y t( ) Kp Ki Kd+ +( ) x t( )× Kp– 2 Kd×–( ) x t( )× z 1–× Kd x t( )× z 2–×+ +1 z 1––
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------=
Kp Ki Kd+ + KA=
Kp– 2Kd– KB=
Kd KC=
Power Control Library, Rev. 0
Freescale Semiconductor 19
Function API
Rewriting,
Eqn. 15
where,
y(t) = y(n)—Present output
y(t) * z-1 = y(n-1)—Previous output
x(t) = x(n)—Present error
x(t) * z-1 = x(n-1)—previous error
x(t) * z-2 = x(n-2)—previous to previous error
2.4.7 ReturnsThe function returns a 16-bit fractional value as a result of calculation of the PID Algorithm.
2.4.8 Range IssuesThe PID controller parameters are in the following range:
-1≤ ƒ16KA ≤ 1-1≤ ƒ16KB ≤ 1 -1 ≤ ƒ16KC ≤ 1
2.4.9 Special IssuesThe function PCLIB_ControllerPID is saturation mode dependent.
2.4.10 ImplementationExample 3. Implementation Code
#include "pclib.h"
static Frac16 pf16DesiredValue; static Frac16 pf16MeasuredValue; static Frac16 pf16Error;
static Frac16 pf16ControllerOutput;
y t( ) KA x t( )× KB x t( )× z 1–× KC x t( )× z 2–×+ +1 z 1––
------------------------------------------------------------------------------------------------------------------=
y t( ) y t( ) z 1–× KA x t( )× KB x t( )× z 1–× KC x t( )× z 2–×+ + +=
Power Control Library, Rev. 0
20 Freescale Semiconductor
Function API
/* Controller parameters */
static PCLIB_CONTROL_PID_RECURRENT_T pudtControllerParam;
void Isr(void);
void main(void)
{
/* Controller parameters initialization */ pudtControllerParam.f16KA = FRAC16(0.527083333); pudtControllerParam.f16KB = FRAC16(-0.514583333); pudtControllerParam.f16KC = FRAC16(0.414583333); pudtControllerParam.f16UpperLimit = 0; pudtControllerParam.f16LowerLimit = 0; pudtControllerParam.f16ControlOutN_1= 0;
pudtControllerParam.f16Delay_x1= 0; pudtControllerParam.f16Delay_x2= 0;
/* Desired value initialization */
pf16DesiredValue = FRAC16(0.5);
/* Measured value initialization */
pf16MeasuredValue = 0;
}
/* Periodical function or interrupt */
void Isr(void)
{
/* Error calculation */
pf16Error = pf16DesiredValue - pf16MeasuredValue;
/* Controller calculation */
pf16ControllerOutput = PCLIB_ControllerPID(pf16Error,
&pudtControllerParam);
}
Power Control Library, Rev. 0
Freescale Semiconductor 21
Function API
2.4.11 Performance
2.5 PCLIB_Controller2P2ZThe function calculates the 2 pole 2 zero control algorithm.
2.5.1 Synopsis#include ”pclib.h”
Frac16 PCLIB_Controller2P2Z(Frac16 f16Error, PCLIB_CONTROL_2P2Z_PARAMS_T * const pudtCtrl)
2.5.2 Prototypeasm Frac16 PCLIB_Controller2P2ZFAsm(Frac16 f16Error, PCLIB_CONTROL_2P2Z_PARAMS_T * const pudtCtrl)
2.5.3 Arguments
Table 11. Performance of PCLIB_ControllerPID function
Code Size (words) 20
Data Size (words) 0
Execution ClockMin 42 cycles
Max 43 cycles
Table 12. Function arguements
Name Type Format Range Description
f16Error In SF16 0x8000...0x7FFF
Input error at step n processed by 2P_2Z algorithm
* const pudtControlStruct
In/Out N/A N/A Pointer to a structure of 2P_2Z controller parameters; the PCLIB_CONTROL_2P2Z_PARAMS_T data type is defined in the header file PCLIB_Controller2P2ZAsm.h
Table 13. User type definitions
Typedef Name In/Out Format Range Description
PCLIB_CONTROL_2P2Z_PARAMS_T f16Coeff_b0 In SF16 0x8000...0x7FFF Controller coefficient for present error
f16Coeff_b1 In SF16 0x8000 ...0x7FFF Controller coefficient for past error
Power Control Library, Rev. 0
22 Freescale Semiconductor
Function API
2.5.4 AvailabilityThis library module is available in the C-callable interface assembly format. This library module is targeted for 56800E and 56800Ex platform.
2.5.5 DependenciesList of all dependent files:
• PCLIB_Controller2P2ZAsm.h• 56800E_types.h
2.5.6 DescriptionThe s-domain transfer function equation for 2-pole 2-zero control law is:
Eqn. 16
y[s] is output and x[s] is input to the system. This control law has two poles (P1 and P2) and two zeros (Z1 and Z2). The value or the placement of these poles and zeros in the bode plot decide the stability and performance of the control loop and system.
z-domain controller Gc(z) at Ts sampling time using the Tustin method.
f16Coeff_b2 In SF16 0x8000 ...0x7FFF Controller coefficient for past to past error
f16Coeff_a1 In SF16 0x8000 ...0x7FFF Controller coefficient for past result
f16Coeff_a2 In SF16 0x8000 ...0x7FFF Controller coefficient for past to past result
f16Delay_x1 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past error
f16Delay_x2 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past to past error
f16Delay_y1 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past result
f16Delay_y2 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past to past result
Table 13. User type definitions (continued)
y s( )x s( )---------- s Z1–( ) s Z2–( )×
s P1–( ) s P2–( )×----------------------------------------------=
Power Control Library, Rev. 0
Freescale Semiconductor 23
Function API
Eqn. 17
where,
y(t) = y(n)—Present output
y(t) * z-1 = y(n-1)—Previous output
y(t) * z-2 = y(n-2)—Previous to previous output
x(t) = x(n)—Present error
x(t) * z-1 = x(n-1)—Previous error
x(t) * z-2 = x(n-2)—Previous to previous error
b0, b1, b2, a1, and a2 are the control coefficient and are function of Z1, Z2, P1, P2 and sampling time Ts.
Eqn. 18
2.5.7 ReturnsThe function returns a 16-bit fractional value as a result of calculation of 2P_2Z algorithm.
2.5.8 Range IssuesThe 2P_2Z controller parameters are in the following range:
-1≤ ƒ16Coeff_b0 ≤ 0.9999-1≤ ƒ16Coeff_b1 ≤ 0.9999-1 ≤ ƒ16Coeff_b2 ≤ 0.9999-1 ≤ ƒ16Coeff_a1 ≤ 0.9999-1 ≤ ƒ16Coeff_a2 ≤ 0.9999
y t( )x t( )--------- b2 z 2–× b1 z 1–× b0+ +( )
1 a2 z 2– a1 z 1–×–×–( )---------------------------------------------------------------=
y t( ) a1 y t( )× z 1–×– a2 y t( )× z 2–×– b0 x t( )× b1 x t( )× z 1–× b2 x t( )× z 2–×+ +=
y n( ) a2 y n 2–( )× a1 y n 1–( )× b2 x n 2–( )× b1 x n 1–( )× b0 x n( )×+ + + +=
Power Control Library, Rev. 0
24 Freescale Semiconductor
Function API
2.5.9 Special IssuesThe function PCLIB_Controller2P2Z is saturation mode dependent.
2.5.10 ImplementationExample 4. Implementation Code
#include "pclib.h"
static Frac16 pf16DesiredValue; static Frac16 pf16MeasuredValue; static Frac16 pf16ErrorK;
static Frac16 pf16ControllerOutput;
/* Controller parameters */
static PCLIB_CONTROL_2P_2Z_PARAMS_T pudtControllerParam;
void Isr(void);
void main(void)
{
/* Controller parameters initialization */ pudtControllerParam.f16Coeff_b0 = FRAC16(0.527083); pudtControllerParam.f16Coeff_b1 = FRAC16(-0.51458); pudtControllerParam.f16Coeff_b2 = FRAC16(0.31458); pudtControllerParam.f16Coeff_a1 = FRAC16(0.5); pudtControllerParam.f16Coeff_a2 = FRAC16(-0.4);
/* Desired value initialization */
pf16DesiredValue = FRAC16(0.5);
/* Measured value initialization */
pf16MeasuredValue = 0;
}
/* Periodical function or interrupt */
void Isr(void)
{
/* Error calculation */
pf16ErrorK = pf16DesiredValue - pf16MeasuredValue;
Power Control Library, Rev. 0
Freescale Semiconductor 25
Function API
/* Controller calculation */
pf16ControllerOutput = PCLIB_Controller2P2Z(pf16ErrorK,
&pudtControllerParam);
}
2.5.11 Performance
2.6 PCLIB_Controller3P3ZThe function calculates the 3 pole 3 zero control algorithm.
2.6.1 Synopsis#include ”pclib.h”
Frac16 PCLIB_Controller3P3Z(Frac16 f16Error, PCLIB_CONTROL_3P3Z_ PARAMS_T * const pudControlStruct)
2.6.2 Prototypeasm Frac16 PCLIB_Controller3P3ZFAsm(Frac16 f16Error, PCLIB_CONTROL_3P3Z_PARAMS_T * const pudControlStruct)
Table 14. Performance of PCLIB_Controller2P2Z function
Code Size (words) 25
Data Size (words) 0
Execution ClockMin 49 cycles
Max 51 cycles
Power Control Library, Rev. 0
26 Freescale Semiconductor
Function API
2.6.3 Arguments
Table 15. Function arguments
Name Type Format Range Description
f16Error In SF16 0x8000...0x7FFF Input error processed by 3 Pole 3 Zero algorithm
* const pudControlStruct
In/Out N/A N/A Pointer to a structure of 3pole 3zero controller parameters; the PCLIB_CONTROL_3P3Z_PARAMS_T data type is defined in header file PCLIB_Controller3P3ZAsm.h
Table 16. User type definitions
Typedef Name In/Out Format Range Description
PCLIB_CONTROL_3P3Z_PARAMS_T f16Coeff_b0 In SF16 0x8000...0x7FFF Controller coefficient for present error
f16Coeff_b1 In SF16 0x8000 ...0x7FFF Controller coefficient for past error
f16Coeff_b2 In SF16 0x8000 ...0x7FFF Controller coefficient for past to past error
f16Coeff_b3 In SF16 0x8000 ...0x7FFF Controller coefficient for past to past to past error
f16Coeff_a1 In SF16 0x8000 ...0x7FFF Controller coefficient for past result
f16Coeff_a2 In SF16 0x8000 ...0x7FFF Controller coefficient for past to past result
f16Coeff_a3 In SF16 0x8000 ...0x7FFF Controller coefficient for past to past to past result
f16Delay_x1 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past error
f16Delay_x2 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past to past error
f16Delay_x3 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past to past to past error
f16Delay_y1 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past result
f16Delay_y2 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past to past result
f16Delay_y3 In/Out SF16 0x8000 ...0x7FFF Controller delay parameter, past to past to past result
Power Control Library, Rev. 0
Freescale Semiconductor 27
Function API
2.6.4 AvailabilityThis library module is available in the C-callable interface assembly format. This library module is targeted for 56800E and 56800Ex platform.
2.6.5 DependenciesList of all dependent files:
• PCLIB_Controller3P3ZAsm.h• 56800E_types.h
2.6.6 DescriptionThe PCLIB_Controller3P3Z function calculates the 3pole 3zero algorithm according to the equations below.
The s-domain transfer function equation for 3-pole 3-zero control law is:
Eqn. 19
y[s] is output and x[s] is input to the system. This control law has three poles P1, P2, and P3 and three zeros Z1, Z2, and Z3. The value or the placement of these poles and zeros in the bode plot decide the stability and performance of the control loop and system.
z-domain controller Gc(z) at Ts sampling time using the Tustin method.
Eqn. 20
where,
y(t) = y(n)—Present output
y(t) * z-1 = y(n-1)—Previous output
y(t) * z-2 = y(n-2)—Previous to previous output
y(t) * z-3 = y(n-3)—Previous to previous to previous output
y s( )x s( )---------- s Z1–( ) s Z2–( )× s Z3–( )×
s P1–( ) s P2–( )× s P3–( )×-------------------------------------------------------------------------=
y t( )x t( )--------- b3 z 3–× b2 z 2–× b1 z 1–× b0+ + +( )
1 a3 z 3– a2 z 2– a1 z 1–×–×–×–------------------------------------------------------------------------------------------=
y t( ) al y t( )× z 1– a2 y t( )×–× z 2–×– a3 y t( )× z 3–×– b0 x t( )× b1 x t( )× z 1–× b2 x t( )× z 2–× b3 x t( )× z 3–×+ + +=
Power Control Library, Rev. 0
28 Freescale Semiconductor
Function API
x(t) = x(n)—Present error
x(t) * z-1 = x(n-1)—Previous error
x(t) * z-2 = x(n-2)—Previous to previous error
x(t) * z-3 = x(n-3)—Previous to previous to previous error
b0, b1, b2, b3, a1, a2, and a3 are the control coefficient and are function of Z1, Z2, Z3, P1, P2, P3 and sampling time Ts.
Eqn. 21
2.6.7 ReturnsThe function returns a 16-bit fractional value as a result of calculation of 3P_3Z algorithm.
2.6.8 Range IssuesThe 3P3Z controller parameters are in the following range:
–1 ≤ f16Coeff_b0≤ 0.9999–1 ≤ f16Coeff_b1≤ 0.9999–1 ≤ f16Coeff_b2≤ 0.9999–1 ≤ f16Coeff_b3≤ 0.9999–1 ≤ f16Coeff_a1≤0.9999 –1≤ f16Coeff_a2≤ 0.9999–1 ≤ f16Coeff_a3≤ 0.9999
2.6.9 Special IssuesThe function PCLIB_Controller3P3Z is saturation mode dependent.
2.6.10 ImplementationExample 5. Implementation Code
#include "pclib.h"
static Frac16 pf16DesiredValue; static Frac16 pf16MeasuredValue; static Frac16 pf16ErrorK;
static Frac16 mf16ControllerOutput;
y n( ) a3 y n 3–( )× a2 y n 2–( )× a1 y n 1–( )× b3 x n 3–( )× b2 x n 2–( )× b1 x n 1–( )× b0 x n( )×+ + + + + +=
Power Control Library, Rev. 0
Freescale Semiconductor 29
Function API
/* Controller parameters */
static PCLIB_CONTROL_3P3Z_PARAMS_T pudtControllerParam;
void Isr(void);
void main(void)
{
/* Controller parameters initialization */ pudtControllerParam.f16Coeff_b0=FRAC16(0.527083); pudtControllerParam.f16Coeff_b1=FRAC16(-0.51458); pudtControllerParam.f16Coeff_b2=FRAC16(0.31458);
pudtControllerParam.f16Coeff_b3=FRAC16(0.2145); pudtControllerParam.f16Coeff_a1=FRAC16(0.5); pudtControllerParam.f16Coeff_a2=FRAC16(-0.4);
pudtControllerParam.f16Coeff_a3=FRAC16(0.43458);
/* Desired value initialization */
pf16DesiredValue = FRAC16(0.5);
/* Measured value initialization */
pf16MeasuredValue = 0;
}
/* Periodical function or interrupt */
void Isr(void)
{
/* Error calculation */
mf16ErrorK = mf16DesiredValue - mf16MeasuredValue;
/* Controller calculation */
mf16ControllerOutput = PCLIB_Controller3P3Z(pf16ErrorK, &pudtControllerParam);
Power Control Library, Rev. 0
30 Freescale Semiconductor
Revision history
2.6.11 Performance
3 Revision history
Table 17. Performance of PCLIB_Controller3P3Z Function
Code Size (words) 29
Data Size (words) 0
Execution ClockMin 55 cycles
Max 55 cycles
Table 3-18. Revision history
Date Revision Number Description
04/2014 0 Initial release.
Document Number: 56800Ex_PCLIBRev. 004/2014
Information in this document is provided solely to enable system and software
implementers to use Freescale products. There are no express or implied copyright
licenses granted hereunder to design or fabricate any integrated circuits based on the
information in this document.
Freescale reserves the right to make changes without further notice to any products
herein. Freescale makes no warranty, representation, or guarantee regarding the
suitability of its products for any particular purpose, nor does Freescale assume any
liability arising out of the application or use of any product or circuit, and specifically
disclaims any and all liability, including without limitation consequential or incidental
damages. “Typical” parameters that may be provided in Freescale data sheets and/or
specifications can and do vary in different applications, and actual performance may
vary over time. All operating parameters, including “typicals,” must be validated for
each customer application by customer’s technical experts. Freescale does not convey
any license under its patent rights nor the rights of others. Freescale sells products
pursuant to standard terms and conditions of sale, which can be found at the following
address: freescale.com/SalesTermsandConditions.
How to Reach Us:Home Page: freescale.com
Web Support: freescale.com/support
Freescale, the Freescale logo, and Kinetis are trademarks of Freescale
Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off. All other product or service names are
the property of their respective owners.
© 2014 Freescale Semiconductor, Inc.