1 ; **********************************************************************************
2 ; SDK Version: PowerSmartâ„¢ Digital Control Library Designer v0.9.12.672
3 ; CGS Version: Code Generator Script v3.0.6 (02/03/2021)
5 ; Date/Time: 02/23/2021 15:45:42
6 ; **********************************************************************************
7 ; Adaptive Gain Control (AGC) Observer Code calculating the AGC modulation factor k_agc
8 ; **********************************************************************************
10 ;------------------------------------------------------------------------------
15 ;------------------------------------------------------------------------------
17 .section .data ; place constant data in the data section
19 ; include NPNZ16b_t object data structure value offsets and status flag labels
20 .include "./sources/power_control/drivers/npnz16b.inc"
22 ;------------------------------------------------------------------------------
26 ; no variables declared
28 ;------------------------------------------------------------------------------
30 .section .text ; place code in the code section
32 ;------------------------------------------------------------------------------
33 ; Global function declaration
34 ; This function calls the z-domain controller processing the latest data point input
35 ;------------------------------------------------------------------------------
37 .global _v_loop_AGCFactorUpdate
38 _v_loop_AGCFactorUpdate:
40 nop ; (debugging break point anchor)
42 ; determine most recent VL
44 ; read and normalize input voltage (normalize to output voltage, not absolute!)
45 mov [w0 + #ptrAltSourceRegister], w1 ; load pointer to most recent input voltage register
46 mov [w1], w4 ; load value into w1
47 mov [w0 + usrParam1], w5 ; load Q15 factor of input-2-output voltage normalization
48 mpy w4*w5, b ; multiply ADC reading of input voltage with normalization factor
49 mov [w0 + usrParam0], w2 ; load bit-shift scaler of input-2-output voltage normalization factor
50 sftac b, w2 ; shift result by input voltage normalization scaler
51 sac.r b, w1 ; store most recent accumulator result in working register
54 mov [w0 + #ptrSourceRegister], w2 ; load pointer to most recent output voltage register
55 mov [w2], w2 ; load value into w2
57 ; Calculate instantaneous VL
58 sub w1, w2, w5 ; calculate most recent VL, place result in w5
60 ; Load modulation median
61 mov [w0 + #AgcMedian], w4 ; load pointer to nominal VL
62 ; ToDo: Remove - AGC Median is a constant value and so is factor scaling
63 ; (no need to calculate at runtime)
64 ; mov [w0 + #agcGainModScaler], w2 ; load AGC factor scaler
65 ; neg w2, w2 ; invert sign of AGC factor scaler
66 ; asr w4, w2, w4 ; shift AGC median by factor scaler
68 ; Divide median by instatneous VL
69 push.s ; Save pointer to NPNZ16b_t data structure
70 repeat #5 ; run divide in 6 steps
71 divf w4, w5 ; divide VL_nom/VL_inst
72 mov w0, w4 ; move result to w4
74 ; ----------------------------------------------------------------------------------
75 ; ToDo: Possible improvement would be to find first bit from left and pack result in
76 ; factor and scaler. This doesn't work due to number format of division result
77 ; and remainer. Packing result as floating point won't increase number
79 ; ----------------------------------------------------------------------------------
81 pop.s ; restore pointer to NPNZ16b_t data structure
82 mov w4, [w0 + #AgcFactor] ; load result into NPNZ16b_t data structure
83 ; for further processing
85 ;------------------------------------------------------------------------------
88 ;------------------------------------------------------------------------------
90 ;------------------------------------------------------------------------------
93 ;------------------------------------------------------------------------------