3.3kW Totem-pole PFC with SiC and XMC1404
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
init_bckgnd_funct.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, 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 
115 //#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)
128 #define LIMIT_1_MILI_S 5
129 
130 #define LIMIT_100_MILI_S 100
131 
133 /*********************************************************************************************************************
134  * Type definition
135  ********************************************************************************************************************/
137 typedef struct IIR_lowpass_int
138 {
139  int16_t k1;
140  int16_t a1[3];
141  int16_t b1[3];
142  int32_t u1[3];
143  int16_t k2;
144  int16_t a2[3];
145  int16_t b2[3];
146  int32_t u2[3];
147  int32_t output1;
148  int32_t output;
150  int32_t calc11;
151  int32_t calc21;
152  int32_t calc12;
153  int32_t calc22;
156 
158 typedef struct controller_PI
159 {
160  int32_t a0;
161  int32_t a1;
162  int32_t a2;
163  int32_t aux;
164  uint8_t shift_to_q13;
165  uint8_t shift_to_q29;
166  int32_t state_output[3];
167  int16_t *duty_iL;
168  int32_t ratio_FF;
169  int16_t duty;
170  int32_t state_error[3];
171  int16_t max_duty;
172  int16_t min_duty;
173  uint16_t PI_ref;
174  uint32_t PI_ref_int;
175  uint16_t PI_ref_max;
176  int16_t PR_calc;
178 
180 typedef struct controller_int
181 {
182  int16_t a[3];
183  int16_t b[3];
184  uint8_t qformat;
185  uint8_t shift_to_q15;
186  int16_t error[3];
187  int32_t state[3];
188  int32_t output_int;
189  int16_t *output_int_limit;
190  uint16_t output;
191  int16_t output_max;
192  uint16_t int_ref;
193  uint16_t ref_offset_LCDO;
194  uint16_t int_ref_steady;
195  int32_t interm_calc1;
196  int32_t interm_calc2;
197  bool first_iter;
199 
200 /*********************************************************************************************************************
201 * External global variables
202  ********************************************************************************************************************/
203 // AC-RMS Filter instance
204 extern volatile IIR_lowpass_int_t ACfilter;
205 
206 // DC-bus Filter instance
207 //extern volatile FIR_lowpass_int_t DCfilter;
208 extern volatile IIR_lowpass_int_t DCfilter;
209 
210 // Scaled AC voltage for filter operation
211 extern volatile int32_t auxAC;
212 
213 // Scaled DC voltage for filter operation
214 extern volatile int32_t auxDC;
215 
216 extern volatile uint16_t time_count_5kHz;
217 
218 extern uint8_t _1ms_count;
219 extern uint8_t _100ms_count;
220 extern uint8_t time_BOP;
221 extern uint8_t time_ACOK;
222 extern uint8_t time_PLD_130V;
223 extern uint8_t time_PLD_150V;
224 extern uint8_t time_V_step;
225 extern uint16_t time_INIT;
226 extern uint8_t time_extra_bulk;
227 
228 extern volatile bool power_stage_ON;
229 extern volatile bool current_loop_ON;
230 
231 extern volatile controller_int_t voltage_int_ctr;
232 extern volatile controller_PI_t current_PI_ctr;
233 
234 /***********************************************************************************************************************
235  * Function Prototypes
236  **********************************************************************************************************************/
237 void IIR_param_init(void);
238 
239 void MATH_DIV_config(void);
240 
241 void control_loop_init(void);
242 
243 void time_counter(void);
244 
245 //void temperature_sense_enable(void);
246 
247 void delay_100us(uint32_t time);
248 
249 void PFC_INV_mode(void);
250 
251 void input_voltage_observer(void);
252 
253 void fan_control_temp_protection(void);
254 
255 void flash_sleep_ctr();
256 
257 #endif /* INIT_BCKGND_FUNCT_H_ */
258