![Microchip Technology AN908 Using Manual Download Page 58](http://html1.mh-extra.com/html/microchip-technology/an908/an908_using-manual_1785807058.webp)
AN908
DS00908A-page 58
2004 Microchip Technology Inc.
MeasCur.s
;*******************************************************************
; MeasCompCurr
;
;Description:
; Read Channels 1 & 2 of ADC, scale them as signed fractional values
; using qKa, qKb and put the results qIa and qIb of ParkParm.
; Running average value of ADC-Ave is maintained and subtracted from
; ADC value before scaling.
;
; Specifically the offset is accumulated as a 32 bit signed integer
;
i= (ADC-Offset)
; and is used to correct the raw ADC by
;
CorrADC = ADCBUFn - iOffset/2^16
; which gives an offset time constant of ~ MeasurementPeriod*2^16
;
; Do not call this routine until conversion is completed.
;
; Scaling constant, qKa and qKb, must be set elsewhere such that
;
qIa = 2 * qKa * CorrADC1
;
qIb = 2 * qKb * CorrADC2
; The factor of 2 is designed to allow qKa & qKb to be given in 1.15.
;
;
;Functional prototypes:
; void MeasCompCurr( void );
; void InitMeasCompCurr( short iOffset_a, short iOffset_b );
;
;On Start: Must call InitMeasCompCurr.
;
;On Entry: MeasCurrParm structure must contain qKa & qKb. ADC channels 1 & 2
; must contain signed fractional value.
;
;On Exit: ParkParm will contain qIa & qIb.
;
;Parameters:
; Input arguments: None
;
; Return:
; Void
;
; SFR Settings required:
; CORCON.SATA = 0
; If there is any chance that Accumulator will overflow must set
; CORCON.SATDW = 1
;
; Support routines required: None
;
; Local Stack usage: None
;
; Registers modified: w0,w1,w4,w5
;
; Timing: 29 cycles
;
;*******************************************************************
.include "general.inc"
; External references
.include "MeasCurr.inc"
.include "Park.inc"