H4-PFC Infineon 1600W Server PSU
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
control_interrupts.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (c) 2017, Infineon Technologies AG
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification,are permitted provided that the following conditions are met:
8  *
9  * - Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * - Neither the name of the copyright holders nor the names of its contributors
15  * may be used to endorse or promote products derived from this software without
16  * specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * To improve the quality of the software, users are encouraged to share
31  * modifications, enhancements or bug fixes with Infineon Technologies AG
32  * dave@infineon.com).
33  */
44 #ifndef CONTROL_INTERRUPTS_H_
45 #define CONTROL_INTERRUPTS_H_
46 
47 /***********************************************************************************************************************
48  * HEADER FILES
49  **********************************************************************************************************************/
50 
51 #include <DAVE.h>
52 
53 /*********************************************************************************************************************
54  * MACROS
55  ********************************************************************************************************************/
61 #define ADC_FIR_TO_Q15 1
62 
63 #define ADC_TO_Q15 3
64 
65 #define IIR_QFORMAT 14
66 
67 #define ADC_TO_IIR (IIR_QFORMAT+ADC_TO_Q15)
68 
69 #define LPF_TO_2ADC (ADC_TO_IIR-1)
70 
71 #define LPF_TO_Q15 15
72 
73 #define NOTCH_TO_Q15 14
74 
75 #define OFFSET_SAMPLES_2 8 //7 //6
76 
77 #define OFFSET_SAMPLES 256 //128 //64
78 
79 #define OFFSET_END 0xFFFF
80 
81 #define OFFSET_VAC 432
82 
89 #define K_DCM_SHIFT 10
90 
91 #define K_DCM_FACTOR 22749 //k_CDM = DCM_capture*1/1475; 1/1475 = 0.55797 = 22.216(Q15) = 22749(Q25 --> Q15*2^10)
92 
93 #define AVG_DCM_SHIFT 15
94 
96 #define IL_AVG_GAIN 1
97 
99 #define T_DCM_MAX 1253 // 85%-1475 --> 1253
100 
101 #define T_DCM_MIN 147 // 10%-1475 --> 147
102 
110 #define MULT_FACTOR_DC_FILTER 9
111 
112 #define DC_FILTER_SHIFT 3
113 
120 #define PWM_FREQ 65
121 
122 #define FREQ_COUNT_MAX 780
123 
124 #define FREQ_COUNT_MIN 420
125 
132 #define COEFF_OFFSETC_9k_Q14 15113 //400V/3.3Vdd/65kHz/9kHzBW/zero=0.7/976R-200R-2SW: 11763 (80t) / 15113 (90t)
133 
134 #define COEFF_SLOPEC_9k_Q14 12605 //400V/3.3Vdd/65kHz/9kHzBW/zero=0.7/976R-200R-2SW: 6836 (80t) / 12605 (90t)
135 
136 #define COEFF_OFFSET1_9k_Q14 16383 //400V/3.3Vdd/65kHz/9kHzBW/zero=0.7/976R-200R-2SW: 13095 (80t) / 16383 (90t)
137 
138 #define COEFF_SLOPE1_9k_Q14 39463 //400V/3.3Vdd/65kHz/9kHzBW/zero=0.7/976R-200R-2SW: 25604 (80t) / 39463 (90t)
139 
140 #define ZERO_LOC_9k_Q14 11468 // 11468 --> 0.7 (Q14) // 9830 --> 0.6 (Q14)
141 
142 
144 #define COEFF_OFFSET1_4k_Q14 12393 //400V/3.3Vdd/65kHz/5kHzBW/zero=0.7/976R-200R-2SW: 9906 (80t) / 12393 (90t)
145 
146 #define COEFF_SLOPE1_4k_Q14 29852 //400V/3.3Vdd/65kHz/5kHzBW/zero=0.7/976R-200R-2SW: 19368 (80t) / 29852 (90t)
147 
148 #define COEFF_OFFSET2_4k_Q14 4228 //400V/3.3Vdd/65kHz/5kHzBW/zero=0.7/976R-200R-2SW: 4306 (80t) / 4228 (90t)
149 
150 #define COEFF_SLOPE2_4k_Q14 5265 //400V/3.3Vdd/65kHz/5kHzBW/zero=0.7/976R-200R-2SW: 4968 (80t) / 5265 (90t)
151 
152 #define ZERO_LOC_4k_Q14 11468 // 11468 --> 0.7 (Q14) // 9830 --> 0.6 (Q14)
153 
155 #define CONSTL_ILIMIT 1550 // 3.3Vdd/976R-200R-2SW --> 3A-2325 (80t) / 2A-1550 (90t)
156 
157 #define COEFF_ILIMIT_Q14 11482 // 3.3Vdd/976R-200R-2SW --> 16.44A-12746 (80t) / 14.8A-11482 (90t)
158 
159 #define I_4kHzBW 4650 // 4650/3.3Vdd/976R-200R-2SW --> 6A // 7752/3.3Vdd/976R-200R-2SW --> 10A
160 
161 #define I_9kHzBW 3100 // 3100/3.3Vdd/976R-200R-2SW --> 4A // 3876/3.3Vdd/976R-200R-2SW --> 5A
162 
164 #define Q28_TO_Q14 14
165 
166 #define Q29_TO_Q14 15
167 
168 #define Q28_TO_Q13 15
169 
170 #define CURRENT_REF_TO_Q15 19 //19 --> 3.3Vdd
171 
172 #define Q30_TO_Q15 15
173 
174 #define ACCOMP_TO_Q15 21
175 
176 
180 #define VOLT_LOOP_SHIFT_Q12 4
181 
182 #define VOLT_LOOP_SHIFT_Q13 3
183 
184 
186 #define BOP_DCBUS_RATIO 13
187 
194 #define VOUT_OFFSET 0
195 
196 #define VOUT_OFFSET_LCDO 174 // 174 --> 3V OFFSET
197 
199 #define VOUT_OVP_STOP 25171+VOUT_OFFSET // 25171 --> 432V/3.3Vdd
200 
202 #define VOUT_STEADY_MIN 23015+VOUT_OFFSET // 23015 --> 395VDC--> 3.3Vdd
203 
204 #define VOUT_STEADY_MAX 24122+VOUT_OFFSET // 24122 --> 414VDC--> 3.3Vdd
205 
206 #define VOUT_ORIGIN1 20790+VOUT_OFFSET
207 
208 #define VOUT_SLOPE1 19423
209 
210 #define VREF_TO_Q15 14
211 
213 #define VOUT_UVP_MIN 18063 // 18063 --> 310VDC/3.3Vdd
214 
216 #define VOUT_START_MIN 14338 // 14338 --> 246V(174Vrms)/3.3Vdd
217 
218 #define VOLTAGE_OFFSET_NL_ON 21845 //21845 --> 375Vdc/3.3Vdd
219 
220 #define VOLTAGE_OFFSET_NL_OFF 22719 //22719 --> 390Vdc/3.3Vdd
221 
224 #define SOFT_START_MAX 2317 // 2317 for full multiplier without voltage loop
225 
227 #define MAX_DUTY 953 // 97% --> 953
228 
234 #define SOFT_START_STEP_VOLTAGE 1022
235 
237 #define ST_STB_BOP_CHECK_BULK 80
238 
239 #define ST_STB_BOP_SFTSTRT_WAIT (10+ST_STB_BOP_CHECK_BULK)
240 
243 #define PFC_RUNNING (0x04|0x08)
244 
245 /*---------------------------------------------------------------------------*/
246 /* Enums / Type Definitions */
247 /*---------------------------------------------------------------------------*/
249 typedef enum state
250 {
251  ST_INIT = 0x00,//0,
252  ST_STB = 0x01,//1,
253  ST_STB_BOP = 0x02,//2,
254  ST_SOFT_START = 0x04,//4,
255  ST_RUNNING = 0x08,//8,
256  ST_LATCH = 0x10,//16,
257  ST_I_OFFSET = 0x20,//32,
258 // ST_NO_PWM = 64,
259 // ST_D = 128
260 } state_t;
261 
263 typedef enum fault
264 {
265  F_INIT = 0x0,
266  F_OVP = 0x1,
267  F_BOP = 0x2,
268  F_UVP = 0x4,
269  F_PEAK = 0x8,
270  F_OTP = 0x10
271 } fault_t;
272 
274 typedef enum
275 {
276  BW_L = 0,
277  BW_H = 1,
278 } comp_BW_t;
279 
281 typedef struct PFC_coefs
282 {
283  uint16_t qiL;
284  uint16_t qiL_k;
285  uint32_t qiL_offset_acc;
286  uint16_t qiL_offset_count;
287  uint16_t qiL_offset;
288  uint16_t DCM_offset;
290  int16_t qiL_int;
291  uint16_t qVbus_DC;
292  uint16_t qVbus_DC_send;
293  int32_t qVbus_DC_filt;
294  uint16_t qVin_AC;
295  uint16_t qVin_BOP;
296  uint32_t qVin_inv2;
297  uint16_t qVin_inv2_16b;
298  uint16_t qTemp;
299  uint16_t qTemp_amb;
300  uint16_t qTemp_send;
302 } PFC_coefs_t;
303 
305 typedef enum grid_voltage
306 {
307  NEGATIVE,
308  POSITIVE
310 
311 /*********************************************************************************************************************
312 * External global variables
313  ********************************************************************************************************************/
314 extern __IO uint32_t *ADCResult_iL;
315 extern __IO uint32_t *ADCResult_DCBus;
316 extern __IO uint32_t *ADCResult_VAC;
317 extern __IO uint32_t *ADCResult_Temp;
318 extern __IO uint32_t *ADCResult_BOP;
319 
320 extern volatile PFC_coefs_t PFC;
321 
322 extern __I uint32_t *DCM_capture_p;
323 extern __I uint32_t *DCM_capture_n;
324 
325 extern volatile state_t status_reg;
326 extern volatile fault_t fault_reg;
327 
328 extern volatile uint16_t freq_in_count;
329 
330 /*********************************************************************************************************************
331 * Inline functions
332  ********************************************************************************************************************/
333 /*---------------------------------------------------------------------------*/
335 __STATIC_INLINE void
337 {
338  PORT0->OUT &= 0xFFFE;
339  PORT0->IOCR0 &= 0xFFFFFF80;
340  PORT0->IOCR0 |= 0x80;
341 }
342 
343 /*---------------------------------------------------------------------------*/
345 __STATIC_INLINE void
347 {
348  PORT0->IOCR0 &= 0xFFFFFF94;
349  PORT0->IOCR0 |= 0x00000094;
350 }
351 
352 /*---------------------------------------------------------------------------*/
354 __STATIC_INLINE void
356 {
357  PORT1->OUT |= 0x0020;
358 }
359 
360 /*---------------------------------------------------------------------------*/
362 __STATIC_INLINE void
364 {
365  PORT1->OUT &= 0xFFDF;
366 }
367 
368 /*---------------------------------------------------------------------------*/
370 __STATIC_INLINE __attribute__((section(".ram_code"))) void
371 set_duty(uint16_t duty)
372 {
373  // PWM duty cycle
374  CCU80_CC80->CR1S = duty;
375  // iL and Vac ADC (Queue) trigger
376  CCU80_CC80->CR2S = duty >> 1;
377  // Vdc and T ADC (Scan) trigger
378  CCU80_CC81->CR1S = (pwm_pfc.config_ptr->period_value + duty) >> 1;
379  // Shadow transfer allowed
380  CCU80->GCSS |= (CCU8_GCSS_S0SE_Msk | CCU8_GCSS_S1SE_Msk);
381 }
382 
383 /*---------------------------------------------------------------------------*/
385 __STATIC_INLINE void
386 Iref(uint16_t level)
387 {
389 // // 212 is the period value
390 // comp1_iLpk.ccu4_config->cc4_slice_ptr->CRS = comp1_iLpk.ccu4_config->period_value - level;
392 // comp1_iLpk.ccu4_config->ccu4_module_ptr->GCSS |= comp1_iLpk.ccu4_config->shadow_txfr_msk;
395 }
396 
397 /*---------------------------------------------------------------------------*/
399 __STATIC_INLINE void
401 {
402  XMC_GPIO_SetOutputHigh(en_pri.gpio_port,en_pri.gpio_pin);
403 }
404 
405 /*---------------------------------------------------------------------------*/
407 __STATIC_INLINE void
409 {
410  XMC_GPIO_SetOutputLow(en_pri.gpio_port,en_pri.gpio_pin);
411 }
412 
413 #endif /* CONTROL_INTERRUPTS_H_ */
414