EPC9143 300 W 16th Brick DC/DC Module Reference Design
v_loop_asm.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/17/2021 10:08:26
6 ; **********************************************************************************
7 ; 4P4Z Control Library File (Dual Bitshift-Scaling Mode)
8 ; **********************************************************************************
9 
10 ;------------------------------------------------------------------------------
11 ;file start
12  .nolist ; (no external dependencies)
13  .list ; list of all external dependencies
14 
15 ;------------------------------------------------------------------------------
16 ;local inclusions.
17  .section .data ; place constant data in the data section
18 
19 ;------------------------------------------------------------------------------
20 ; Define status flags bit positions
21  .equ NPNZ16_STATUS_ENABLED, 15 ; bit position of the ENABLE control bit
22  .equ NPNZ16_STATUS_INVERT_INPUT, 14 ; bit position of the INVERT_INPUT control bit
23  .equ NPNZ16_STATUS_SWAP_SOURCE, 13 ; bit position of the SWAP_SOURCE control bit
24  .equ NPNZ16_STATUS_SWAP_TARGET, 12 ; bit position of the SWAP_TARGET control bit
25  .equ NPNZ16_STATUS_AGC_ENABLED, 11 ; bit position of the AGC_ENABLED control bit
26  .equ NPNZ16_STATUS_USAT, 1 ; bit position of the UPPER_SATURATION_FLAG status bit
27  .equ NPNZ16_STATUS_LSAT, 0 ; bit position of the LOWER_SATURATION_FLAG status bit
28 
29 ;------------------------------------------------------------------------------
30 ; NPNZ16b_s data structure address offset declarations for data structure addressing
31  .equ Status, 0 ; controller object status word at address-offset = 0
32  .equ ptrSourceRegister, 2 ; parameter group Ports.Source: pointer to source memory address
33  .equ SourceNormShift, 4 ; parameter group Ports.Source: bit-shift scaler of normalization factor
34  .equ SourceNormFactor, 6 ; parameter group Ports.Source: Q15 normalization factor
35  .equ SourceOffset, 8 ; parameter group Ports.Source: value of source input signal/value offset
36  .equ ptrAltSourceRegister, 10 ; parameter group Ports.AltSource: pointer to alternate source memory address
37  .equ AltSourceNormShift, 12 ; parameter group Ports.AltSource: bit-shift scaler of normalization factor
38  .equ AltSourceNormFactor, 14 ; parameter group Ports.AltSource: Q15 normalization factor
39  .equ AltSourceOffset, 16 ; parameter group Ports.AltSource: value of alternate source input signal/value offset
40  .equ ptrTargetRegister, 18 ; parameter group Ports.Target: pointer to target memory address
41  .equ TargetNormShift, 20 ; parameter group Ports.Target: bit-shift scaler of normalization factor
42  .equ TargetNormFactor, 22 ; parameter group Ports.Target: Q15 normalization factor
43  .equ TargetOffset, 24 ; parameter group Ports.Target: value of target output signal/value offset
44  .equ ptrAltTargetRegister, 26 ; parameter group Ports.AltTarget: pointer to alternate target memory address
45  .equ AltTargetNormShift, 28 ; parameter group Ports.AltTarget: bit-shift scaler of normalization factor
46  .equ AltTargetNormFactor, 30 ; parameter group Ports.AltTarget: Q15 normalization factor
47  .equ AltTargetOffset, 32 ; parameter group Ports.AltTarget: value of alternate target output signal/value offset
48  .equ ptrControlReference, 34 ; parameter group Ports.ConrolReference: pointer to control reference variable/register memory address
49  .equ ptrACoefficients, 36 ; parameter group Filter: pointer to A-coefficients array start address
50  .equ ptrBCoefficients, 38 ; parameter group Filter: pointer to B-coefficients array start address
51  .equ ptrControlHistory, 40 ; parameter group Filter: pointer to control history array start address
52  .equ ptrErrorHistory, 42 ; parameter group Filter: pointer to error history array start address
53  .equ ACoefficientsArraySize, 44 ; parameter group Filter: size of the A-coefficients array
54  .equ BCoefficientsArraySize, 46 ; parameter group Filter: size of the B-coefficients array
55  .equ ControlHistoryArraySize, 48 ; parameter group Filter: size of the control history array
56  .equ ErrorHistoryArraySize, 50 ; parameter group Filter: size of the error history array
57  .equ normPreShift, 52 ; parameter group Filter: value of input value normalization bit-shift scaler
58  .equ normPostShiftA, 54 ; parameter group Filter: value of A-term normalization bit-shift scaler
59  .equ normPostShiftB, 56 ; parameter group Filter: value of B-term normalization bit-shift scaler
60  .equ normPostScaler, 58 ; parameter group Filter: control loop output normalization factor
61  .equ PTermScaler, 60 ; parameter group Filter: P-Term coefficient scaler
62  .equ PTermFactor, 62 ; parameter group Filter: P-Term coefficient fractional factor
63  .equ AgcScaler, 64 ; parameter group GainControl: bit-shift scaler of Adaptive Gain Control Modulation factor
64  .equ AgcFactor, 66 ; parameter group GainControl: Q15 value of Adaptive Gain Control Modulation factor
65  .equ AgcMedian, 68 ; parameter group GainControl: Q15 value of Adaptive Gain Control Modulation nominal operating point
66  .equ ptrAgcObserverFunction, 70 ; parameter group GainControl: function pointer to observer function updating the AGC modulation factor
67  .equ MinOutput, 72 ; parameter group Limits: minimum clamping value of primary control output
68  .equ MaxOutput, 74 ; parameter group Limits: maximum clamping value of primary control output
69  .equ AltMinOutput, 76 ; parameter group Limits: minimum clamping value of alternate control output
70  .equ AltMaxOutput, 78 ; parameter group Limits: maximum clamping value of alternate control output
71  .equ ptrADCTriggerARegister, 80 ; parameter group ADCTriggerControl: pointer to ADC trigger A register memory address
72  .equ ADCTriggerAOffset, 82 ; parameter group ADCTriggerControl: value of ADC trigger A offset
73  .equ ptrADCTriggerBRegister, 84 ; parameter group ADCTriggerControl: pointer to ADC trigger B register memory address
74  .equ ADCTriggerBOffset, 86 ; parameter group ADCTriggerControl: value of ADC trigger B offset
75  .equ ptrDProvControlInput, 88 ; parameter group DataProviders: pointer to external variable/register the most recent, raw control input will be pushed to
76  .equ ptrDProvControlInputComp, 90 ; parameter group DataProviders: pointer to external variable/register the most recent, compensated control input will be pushed to
77  .equ ptrDProvControlError, 92 ; parameter group DataProviders: pointer to external variable/register the most recent control error will be pushed to
78  .equ ptrDProvControlOutput, 94 ; parameter group DataProviders: pointer to external variable/register the most recent control output will be pushed to
79  .equ ptrExtHookStartFunction, 96 ; parameter group ExtensionHooks: pointer to external extension function which will be called by this controller at the beginning after evaluating the enable flag. This function call will be bypassed when the controller is disabled.
80  .equ ExtHookStartFunctionParam, 98 ; parameter group ExtensionHooks: 16-bit wide function parameter variable or pointer to a parameter variable or data structure of extension function
81  .equ ptrExtHookSourceFunction, 100 ; parameter group ExtensionHooks: pointer to external extension function which will be called by this controller after the most recent controller input has been read and compensated but before the most recent error is calculated.
82  .equ ExtHookSourceFunctionParam, 102 ; parameter group ExtensionHooks: 16-bit wide function parameter variable or pointer to a parameter variable or data structure of extension function
83  .equ ptrExtHookPreAntiWindupFunction, 104 ; parameter group ExtensionHooks: pointer to external extension function which will be called by this controller after the most recent compensation filter result has been computed and before anti-windup clamping is applied
84  .equ ExtHookPreAntiWindupFunctionParam, 106 ; parameter group ExtensionHooks: 16-bit wide function parameter variable or pointer to a parameter variable or data structure of extension function
85  .equ ptrExtHookTargetFunction, 108 ; parameter group ExtensionHooks: pointer to external extension function which will be called by this controller before the most recent controller output is written to target, after the value has passed through anti-windup clamping.
86  .equ ExtHookTargetFunctionParam, 110 ; parameter group ExtensionHooks: 16-bit wide function parameter variable or pointer to a parameter variable or data structure of extension function
87  .equ ptrExtHookStopFunction, 112 ; parameter group ExtensionHooks: pointer to external extension function which will be called by this controller after the compensation loop computation has been completed. This function call will be bypassed when the controller is disabled.
88  .equ ExtHookStopFunctionParam, 114 ; parameter group ExtensionHooks: 16-bit wide function parameter variable or pointer to a parameter variable or data structure of extension function
89  .equ ptrExtHookEndFunction, 116 ; parameter group ExtensionHooks: pointer to external extension function which will be called by this controller after the compensation loop computation has been completed, regardless of the loop execution being bypassed or not
90  .equ ExtHookEndFunctionParam, 118 ; parameter group ExtensionHooks: 16-bit wide function parameter variable or pointer to a parameter variable or data structure of extension function
91  .equ usrParam0, 120 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #1 for user-defined, advanced control options
92  .equ usrParam1, 122 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #2 for user-defined, advanced control options
93  .equ usrParam2, 124 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #3 for user-defined, advanced control options
94  .equ usrParam3, 126 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #4 for user-defined, advanced control options
95  .equ usrParam4, 128 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #5 for user-defined, advanced control options
96  .equ usrParam5, 130 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #6 for user-defined, advanced control options
97  .equ usrParam6, 132 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #7 for user-defined, advanced control options
98  .equ usrParam7, 134 ; parameter group Advanced: generic 16-bit wide, user-defined parameter #8 for user-defined, advanced control options
99 
100 ;------------------------------------------------------------------------------
101 ;source code section.
102  .section .text ; place code in the text section
103 
104 ;------------------------------------------------------------------------------
105 ; Global function declaration
106 ; This function calls the z-domain controller processing the latest data point input
107 ;------------------------------------------------------------------------------
108 
109  .global _v_loop_Update ; provide global scope to routine
110  _v_loop_Update: ; local function label
111 
112 ;------------------------------------------------------------------------------
113 ; Check status word for Enable/Disable flag and bypass computation, if disabled
114  btss [w0], #NPNZ16_STATUS_ENABLED ; check ENABLED bit state, skip (do not execute) next instruction if set
115  bra V_LOOP_LOOP_BYPASS ; if ENABLED bit is cleared, jump to end of control code
116 
117 ;------------------------------------------------------------------------------
118 ; Setup pointers to A-Term data arrays
119  mov [w0 + #ptrACoefficients], w8 ; load pointer to first index of A coefficients array
120 
121 ;------------------------------------------------------------------------------
122 ; Load pointer to first element of control history array
123  mov [w0 + #ptrControlHistory], w10 ; load pointer address into working register
124 
125 ;------------------------------------------------------------------------------
126 ; Compute compensation filter term
127  clr a, [w8]+=4, w4, [w10]+=2, w6 ; clear accumulator A and prefetch first operands
128  mac w4*w6, a, [w8]+=4, w4, [w10]+=2, w6 ; multiply control output (n-1) from the delay line with coefficient A1
129  mac w4*w6, a, [w8]+=4, w4, [w10]+=2, w6 ; multiply control output (n-2) from the delay line with coefficient A2
130  mac w4*w6, a, [w8]+=4, w4, [w10]+=2, w6 ; multiply control output (n-3) from the delay line with coefficient A3
131  mac w4*w6, a ; multiply & accumulate last control output with coefficient of the delay line (no more prefetch)
132 
133 ;------------------------------------------------------------------------------
134 ; Backward normalization of recent result
135  mov [w0 + #normPostShiftA], w6 ; load A-coefficients post bit-shift scaler value into working register
136  sftac a, w6 ; shift accumulator A by number of bits loaded in working register
137 
138 ;------------------------------------------------------------------------------
139 ; Update error history (move error one tick down the delay line)
140  mov [w10 + #6], w6 ; move entry (n-4) into buffer
141  mov w6, [w10 + #8] ; move buffered value one tick down the delay line
142  mov [w10 + #4], w6 ; move entry (n-3) into buffer
143  mov w6, [w10 + #6] ; move buffered value one tick down the delay line
144  mov [w10 + #2], w6 ; move entry (n-2) into buffer
145  mov w6, [w10 + #4] ; move buffered value one tick down the delay line
146  mov [w10 + #0], w6 ; move entry (n-1) into buffer
147  mov w6, [w10 + #2] ; move buffered value one tick down the delay line
148 
149 ;------------------------------------------------------------------------------
150 ; Read data from input source
151  mov [w0 + #ptrSourceRegister], w2 ; load pointer to input source register
152  mov [w2], w1 ; move value from input source into working register
153  mov [w0 + #ptrDProvControlInputComp], w2 ; load pointer address of target buffer of most recent, compensated controller input from data structure
154  mov w1, [w2] ; copy most recent controller input value to given data buffer target
155 
156 ;------------------------------------------------------------------------------
157 ; Load reference and calculate error input to transfer function
158  mov [w0 + #ptrControlReference], w2 ; move pointer to control reference into working register
159  subr w1, [w2], w1 ; calculate error (=reference - input)
160  mov [w0 + #normPreShift], w2 ; move error input scaler into working register
161  sl w1, w2, w1 ; normalize error result to fractional number format
162 
163 ;------------------------------------------------------------------------------
164 ; Setup pointers to B-Term data arrays
165  mov [w0 + #ptrBCoefficients], w8 ; load pointer to first index of B coefficients array
166  mov w1, [w10] ; add most recent error input to history array
167 
168 ;------------------------------------------------------------------------------
169 ; Compute B-Term of the compensation filter
170  clr b, [w8]+=4, w4, [w10]+=2, w6 ; clear accumulator B and prefetch first operands
171  mac w4*w6, b, [w8]+=4, w4, [w10]+=2, w6 ; multiply & accumulate error input (n-0) from the delay line with coefficient B0 and prefetch next operands
172  mac w4*w6, b, [w8]+=4, w4, [w10]+=2, w6 ; multiply & accumulate error input (n-1) from the delay line with coefficient B1 and prefetch next operands
173  mac w4*w6, b, [w8]+=4, w4, [w10]+=2, w6 ; multiply & accumulate error input (n-2) from the delay line with coefficient B2 and prefetch next operands
174  mac w4*w6, b, [w8]+=4, w4, [w10]+=2, w6 ; multiply & accumulate error input (n-3) from the delay line with coefficient B3 and prefetch next operands
175  mac w4*w6, b ; multiply & accumulate last error input with coefficient of the delay line (no more prefetch)
176 
177 ;------------------------------------------------------------------------------
178 ; Backward normalization of recent result
179  mov [w0 + #normPostShiftB], w6 ; load B-coefficients post bit-shift scaler value into working register
180  sftac b, w6 ; shift accumulator B by number of bits loaded in working register
181 
182 ;------------------------------------------------------------------------------
183 ; Adaptive Loop Gain Modulation
184  mov #ACCBH, w2 ; capture address of accumulator B high word and store it in working register
185  fbcl [w2], w3 ; find first bit change from left in accumulator B and store position in working register
186  sftac b, w3 ; shift accumulator by 'n' bits to scale contents into ACCH window
187  sac.r b, w6 ; store result of accumulator B in working register
188  mov [w0 + ptrAgcObserverFunction], w1 ; load function pointer to observer function
189  call w1 ; call extern observer function to update gain modulation factor
190  mov [w0 + #AgcFactor], w4 ; load AGC modulation factor into working register
191  mov [w0 + #AgcScaler], w2 ; load AGC modulation factor scaler into working register
192  mpy w4*w6, b ; multiply accumulator B result with AGC modulation factor
193  neg w3, w3 ; negate previously stored accumulator shift value
194  add w3, w2, w2 ; add post scaler bit-shift scaler and accumulator scaler
195  sftac b, w2 ; shift result by AGC scaler with accumulator scaling
196 
197 ;------------------------------------------------------------------------------
198 ; Add accumulators finalizing LDE computation
199  add a ; add accumulator b to accumulator a
200  sac.r a, w4 ; store most recent accumulator result in working register
201 
202 ;------------------------------------------------------------------------------
203 ; Controller Anti-Windup (control output value clamping)
204 
205 ; Check for lower limit violation
206  mov [w0 + #MinOutput], w6 ; load lower limit value
207  cpsgt w4, w6 ; compare values and skip next instruction if control output is within operating range (control output > lower limit)
208  mov w6, w4 ; override controller output
209  V_LOOP_CLAMP_MIN_EXIT:
210 
211 ; Check for upper limit violation
212  mov [w0 + #MaxOutput], w6 ; load upper limit value
213  cpslt w4, w6 ; compare values and skip next instruction if control output is within operating range (control output < upper limit)
214  mov w6, w4 ; override controller output
215  V_LOOP_CLAMP_MAX_EXIT:
216 
217 ;------------------------------------------------------------------------------
218 ; Write control output value to target
219  mov [w0 + #ptrTargetRegister], w8 ; capture pointer to target in working register
220  mov w4, [w8] ; move control output to target address
221  mov [w0 + #ptrAltTargetRegister], w8 ; capture pointer to alternate target in working register
222  mov w4, [w8] ; move control output to alternate target address
223 
224 ;------------------------------------------------------------------------------
225 ; Update ADC trigger locations
226  asr w4, #1, w6 ; half control output by shifting value one bit to the right
227  ; Update ADC trigger A position
228  mov [w0 + #ADCTriggerAOffset], w8 ; load user-defined ADC trigger A offset value into working register
229  add w6, w8, w10 ; add user-defined ADC trigger A offset to half of control output
230  mov [w0 + #ptrADCTriggerARegister], w8 ; load pointer to ADC trigger A register into working register
231  mov w10, [w8] ; push new ADC trigger value to ADC trigger A register
232 
233 ;------------------------------------------------------------------------------
234 ; Load pointer to first element of control history array
235  mov [w0 + #ptrControlHistory], w10 ; load pointer address into working register
236 
237 ;------------------------------------------------------------------------------
238 ; Update control output history (move entries one tick down the delay line)
239  mov [w10 + #4], w6 ; move entry (n-3) one tick down the delay line
240  mov w6, [w10 + #6]
241  mov [w10 + #2], w6 ; move entry (n-2) one tick down the delay line
242  mov w6, [w10 + #4]
243  mov [w10 + #0], w6 ; move entry (n-1) one tick down the delay line
244  mov w6, [w10 + #2]
245  mov w4, [w10] ; add most recent control output to history
246 
247 ;------------------------------------------------------------------------------
248 ; Enable/Disable bypass branch target with dummy read of source buffer
249  goto V_LOOP_LOOP_EXIT ; when enabled, step over dummy read and go straight to EXIT
250  V_LOOP_LOOP_BYPASS: ; Enable/Disable bypass branch target to perform dummy read of source to clear the source buffer
251  mov [w0 + #ptrSourceRegister], w2 ; load pointer to input source register
252  mov [w2], w1 ; move value from input source into working register
253  mov [w0 + #ptrDProvControlInputComp], w2 ; load pointer address of target buffer of most recent, compensated controller input from data structure
254  mov w1, [w2] ; copy most recent controller input value to given data buffer target
255  V_LOOP_LOOP_EXIT: ; Exit control loop branch target
256 
257 ;------------------------------------------------------------------------------
258 ; End of routine
259  return ; end of function; return to caller
260 
261 ;------------------------------------------------------------------------------
262 
263 
264 ;------------------------------------------------------------------------------
265 ; Global function declaration v_loop_Reset
266 ; This function clears control and error histories enforcing a reset
267 ;------------------------------------------------------------------------------
268 
269  .global _v_loop_Reset ; provide global scope to routine
270  _v_loop_Reset: ; local function label
271 
272 ;------------------------------------------------------------------------------
273 ; Clear control history array
274  push w0 ; save contents of working register WREG0
275  mov [w0 + #ptrControlHistory], w0 ; set pointer to the base address of control history array
276  clr [w0++] ; clear next address of control history array
277  clr [w0++] ; clear next address of control history array
278  clr [w0++] ; clear next address of control history array
279  clr [w0] ; clear last address of control history array
280  pop w0 ; restore contents of working register WREG0
281 
282 ;------------------------------------------------------------------------------
283 ; Clear error history array
284  push w0 ; save contents of working register WREG0
285  mov [w0 + #ptrErrorHistory], w0 ; set pointer to the base address of error history array
286  clr [w0++] ; Clear next address of error history array
287  clr [w0++] ; Clear next address of error history array
288  clr [w0++] ; Clear next address of error history array
289  clr [w0++] ; Clear next address of error history array
290  clr [w0] ; clear last address of error history array
291  pop w0 ; restore contents of working register WREG0
292 
293 ;------------------------------------------------------------------------------
294 ; End of routine
295  return ; end of function; return to caller
296 
297 ;------------------------------------------------------------------------------
298 
299 
300 ;------------------------------------------------------------------------------
301 ; Global function declaration v_loop_Precharge
302 ; This function loads user-defined default values into control and error histories
303 ;------------------------------------------------------------------------------
304 
305  .global _v_loop_Precharge ; provide global scope to routine
306  _v_loop_Precharge: ; local function label
307 
308 ;------------------------------------------------------------------------------
309 ; Charge error history array with defined value
310  push w0 ; save contents of working register WREG0
311  push w1 ; save contents of working register WREG1
312  mov [w0 + #ptrErrorHistory], w0 ; set pointer to the base address of error history array
313  mov w1, [w0++] ; Load user value into next address of error history array
314  mov w1, [w0++] ; Load user value into next address of error history array
315  mov w1, [w0++] ; Load user value into next address of error history array
316  mov w1, [w0++] ; Load user value into next address of error history array
317  mov w1, [w0] ; load user value into last address of error history array
318  pop w1 ; restore contents of working register WREG1
319  pop w0 ; restore contents of working register WREG0
320 
321 ;------------------------------------------------------------------------------
322 ; Charge control history array with defined value
323  push w0 ; save contents of working register WREG0
324  push w2 ; save contents of working register WREG2
325  mov [w0 + #ptrControlHistory], w0 ; set pointer to the base address of control history array
326  mov w2, [w0++] ; Load user value into next address of control history array
327  mov w2, [w0++] ; Load user value into next address of control history array
328  mov w2, [w0++] ; Load user value into next address of control history array
329  mov w2, [w0] ; Load user value into last address of control history array
330  pop w2 ; restore contents of working register WREG2
331  pop w0 ; restore contents of working register WREG0
332 
333 ;------------------------------------------------------------------------------
334 ; End of routine
335  return ; end of function; return to caller
336 
337 ;------------------------------------------------------------------------------
338 
339 
340 ;------------------------------------------------------------------------------
341 ; Global function declaration v_loop_PTermUpdate
342 ; This function executes a P-Term based control loop used for plant measurements only.
343 ; THIS LOOP IS NOT SUITED FOR STABLE OPERATION
344 ;------------------------------------------------------------------------------
345 
346  .global _v_loop_PTermUpdate ; provide global scope to routine
347  _v_loop_PTermUpdate: ; local function label
348 
349 ;------------------------------------------------------------------------------
350 ; Check status word for Enable/Disable flag and bypass computation when disabled
351  btss [w0], #NPNZ16_STATUS_ENABLED ; check ENABLED bit state, skip (do not execute) next instruction if set
352  bra V_LOOP_PTERM_LOOP_BYPASS ; if ENABLED bit is cleared, jump to end of control code
353 
354 ;------------------------------------------------------------------------------
355 ; Read data from input source
356  mov [w0 + #ptrSourceRegister], w2 ; load pointer to input source register
357  mov [w2], w1 ; move value from input source into working register
358  mov [w0 + #ptrDProvControlInputComp], w2 ; load pointer address of target buffer of most recent, compensated controller input from data structure
359  mov w1, [w2] ; copy most recent controller input value to given data buffer target
360 
361 ;------------------------------------------------------------------------------
362 ; Load reference and calculate error input to transfer function
363  mov [w0 + #ptrControlReference], w2 ; move pointer to control reference into working register
364  subr w1, [w2], w1 ; calculate error (=reference - input)
365  mov [w0 + #normPreShift], w2 ; move error input scaler into working register
366  sl w1, w2, w1 ; normalize error result to fractional number format
367 
368 ;------------------------------------------------------------------------------
369 ; Load P-gain factor from data structure
370  mov [w0 + #PTermFactor], w6 ; move P-coefficient fractional into working register
371  mov [w0 + #PTermScaler], w2 ; move P-coefficient scaler into working register
372  mov w1, w4 ; move error to MPY working register
373  ; calculate P-control result
374  mpy w4*w6, a ; multiply most recent error with P-coefficient
375  sftac a, w2 ; shift accumulator to post-scale floating number
376  sac.r a, w4 ; store accumulator result to working register
377 
378 ;------------------------------------------------------------------------------
379 ; Controller Anti-Windup (control output value clamping)
380 
381 ; Check for lower limit violation
382  mov [w0 + #MinOutput], w6 ; load lower limit value
383  cpsgt w4, w6 ; compare values and skip next instruction if control output is within operating range (control output > lower limit)
384  mov w6, w4 ; override controller output
385  V_LOOP_PTERM_CLAMP_MIN_EXIT:
386 
387 ; Check for upper limit violation
388  mov [w0 + #MaxOutput], w6 ; load upper limit value
389  cpslt w4, w6 ; compare values and skip next instruction if control output is within operating range (control output < upper limit)
390  mov w6, w4 ; override controller output
391  V_LOOP_PTERM_CLAMP_MAX_EXIT:
392 
393 ;------------------------------------------------------------------------------
394 ; Write control output value to target
395  mov [w0 + #ptrTargetRegister], w8 ; capture pointer to target in working register
396  mov w4, [w8] ; move control output to target address
397  mov [w0 + #ptrAltTargetRegister], w8 ; capture pointer to alternate target in working register
398  mov w4, [w8] ; move control output to alternate target address
399 
400 ;------------------------------------------------------------------------------
401 ; Update ADC trigger locations
402  asr w4, #1, w6 ; half control output by shifting value one bit to the right
403  ; Update ADC trigger A position
404  mov [w0 + #ADCTriggerAOffset], w8 ; load user-defined ADC trigger A offset value into working register
405  add w6, w8, w10 ; add user-defined ADC trigger A offset to half of control output
406  mov [w0 + #ptrADCTriggerARegister], w8 ; load pointer to ADC trigger A register into working register
407  mov w10, [w8] ; push new ADC trigger value to ADC trigger A register
408 
409 ;------------------------------------------------------------------------------
410 ; Enable/Disable bypass branch target with dummy read of source buffer
411  goto V_LOOP_PTERM_LOOP_EXIT ; when enabled, step over dummy read and go straight to EXIT
412  V_LOOP_PTERM_LOOP_BYPASS: ; Enable/Disable bypass branch target to perform dummy read of source to clear the source buffer
413  mov [w0 + #ptrSourceRegister], w2 ; load pointer to input source register
414  mov [w2], w1 ; move value from input source into working register
415  mov [w0 + #ptrDProvControlInputComp], w2 ; load pointer address of target buffer of most recent, compensated controller input from data structure
416  mov w1, [w2] ; copy most recent controller input value to given data buffer target
417  V_LOOP_PTERM_LOOP_EXIT: ; Exit P-Term control loop branch target
418 
419 ;------------------------------------------------------------------------------
420 ; End of routine
421  return ; end of function; return to caller
422 
423 ;------------------------------------------------------------------------------
424 
425 
426 ;------------------------------------------------------------------------------
427 ; End of file
428  .end ; end of file v_loop_asm.s
429 
430 ;------------------------------------------------------------------------------
431 
432 
433 ; **********************************************************************************
434 ; Download latest version of this tool here: https://areiter128.github.io/DCLD
435 ; **********************************************************************************