Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
v_loop.h
1 /* *********************************************************************************
2  * PowerSmartâ„¢ Digital Control Library Designer, Version 0.9.12.672
3  * *********************************************************************************
4  * 4p4z controller function declarations and compensation filter coefficients
5  * derived for following operating conditions:
6  * *********************************************************************************
7  *
8  * Controller Type: 4P4Z - Advanced High-Q Compensator
9  * Sampling Frequency: 500000 Hz
10  * Fixed Point Format: Q15
11  * Scaling Mode: 4 - Fast Floating Point Coefficient Scaling
12  * Input Gain: 0.5
13  *
14  * *********************************************************************************
15  * CGS Version: 3.0.7
16  * CGS Date: 03/07/2021
17  * *********************************************************************************
18  * User: M91406
19  * Date/Time: 03/08/2021 12:42:58
20  * ********************************************************************************/
21 
22 // This is a guard condition so that contents of this file are not included
23 // more than once.
24 #ifndef __SPECIAL_FUNCTION_LAYER_V_LOOP_H__
25 #define __SPECIAL_FUNCTION_LAYER_V_LOOP_H__
26 
27 #include <xc.h> // include processor files - each processor file is guarded
28 #include <dsp.h> // include DSP data types (e.g. fractional)
29 #include <stdint.h> // include standard integer number data types
30 #include <stdbool.h> // include standard boolean data types (true/false)
31 
32 #include "npnz16b.h" // include NPNZ library header file
33 
34 /* *******************************************************************************
35  * Data Arrays:
36  * The NPNZ16b_s data structure contains pointers to coefficient, control and error
37  * history arrays. The pointer target objects (variables and arrays) are defined
38  * in controller source file v_loop.c
39  *
40  * Type definitions for A- and B- coefficient arrays as well as error- and control
41  * history arrays are aligned in memory using the 'packed' attribute for optimized
42  * addressing during DSP computations. These aligned data structures need to be
43  * placed in specific memory locations to allow direct X/Y-access from the DSP.
44  * This X/Y-memory placement is covered by the declarations used in controller
45  * source file v_loop.c
46  * ******************************************************************************/
47 
48 
54 {
55  volatile int32_t ACoefficients[4]; // A-Coefficients
56  volatile int32_t BCoefficients[5]; // B-Coefficients
57 } __attribute__((packed)); // Data structure packing A- and B- coefficient arrays in a linear memory space for optimized DSP code execution
59 
60 
66 {
67  volatile fractional ControlHistory[4]; // Control History Array
68  volatile fractional ErrorHistory[5]; // Error History Array
69 } __attribute__((packed)); // Data structure packing control and error histories arrays in a linear memory space for optimized DSP code execution
70 typedef struct V_LOOP_CONTROL_LOOP_HISTORIES_s V_LOOP_CONTROL_LOOP_HISTORIES_t; // Data type of data structure packing control and error histories arrays
71 
72 
77 extern volatile int16_t v_loop_pterm_factor; // Q15 fractional of the P-Term factor
78 
79 
84 extern volatile int16_t v_loop_pterm_scaler; // Bit-shift scaler of the P-Term factor
85 
86 
87 
92 extern volatile struct NPNZ16b_s v_loop; // user-controller data object
93 
94 
95 /* *******************************************************************************
96  * Function call prototypes for initialization routines and control loop handling
97  * ******************************************************************************/
98 
99 
116 extern volatile uint16_t v_loop_Initialize( // v_loop initialization function call
117  volatile struct NPNZ16b_s* controller // Pointer to NPNZ16b data object
118  );
119 
120 
135 extern void v_loop_Reset( // v_loop reset function call (Assembly)
136  volatile struct NPNZ16b_s* controller // Pointer to NPNZ16b data object
137  );
138 
139 
153 extern void v_loop_Precharge( // v_loop history pre-charge function call (Assembly)
154  volatile struct NPNZ16b_s* controller, // Pointer to NPNZ16b data object
155  volatile fractional ctrl_input, // user-defined, constant error history value
156  volatile fractional ctrl_output // user-defined, constant control output history value
157  );
158 
159 
176 extern void v_loop_Update( // Calls the 4P4Z controller (Assembly)
177  volatile struct NPNZ16b_s* controller // Pointer to NPNZ16b data object
178  );
179 
180 
203 extern void v_loop_PTermUpdate( // Calls the P-Term controller (Assembly)
204  volatile struct NPNZ16b_s* controller // Pointer to NPNZ16b data object
205  );
206 
207 #endif // end of __SPECIAL_FUNCTION_LAYER_V_LOOP_H__
208 
209 
210 //**********************************************************************************
211 // Download latest version of this tool here: https://areiter128.github.io/DCLD
212 //**********************************************************************************
213 
v_loop
volatile struct NPNZ16b_s v_loop
External reference to user-defined NPNZ16b controller data object 'v_loop'.
Definition: v_loop.c:94
v_loop_Precharge
void v_loop_Precharge(volatile struct NPNZ16b_s *controller, volatile fractional ctrl_input, volatile fractional ctrl_output)
Prototype of the Assembly routine '_v_loop_Precharge' loading user-defined values into the NPNZ16b co...
NPNZ16b_s
Global NPNZ controller data object.
Definition: npnz16b.h:502
V_LOOP_CONTROL_LOOP_HISTORIES_s::ErrorHistory
volatile fractional ErrorHistory[5]
Definition: v_loop.h:68
v_loop_PTermUpdate
void v_loop_PTermUpdate(volatile struct NPNZ16b_s *controller)
Prototype of the alternate Assembly P-Term control loop helping to call the v_loop P-Term controller ...
v_loop_pterm_scaler
volatile int16_t v_loop_pterm_scaler
Bit-shift scaler of the P-Term Coefficient for Plant Measurements.
Definition: v_loop.c:90
V_LOOP_CONTROL_LOOP_COEFFICIENTS_s::ACoefficients
volatile int32_t ACoefficients[4]
Definition: v_loop.h:55
v_loop_Initialize
volatile uint16_t v_loop_Initialize(volatile struct NPNZ16b_s *controller)
Initializes controller coefficient arrays and normalization factors.
Definition: v_loop.c:107
V_LOOP_CONTROL_LOOP_HISTORIES_s
Data structure packing A- and B- coefficient arrays in a linear memory space for optimized DSP code e...
Definition: v_loop.h:66
v_loop_Reset
void v_loop_Reset(volatile struct NPNZ16b_s *controller)
Prototype of the Assembly routine '_v_loop_Reset' clearing the NPNZ16b controller output and error hi...
v_loop_pterm_factor
volatile int16_t v_loop_pterm_factor
Q15 fractional of the P-Term Coefficient for Plant Measurements.
Definition: v_loop.c:89
V_LOOP_CONTROL_LOOP_COEFFICIENTS_s
Data structure packing A- and B- coefficient arrays in a linear memory space for optimized DSP code e...
Definition: v_loop.h:54
v_loop_Update
void v_loop_Update(volatile struct NPNZ16b_s *controller)
Prototype of the Assembly feedback control loop routine helping to call the v_loop controller from C-...
V_LOOP_CONTROL_LOOP_COEFFICIENTS_s::BCoefficients
volatile int32_t BCoefficients[5]
Definition: v_loop.h:56
V_LOOP_CONTROL_LOOP_HISTORIES_s::ControlHistory
volatile fractional ControlHistory[4]
Definition: v_loop.h:67