![Microchip Technology AN908 Using Manual Download Page 62](http://html1.mh-extra.com/html/microchip-technology/an908/an908_using-manual_1785807062.webp)
AN908
DS00908A-page 62
2004 Microchip Technology Inc.
PI.s
;*******************************************************************
; PI
;
;Description: Calculate PI correction.
;
;void CalcPI( tPIParm *pParm)
;{
;
Err = InRef - InMeas
;
U = Sum + Kp * Err
;
if( U > Outmax )
;
Out = Outmax
;
else if( U < Outmin )
;
Out = Outmin
;
else
;
Out = U
;
Exc = U - Out
;
Sum = Sum + Ki * Err - Kc * Exc
;}
;
;void InitPI( tPIParm *pParm)
;{
;
Sum = 0
;
Out = 0
;}
;
;----------------------------
; Representation of PI constants:
; The constant Kp is scaled so it can be represented in 1.15 format by
; adjusting the constant by a power of 2 which is removed when the
; calculation is completed.
;
; Kp is scaled Kp = qKp * 2^NKo
;
; Ki & Kc are scaled Ki = qKi, Kc = qKc
;
;
;Functional prototype:
;
; void InitPI( tPIParm *pParm)
; void CalcPI( tPIParm *pParm)
;
;On Entry: PIParm structure must contain qKp,qKi,qKc,qOutMax,qOutMin,
;
InRef,InMeas
;On Exit:
PIParm will contain qOut
;
;Parameters:
; Input arguments: tPIParm *pParm
;
; Return:
;
Void
;
; SFR Settings required:
;
CORCON.SATA= 0
;
CORCON.IF
= 0
;
; Support routines required: None
; Local Stack usage:
0
; Registers modified: w0-w6,AccA
;
; Timing:
; 31 instruction cycles max, 28 cycles min
;*******************************************************************