Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
v_loop_extensions.s
1 ; **********************************************************************************
2 ; SDK Version: PowerSmart(TM) Digital Control Library Designer v0.9.12.660
3 ; CGS Version: Code Generator Script v3.0.2 (01/05/2021)
4 ; Author: M91406
5 ; Date/Time: 01/12/2021 21:22:33
6 ; **********************************************************************************
7 ; Template for user extension functions extending functions of the common
8 ; control loop code using User Extension Hooks. These extensions allow user
9 ; to tie in proprietary user code into the assembly routine of the main control
10 ; loop.
11 ;
12 ; Please refer to the PS-DCLD User Guide for details about how to use this
13 ; feature.
14 ;
15 ; **********************************************************************************
16 
17 ;------------------------------------------------------------------------------
18 ; file start
19  .nolist ; (no external dependencies)
20  .list ; list of all external dependencies
21 
22 ;------------------------------------------------------------------------------
23 ; local inclusions.
24  .section .data ; place constant data in the data section
25 
26 ;------------------------------------------------------------------------------
27 ; include NPNZ16B_t data structure and global constants to allow access
28 ; to the active control loop data object
29 
30  .include "./sources/power_control/drivers/npnz16b.inc" ; include NPNZ16b_t object data structure value offsets and status flag labels
31 
32 ;------------------------------------------------------------------------------
33 ; source code section.
34  .section .text ; place code in the text section
35 
36 ;------------------------------------------------------------------------------
37 ; Global function call prototype declarations
38 ; These global function calls are used to publish functions across the
39 ; application. Add a function call prototype to a C-header file to allow
40 ; calling this function from C-code.
41 ;
42 ; extern void __attribute__((near))my_function(void);
43 ;
44 ;------------------------------------------------------------------------------
45 
46  .global _my_function ; provide global scope to routine
47 
48 ;------------------------------------------------------------------------------
49 
50 ;------------------------------------------------------------------------------
51 ; User Functions
52 ;------------------------------------------------------------------------------
53 
54 ;------------------------------------------------------------------------------
55 ; MY FUNCTION is a simple function template, when used as a user extension
56 ; function, this function will be directly called by a CALL Wn instruction
57 ; to minimize the function call overhead to 2 instruction cycles only.
58 ; However, there is no context handling as it is assumed user extension
59 ; functions are commonly using the same data object as the main control loop.
60 ; Hence, all data is kept in its place just like this code would be part of
61 ; the main loop itself.
62 ;
63 ; Please refer to the PS-DCLD User Guide for details about how to use this
64 ; feature, which working registers are in use by the main loop and which
65 ; can/may be used and/or manipulated by this routine.
66 ;
67 ;------------------------------------------------------------------------------
68 ; Start of routine
69 _my_function: ; local function label (placeholder)
70 
71  nop ; place your code here
72  nop
73  nop
74 
75  mov #0x88B8, w4
76 
77  nop ; place your code here
78  nop
79  nop
80 
81 
82  lsr w4, w2
83 
84  ; Check for upper limit violation
85  mov [w0 + #MaxOutput], w6 ; load upper limit value
86  lsr w6, w3 ; load upper limit value, shifted one bit to the right
87  cpslt w2, w3 ; compare values and skip next instruction if control output is within operating range (control output < upper limit)
88  mov w6, w4 ; override controller output
89 
90  ; Check for lower limit violation
91  mov [w0 + #MinOutput], w6 ; load lower limit value
92  lsr w6, w3 ; load upper limit value, shifted one bit to the right
93  cpsgt w2, w3 ; compare values and skip next instruction if control output is within operating range (control output > lower limit)
94  mov w6, w4 ; override controller output
95 
96 
97 
98 ;------------------------------------------------------------------------------
99 ; End of routine
100  return ; end of function; return to caller
101 
102 ;------------------------------------------------------------------------------
103 
104 
105 ;------------------------------------------------------------------------------
106 ; End of file
107  .end ; end of file v_loop_extensions.s
108 
109 ;------------------------------------------------------------------------------
110 
111 
112 ; **********************************************************************************
113 ; Download latest version of this tool here: https://areiter128.github.io/DCLD
114 ; **********************************************************************************