3.3kW Totem-pole PFC with CoolMOS and XMC1402
init_bckgnd_funct.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Infineon Technologies AG
3  * <br>All rights reserved.
4  * <br>Redistribution and use in source and binary forms, with or without
5  * modification,are permitted provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the documentation
10  * and/or other materials provided with the distribution.
11  * - Neither the name of the copyright holders nor the names of its contributors
12  * may be used to endorse or promote products derived from this software without
13  * specific prior written permission.
14  * .
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  * <br>To improve the quality of the software, users are encouraged to share
27  * modifications, enhancements or bug fixes with Infineon Technologies AG
28  * dave@infineon.com).
29  */
30 
43 #ifndef INIT_BCKGND_FUNCT_H_
44 #define INIT_BCKGND_FUNCT_H_
45 
46 /***********************************************************************************************************************
47  * HEADER FILES
48  **********************************************************************************************************************/
49 
50 #include <DAVE.h>
51 #include "xmc_flash.h"
52 
53 /*********************************************************************************************************************
54  * MACROS
55  ********************************************************************************************************************/
61 #define DIV_AUTO_START 0
62 
63 #define UNSIGNED_DIVISION 4
64 
65 #define SIGNED_DIVISION 0
66 
67 #define DIV_32BIT_BY_32BIT 0
68 
75 #define MAX_DUTY 1453 // 98.5%-1475U(65kHz) --> 1453; // 94%-1475U --> 1387(65kHz);
76 
77 #define MIN_DUTY 11 // 4%-1475U --> 55(65kHz); // 0.75%-1475U --> 11(65kHz);
78 
79 #define MAX_DELTA_DUTY (MAX_DUTY >> 1) //Current loop will modify the DFF in a fraction of the maximum duty
80 
82 #define MAX_DUTY_LCDO 1387 // 60%-1475U(65kHz) --> 885; // 94%-1475U --> 1387(65kHz);
83 
86 #define CLK_CORE_HZ 48000000UL
87 
93 #define VIN_MIN_START_INIT 2530 //2530 --> 172Vrms/5Vdd //2500 --> 170Vrms/5Vdd
94 
95 #define VIN_MIN_START 2530 //2530 --> 172Vrms/5Vdd //2500 --> 170Vrms/5Vdd
96 
97 #define VIN_MIN_PLD_130V 2133 //2133 --> 145Vrms/5Vdd //2059 --> 140Vrms/5Vdd
98 
99 #define VIN_MIN_PLD_150V 2500 //2500 --> 170Vrms/5Vdd //2427 --> 165Vrms/5Vdd
100 
102 #define VRMS_MIN_LIMIT 1176 // 1176 --> 80Vrms/5Vdd // 735 --> 50Vrms/5Vdd
103 #if (VRMS_MIN_LIMIT >= VIN_MIN_PLD_130V)
104  #error "RMS limitation should be lower than minimum expected RMS during operation"
105 #endif
106 
113 #define I_IN_AVG_MAX 17882 //17882 --> 30A/5Vdd/47R-750R-1.9SW //14902 --> 25A/5Vdd/47R-750R-1.9SW //9255 --> 15A/5Vdd/47R-1k18-1.25SW //15425 --> 25A/5Vdd/47R-1k18-1.25SW
114 //#define I_IN_MAX16b 0xFFFFU //0xFFFFU = 65535
117 //#define I_IN_FACTOR 1
119 //#define I_IN_MAX_FACTOR (I_IN_MAX16b >> I_IN_FACTOR)
127 #define T_MIN_ADC 1945 // 1945 --> 10°C
128 
129 #define T_CORNER_ADC 301 // 301 --> 70°C
130 
131 #define T_UC_ZERO_ADC 2225 // 2225 --> 10°-70° linear
132 
133 #define T_UC_SLOPE_ADC 1170 // 1170 --> 10°-70° linear
134 
135 #define T_OC_ZERO_ADC 589 // 589 --> 70°-130° linear
136 
137 #define T_OC_SLOPE_ADC 7959 // 7959 --> 70°-130° linear
138 
140 #define T_MIN_PWM 40
141 
142 #define T_MAX_PWM 65
143 
144 #define PR_FAN_PWM (fan_pwm.config_ptr->period_value)
145 
146 #define T_SLOPE_PWM (PR_FAN_PWM/(T_MAX_PWM-T_MIN_PWM))
147 
149 #define FAN_MS (80) // 80ms approx
150 
157 #define LIMIT_1_MILI_S 5
158 
159 #define LIMIT_100_MILI_S 100
160 
162 /*********************************************************************************************************************
163  * Type definition
164  ********************************************************************************************************************/
166 typedef struct IIR_lowpass_int
167 {
168  int16_t k1;
169  int16_t a1[3];
170  int16_t b1[3];
171  int32_t u1[3];
172  int16_t k2;
173  int16_t a2[3];
174  int16_t b2[3];
175  int32_t u2[3];
176  int32_t output1;
177  int32_t output;
179  int32_t calc11;
180  int32_t calc21;
181  int32_t calc12;
182  int32_t calc22;
185 
187 typedef struct controller_PI
188 {
189  int32_t a0;
190  int32_t a1;
191  int32_t a2;
192  int32_t aux;
193  uint8_t shift_to_q13;
194  uint8_t shift_to_q29;
195  int32_t state_output[3];
196  int16_t *duty_iL;
197  int32_t ratio_FF;
198  int16_t duty;
199  int32_t state_error[3];
200  int16_t max_duty;
201  int16_t min_duty;
202  uint16_t PI_ref;
203  uint32_t PI_ref_int;
204  uint16_t PI_ref_max;
205  int16_t PR_calc;
207 
209 typedef struct controller_int
210 {
211  int16_t a[3];
212  int16_t b[3];
213  uint8_t qformat;
214  uint8_t shift_to_q15;
215  int16_t error[3];
216  int32_t state[3];
217  int32_t output_int;
218  int16_t *output_int_limit;
219  uint16_t output;
220  int16_t output_max;
221  uint16_t int_ref;
222  uint16_t ref_offset_LCDO;
223  uint16_t int_ref_steady;
224  int32_t interm_calc1;
225  int32_t interm_calc2;
226  bool first_iter;
228 
229 /*********************************************************************************************************************
230 * External global variables
231  ********************************************************************************************************************/
232 // AC-RMS Filter instance
233 extern volatile IIR_lowpass_int_t ACfilter;
234 
235 // DC-bus Filter instance
236 //extern volatile FIR_lowpass_int_t DCfilter;
237 extern volatile IIR_lowpass_int_t DCfilter;
238 
239 // Scaled AC voltage for filter operation
240 extern volatile int32_t auxAC;
241 
242 // Scaled DC voltage for filter operation
243 extern volatile int32_t auxDC;
244 
245 extern volatile uint16_t time_count_5kHz;
246 
247 extern uint8_t _1ms_count;
248 extern uint8_t _100ms_count;
249 extern uint8_t time_BOP;
250 extern uint8_t time_ACOK;
251 extern uint8_t time_PLD_130V;
252 extern uint8_t time_PLD_150V;
253 extern uint8_t time_V_step;
254 extern uint16_t time_INIT;
255 extern uint8_t time_extra_bulk;
256 
257 extern volatile bool power_stage_ON;
258 extern volatile bool current_loop_ON;
259 
260 extern volatile controller_int_t voltage_int_ctr;
261 extern volatile controller_PI_t current_PI_ctr;
262 
263 /***********************************************************************************************************************
264  * Function Prototypes
265  **********************************************************************************************************************/
266 void IIR_param_init(void);
267 
268 void MATH_DIV_config(void);
269 
270 void control_loop_init(void);
271 
272 void time_counter(void);
273 
274 //void temperature_sense_enable(void);
275 
276 void delay_100us(uint32_t time);
277 
278 void PFC_INV_mode(void);
279 
280 void input_voltage_observer(void);
281 
282 void fan_control_temp_protection(void);
283 
284 void flash_sleep_ctr();
285 
286 #endif /* INIT_BCKGND_FUNCT_H_ */
287 
uint16_t time_INIT
Definition: init_bckgnd_funct.c:101
int32_t a1
Definition: init_bckgnd_funct.h:190
int16_t k2
Definition: init_bckgnd_funct.h:172
volatile int32_t auxDC
Definition: init_bckgnd_funct.c:72
uint16_t ref_offset_LCDO
Definition: init_bckgnd_funct.h:222
int16_t PR_calc
Definition: init_bckgnd_funct.h:205
void input_voltage_observer(void)
BOP protection, checking AVG input voltage. The function modifies the control status register...
Definition: init_bckgnd_funct.c:452
uint8_t _100ms_count
Definition: init_bckgnd_funct.c:95
Definition: init_bckgnd_funct.h:187
struct controller_PI controller_PI_t
void PFC_INV_mode(void)
Operation mode (PFC - AC/DC or inverter - DC/AC) selection function. Decision taken only once when ...
Definition: init_bckgnd_funct.c:416
uint8_t time_extra_bulk
Definition: init_bckgnd_funct.c:102
int32_t calc11
Definition: init_bckgnd_funct.h:179
int32_t output_int
Definition: init_bckgnd_funct.h:217
uint32_t PI_ref_int
Definition: init_bckgnd_funct.h:203
int32_t ratio_FF
Definition: init_bckgnd_funct.h:197
void MATH_DIV_config(void)
DIV kernel of the MATH co-processor initialization. Used in the input RMS feedforward.
Definition: init_bckgnd_funct.c:123
int32_t calc12
Definition: init_bckgnd_funct.h:181
uint16_t int_ref
Definition: init_bckgnd_funct.h:221
int16_t a1[3]
Definition: init_bckgnd_funct.h:169
volatile uint16_t time_count_5kHz
Definition: control_interrupts.c:93
volatile bool power_stage_ON
Definition: init_bckgnd_funct.c:85
uint8_t time_V_step
Definition: init_bckgnd_funct.c:100
void time_counter(void)
Time counter is a background process to count "real-time" in the application.
Definition: init_bckgnd_funct.c:339
int32_t calc22
Definition: init_bckgnd_funct.h:182
uint8_t qformat
Definition: init_bckgnd_funct.h:213
state
Definition: control_interrupts.h:257
void IIR_param_init(void)
IIR coefficients initialization. IIR cascaded low-pass filter of the AC voltage to obtain the RMS va...
Definition: init_bckgnd_funct.c:261
uint8_t shift_to_q29
Definition: init_bckgnd_funct.h:194
uint8_t shift_to_q13
Definition: init_bckgnd_funct.h:193
uint16_t int_ref_steady
Definition: init_bckgnd_funct.h:223
uint8_t time_PLD_150V
Definition: init_bckgnd_funct.c:99
bool first_iter
Definition: init_bckgnd_funct.h:226
void flash_sleep_ctr()
Flash memory sleep state control.
Definition: init_bckgnd_funct.c:737
void delay_100us(uint32_t time)
Delay function.
Definition: init_bckgnd_funct.c:396
volatile controller_int_t voltage_int_ctr
Definition: init_bckgnd_funct.c:80
Definition: init_bckgnd_funct.h:166
volatile IIR_lowpass_int_t ACfilter
Definition: init_bckgnd_funct.c:58
Definition: init_bckgnd_funct.h:209
int16_t * output_int_limit
Definition: init_bckgnd_funct.h:218
volatile IIR_lowpass_int_t DCfilter
Definition: init_bckgnd_funct.c:69
void control_loop_init(void)
Assign value to the coefficients of voltage and current loops. Reset the state and output of both c...
Definition: init_bckgnd_funct.c:140
int16_t k1
Definition: init_bckgnd_funct.h:168
int16_t duty
Definition: init_bckgnd_funct.h:198
int16_t min_duty
Definition: init_bckgnd_funct.h:201
int16_t output_max
Definition: init_bckgnd_funct.h:220
struct controller_int controller_int_t
volatile bool current_loop_ON
Definition: init_bckgnd_funct.c:87
uint16_t output
Definition: init_bckgnd_funct.h:219
volatile int32_t auxAC
Definition: init_bckgnd_funct.c:61
uint16_t PI_ref
Definition: init_bckgnd_funct.h:202
int32_t output
Definition: init_bckgnd_funct.h:177
uint16_t PI_ref_max
Definition: init_bckgnd_funct.h:204
int32_t output1
Definition: init_bckgnd_funct.h:176
uint8_t _1ms_count
Definition: init_bckgnd_funct.c:94
int32_t u1[3]
Definition: init_bckgnd_funct.h:171
uint8_t time_PLD_130V
Definition: init_bckgnd_funct.c:98
int32_t u2[3]
Definition: init_bckgnd_funct.h:175
int32_t aux
Definition: init_bckgnd_funct.h:192
int16_t b1[3]
Definition: init_bckgnd_funct.h:170
int16_t max_duty
Definition: init_bckgnd_funct.h:200
int32_t calc21
Definition: init_bckgnd_funct.h:180
int16_t * duty_iL
Definition: init_bckgnd_funct.h:196
struct IIR_lowpass_int IIR_lowpass_int_t
int32_t a2
Definition: init_bckgnd_funct.h:191
int16_t b2[3]
Definition: init_bckgnd_funct.h:174
int32_t a0
Definition: init_bckgnd_funct.h:189
uint8_t shift_to_q15
Definition: init_bckgnd_funct.h:214
int32_t interm_calc2
Definition: init_bckgnd_funct.h:225
int32_t interm_calc1
Definition: init_bckgnd_funct.h:224
uint8_t time_BOP
Definition: init_bckgnd_funct.c:96
volatile controller_PI_t current_PI_ctr
Definition: init_bckgnd_funct.c:82
uint8_t time_ACOK
Definition: init_bckgnd_funct.c:97
void fan_control_temp_protection(void)
Temperature monitoring: protection and fan control.
Definition: init_bckgnd_funct.c:660
int16_t a2[3]
Definition: init_bckgnd_funct.h:173