Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Adaptive Gain Control Example
v_loop_agc.s
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)
4 ; Author: M91406
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 ; **********************************************************************************
9 
10 ;------------------------------------------------------------------------------
11 ;file start
12  .nolist
13  .list
14 
15 ;------------------------------------------------------------------------------
16 ;local inclusions.
17  .section .data ; place constant data in the data section
18 
19  ; include NPNZ16b_t object data structure value offsets and status flag labels
20  .include "./sources/power_control/drivers/npnz16b.inc"
21 
22 ;------------------------------------------------------------------------------
23 ;local variables.
24 
25  .section .bss
26  ; no variables declared
27 
28 ;------------------------------------------------------------------------------
29 ;code section.
30  .section .text ; place code in the code section
31 
32 ;------------------------------------------------------------------------------
33 ; Global function declaration
34 ; This function calls the z-domain controller processing the latest data point input
35 ;------------------------------------------------------------------------------
36 
37  .global _v_loop_AGCFactorUpdate
38 _v_loop_AGCFactorUpdate:
39 
40  nop ; (debugging break point anchor)
41 
42  ; determine most recent VL
43 
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
52 
53  ; read output voltage
54  mov [w0 + #ptrSourceRegister], w2 ; load pointer to most recent output voltage register
55  mov [w2], w2 ; load value into w2
56 
57  ; Calculate instantaneous VL
58  sub w1, w2, w5 ; calculate most recent VL, place result in w5
59 
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
67 
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
73 
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
78  ; resolution.
79  ; ----------------------------------------------------------------------------------
80 
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
84 
85 ;------------------------------------------------------------------------------
86 ; End of routine
87  return
88 ;------------------------------------------------------------------------------
89 
90 ;------------------------------------------------------------------------------
91 ; End of file
92  .end
93 ;------------------------------------------------------------------------------
94 
95