2 ; **********************************************************************************
3 ; SDK Version: z-Domain Control Loop Designer v0.9.9.312
4 ; AGS Version: Assembly Generator Script v2.0.16 (07/22/2020)
6 ; Date/Time: 07/23/2020 3:26:49 PM
7 ; **********************************************************************************
8 ; 3P3Z Control Library File (Fast Floating Point Coefficient Scaling Mode)
9 ; **********************************************************************************
11 ;------------------------------------------------------------------------------
16 ;------------------------------------------------------------------------------
18 .section .data ; place constant data in the data section
20 ; include NPNZ16b_t object data structure value offsets and status flag labels
21 .include "./sources/power_control/drivers/npnz16b.inc"
23 ;------------------------------------------------------------------------------
27 ; no variables declared
29 ;------------------------------------------------------------------------------
31 .section .text ; place code in the code section
33 ;------------------------------------------------------------------------------
34 ; Global function declaration
35 ; This function calls the z-domain controller processing the latest data point input
36 ;------------------------------------------------------------------------------
38 .global _v_loop_AGCFactorUpdate
39 _v_loop_AGCFactorUpdate:
41 nop ; (debugging break point anchor)
43 ; determine most recent VL
45 ; read and normalize input voltage (normalize to output voltage, not absolute!)
46 mov [w0 + #ptrAltSourceRegister], w1 ; load pointer to most recent input voltage register
47 mov [w1], w4 ; load value into w1
48 mov [w0 + usrParam2], w5 ; load Q15 factor of input-2-output voltage normalization
49 mpy w4*w5, b ; multiply ADC reading of input voltage with normalization factor
50 mov [w0 + usrParam1], w2 ; load bit-shift scaler of input-2-output voltage normalization factor
51 sftac b, w2 ; shift result by input voltage normalization scaler
52 sac.r b, w1 ; store most recent accumulator result in working register
55 mov [w0 + #ptrSourceRegister], w2 ; load pointer to most recent output voltage register
56 mov [w2], w2 ; load value into w2
58 ; Calculate instantaneous VL
59 sub w1, w2, w5 ; calculate most recent VL, place result in w5
61 ; Load modulation median
62 mov [w0 + #AgcMedian], w4 ; load pointer to nominal VL
63 ; ToDo: Remove - AGC Median is a constant value and so is factor scaling
64 ; (no need to calculate at runtime)
65 ; mov [w0 + #agcGainModScaler], w2 ; load AGC factor scaler
66 ; neg w2, w2 ; invert sign of AGC factor scaler
67 ; asr w4, w2, w4 ; shift AGC median by factor scaler
69 ; Divide median by instatneous VL
70 push.s ; Save pointer to NPNZ16b_t data structure
71 repeat #5 ; run divide in 6 steps
72 divf w4, w5 ; divide VL_nom/VL
73 mov w0, w4 ; move result to w4
75 ; ----------------------------------------------------------------------------------
76 ; ToDo: Possible improvement would be to find first bit from left and pack result in
77 ; factor and scaler. This doesn't work due to number format of division result
78 ; and remainer. Packing result as floating point won't increase number
80 ; ----------------------------------------------------------------------------------
82 pop.s ; restore pointer to NPNZ16b_t data structure
83 mov w4, [w0 + #AgcFactor] ; load result into NPNZ16b_t data structure
84 ; for further processing
86 ;------------------------------------------------------------------------------
89 ;------------------------------------------------------------------------------
91 ;------------------------------------------------------------------------------
94 ;------------------------------------------------------------------------------