XMC42_800WPSU_LLC
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
interrupts_control.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 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 
42 #ifndef INTERRUPTS_CONTROL_H_
43 #define INTERRUPTS_CONTROL_H_
44 
45 
46 /***********************************************************************************************************************
47  * HEADER FILES
48  **********************************************************************************************************************/
49 #include <DAVE.h>
50 #include <XMC4200.h>
51 
52 #include <init_bckgnd.h>
53 
54 
55 /*********************************************************************************************************************
56  * MACROS
57  ********************************************************************************************************************/
58 
60 #define CSG_rise_ISR IRQ_Hdlr_75
61 
62 
68 #define LLC_PERIOD_MAX 1600 //1600 --> 50kHz (80MHz CLK)
69 
71 #define LLC_PERIOD_MIN 266 //266 --> 300kHz (80MHz CLK)
72 
74 #define LINEAR_PR_STEP 3 //2
75 
77 #define LLC_COMP_TIME 22//22//11
78 
79 //const uint16_t deadtime_test = 12; //12 --> 151ns (80MHz CLK)
80 #define DEADTIME_TEST 12
81 
83 #define MIN_DEADTIME 13U
84 
86 #define DEADTIME_SLOPE 2457
87 
89 #define DEADTIME_0Hz 43
90 
92 #define DEADTIME_BURST 28
93 
95 #define START_FREQ 177 //177 --> 450kHz; 160 --> 500kHz; 133 --> 600kHz; 114 --> 700kHz
96 
98 #define PR_START 160 //152
99 
101 #define DUTY_START 28-5 //+DRIVER_DELAY_COMP
102 
104 #define PR_START_SEQ 115 //111
105 
107 #define DUTY_START_SEQ1 39
108 
110 #define DUTY_START_SEQ2 47
111 
113 #define ADC_START 14
114 
116 #define DEADTIME_R_COMP 9 //8
117 
119 #define DEADTIME_R_START 10+DEADTIME_R_COMP
120 
122 #define DEADTIME_F_COMP -9 //0
123 
125 #define DEADTIME_F_START 10+DEADTIME_F_COMP
126 
128 #define DRIVER_DELAY_COMP -9
129 
131 #define DELAY_SR1_SR2_DIFF 9
132 #define DELAY_SR1_ON 29 - 8
133 #define DELAY_SR2_ON DELAY_SR1_ON-DELAY_SR1_SR2_DIFF
134 
136 #define BELOW_FREQ 888 //888 --> 90kHz //800 --> 100kHz
137 #define RES_FREQ 536 //536 --> 149kHz
138 
143 #define DELAY_SR1_SR2_OFF_DIFF 9
144 #define DELAY_SR1_OFF_BELOW_1 225 + 13
145 #define DELAY_SR2_OFF_BELOW_1 DELAY_SR1_OFF_BELOW_1-DELAY_SR1_SR2_OFF_DIFF
146 #define DELAY_SR1_OFF_BELOW_2 263 + 13 + 20 //263 + 13
147 #define DELAY_SR2_OFF_BELOW_2 DELAY_SR1_OFF_BELOW_2-DELAY_SR1_SR2_OFF_DIFF
148 
150 #define DELAY_SR1_SR2_OFF_DIFF_ABOVE 1
151 #define DELAY_SR1_OFF_ABOVE 16 + 8
152 #define DELAY_SR2_OFF_ABOVE DELAY_SR1_OFF_ABOVE-DELAY_SR1_SR2_OFF_DIFF_ABOVE
153 
155 #define DELAY_SR1_ON_BURST 13
156 #define DELAY_SR2_ON_BURST DELAY_SR1_ON_BURST-DELAY_SR1_SR2_DIFF
157 #define DELAY_SR1_OFF_BURST -8
158 #define DELAY_SR2_OFF_BURST DELAY_SR1_OFF_BURST-DELAY_SR1_SR2_DIFF
159 
160 
162 //#define DELAY_SR_OFF 38-DEADTIME_TEST //26+4 //delaySR-deadtime_test-3 = 41-12-3
163 
164 //const uint16_t period_llc_test = 200;//LLC_PERIOD_MIN; //615 --> 130kHz; 592 -->135kHz; 571 --> 140kHz; 551 --> 145kHz; 533 --> 150kHz; 500 --> 160kHz [with 80MHz CLK (12MHz osci)]
165 #define PERIOD_LLC_TEST 200
166 
167 #define SHADOW_TRANSFER_LLC_SR (CCU8_GCSS_S2SE_Msk|CCU8_GCSS_S1SE_Msk|CCU8_GCSS_S0SE_Msk)
168 
169 #define SHADOW_TRANSFER_LLC_SR_CLEAR (CCU8_GCSC_S2SC_Msk|CCU8_GCSC_S1SC_Msk|CCU8_GCSC_S0SC_Msk)
170 
177 #define CHARGE_HS_TOTAL 6
178 
180 #define CHARGE_HS_LOW 1
181 
188 #define VDC_BUS_START 11288 // 11288 --> 390Vbulk/3.3VddXMC13 //11408 --> 394Vbulk/3.3VddXMC13 // 10712 --> 370Vbulk/3.3VddXMC13 // 7064 --> 370Vbulk/5VddXMC13
189 
191 #define VDC_BUS_START_HYST 11344 // 11344 --> 392Vbulk/3.3VddXMC13 //11432 --> 395Vbulk/3.3VddXMC13 // 10712 --> 370Vbulk/3.3VddXMC13 // 7064 --> 370Vbulk/5VddXMC13
192 
194 #define VDC_BUS_STOP 9640 // 9264 --> 320Vbulk/3.3VddXMC13 //9552 --> 330Vbulk/3.3VddXMC13 // 9640 --> 333Vbulk/3.3VddXMC13 // 9784 --> 338Vbulk/3.3VddXMC13 // 9840 --> 340Vbulk/3.3VddXMC13 // 9984 --> 345Vbulk/3.3VddXMC13 // 10128 --> 350Vbulk/3.3VddXMC13
195 
197 #define VDC_BUS_DATA_OK 1448 // 1448 --> 50Vbulk/3.3VddXMC13
198 
206 #define VOUT_TARGET 16055 // 2.5V REF: 12.2V*.1/2.49 = 0.4899 => 16055(Q15) // 2.5V REF: 12.15V*.1/2.49 = 0.482 => 15989(Q15) // 2.5V REF: 12.05V*.1/2.49 = 0.488 => 15857(Q15) // 2.5V REF: 12V*.1/2.5 = 0.48 => 15729(Q15) //23831 --> 12V/kv=0.2
207 
209 #define VOUT_ORING_ON 15457 // 2.5V REF: 11.9V*11/111/2.5 = 0.4717 => 15457 (Q15) VOring_15067(Q15) //23000 --> 11.6V/kv=0.2 //22500-->11.3V/kv=0.2
210 
212 #define VOUT_SR_ON 13248 // 2.5V REF: 10.2V*11/111/2.5 = 0.404 => 13248(Q15) //22500-->11.3V/kv=0.2 //19800 --> 9.97V/kv=0.2
213 
215 #define VOUT_OVP_LATCH 18350 // 2.5V REF: 14V*.1/2.5 = 0.56 => 18350(Q15) // 14V*.2/3.3 = 0.8484 => 27803(Q15)
216 
218 #define VOUT_BURST_DIFF 197 // 2.5V REF: 0.1V*.1/2.5 = 0.004 => 131(Q15) // 2.5V REF: 0.15V*.1/2.5 = 0.006 => 197(Q15) // 2.5V REF: 0.2V*.1/2.5 = 0.008 => 262(Q15)
219 
221 #define VOUT_BURST VOUT_TARGET+VOUT_BURST_DIFF
222 
229 #define IOUT_OCP_LATCH_HARD 3228 // 2.5V REF, offset: 83A*250uR*50+offset = 1.96V => 3228(12bit) // 2.5V REF, offset: 87A*250uR*50+offset = 2.01V => 3297(12bit)
230 
232 #define IOUT_OCP_LATCH_MED 3043 // 2.5V REF, offset: 74A*250uR*50+offset = 1.85V => 3031(12bit)
233 
235 #define IOUT_OCP_LATCH_SOFT 2960 // 2.5V REF, offset: 70A*250uR*50+offset = 1.8V => 2949(12bit)
236 
238 #define LS1_HS0_PWM 0x100 // P0.7 = 0; P0.8 = 1 --> P0_IN = 0x100;
239 
241 #define LS0_HS1_PWM 0x80 // P0.7 = 1; P0.8 = 0 --> P0_IN = 0x80;
242 
249 #define Q15_PRODUCT_SHIFT 15
250 
252 #define ADC_TO_Q15 3
253 
255 #define V_TARGET_STEP 7
256 
262 #define a1_peak -1.98622f //-1.99032f
263 #define a2_peak 0.9862674721f //0.990367553344f
264 
265 #define b1_peak 1.99858f //1.9972f
266 #define b2_peak -0.99862772985841f //-0.99724769140625f
267 
270 /*********************************************************************************************************************
271  * Enum / type definition
272  ********************************************************************************************************************/
274 typedef union
275 {
276  struct
277  {
278  uint8_t _fill[3];
279  uint8_t command;
280  union
281  {
282  uint32_t ui32[4];
283  uint16_t ui16[8];
284  uint8_t ui8[16];
285  } payload;
286  } msg;
287  struct
288  {
289  uint8_t _fill[3];
290  uint8_t ui8[18];
291  } raw;
292 } msg_t;
293 
295 typedef enum
296 {
297  ST_INIT = 0x0,
298  ST_STB = 0x01,
299  ST_CHARGE = 0x02,
300 // ST_COMP = 0x04,
301 // ST_LINEAR_PR = 0x08,
304  ST_RUNNING = 0x10,
305  ST_BURST = 0x20,
306  ST_OCP = 0x100,
307  ST_LATCH = 0x200
308  //ST_CHARGE = 0x80,
309 
310 } state_t;
311 
313 typedef enum fault
314 {
315  F_INIT = 0x0,
316  F_OVP = 0x01,
317  F_OCP_H = 0x02,
318  F_OCP_M = 0x04,
319  F_OCP_S = 0x08,
320  F_UVP = 0x10,
321  F_SC = 0x20
322 // F_PEAK = 8
323 } fault_t;
324 
326 typedef enum burst_mode
327 {
330 } burst_mode_t;
331 
333 typedef enum ramp_loop_mode
334 {
335  ramp = 0,
336  loop = 1
338 
340 typedef struct
341 {
342  uint16_t qiR;
343  uint16_t q12V;
344  uint16_t q12V_oring;
345  uint16_t qIout;
346  uint16_t *qVout;
347  uint16_t deadtime;
348  uint32_t SR1_on_timing;
349  uint32_t SR2_on_timing;
350  uint32_t SR1_off_timing;
351  uint32_t SR2_off_timing;
353 // uint16_t qVin_inv2_16b; /**< Inverse of the input voltage RMS square in 16-bit Q15 codification. */
354 // uint16_t qTemp; /**< Temperature sensing in power board. */
355 // uint16_t qTemp_amb; /**< Temperature sensing in TSE of XMC. */
356 } LLC_t;
357 
359 typedef struct
360 {
361  int16_t a[3];
362  int16_t b[3];
363  uint8_t qformat;
364  uint8_t shift_to_q15;
365  int16_t error[3];
366  int32_t state[3];
367  int32_t int_calc;
368  int32_t output_int;
369  int16_t *output_int_limit;
370  int16_t soft_start;
371  int16_t *output;
372  int16_t output_max;
373  uint16_t int_ref;
374  uint16_t int_ref_steady;
375  bool first_iter;
377 // float fCoeff_peak[3]; /**< Peaking filter coefficients. Float format. */
378  float fIn_peak[3];
379  float fOut_peak[3];
380  int16_t qOut_peak;
381 } controller_t;
382 
383 /*********************************************************************************************************************
384  * Variables
385  ********************************************************************************************************************/
386 
387 extern __IO uint32_t *ADCResult_iR;
388 extern __IO uint32_t *ADCResult_12V;
389 extern __IO uint32_t *ADCResult_12VOr;
390 extern __IO uint32_t *ADCResult_iOut;
391 
392 //extern volatile uint16_t VDC_bus;
393 
394 extern volatile controller_t voltage_int_ctr;
395 
396 extern volatile uint16_t time_count_100kHz;
397 extern volatile uint16_t time_IMON_100kHz;
398 
399 static volatile uint8_t OCP_hard_count = 0;
400 
401 extern volatile uint8_t start_sequence_count;
402 
403 extern volatile state_t status_reg;
404 extern volatile fault_t fault_reg;
405 extern volatile burst_mode_t burst_status;
406 
407 extern volatile LLC_t LLC;
408 //extern LLC_t LLC;
409 
410 extern volatile uint16_t Temp_fan;
411 
412 
413 /*********************************************************************************************************************
414  * FUNCTIONS
415  ********************************************************************************************************************/
416 /*---------------------------------------------------------------------------*/
417 #ifndef DOXYGEN_SKIP
418 __attribute__((section(".ram_code")))
419 #endif
420 __STATIC_INLINE void
422 {
423  PORT0->OMR = 0x40000;
424  PORT0->IOCR0 &= 0xFF80FFFF;
425  PORT0->IOCR0 |= 0x800000;
426 
427  PORT2->OMR = 0x80000000;
428  PORT2->IOCR12 &= 0x80FFFFFF;
429  PORT2->IOCR12 |= 0x80000000;
430 }
431 
432 /*---------------------------------------------------------------------------*/
433 #ifndef DOXYGEN_SKIP
434 __attribute__((section(".ram_code")))
435 #endif
436 __STATIC_INLINE void
438 {
439  PORT0->IOCR0 &= 0xFF98FFFF;
440  PORT0->IOCR0 |= 0x980000;
441 
442  PORT2->IOCR12 &= 0x98FFFFFF;
443  PORT2->IOCR12 |= 0x98000000;
444 }
445 
446 /*---------------------------------------------------------------------------*/
447 #ifndef DOXYGEN_SKIP
448 __attribute__((section(".ram_code")))
449 #endif
450 __STATIC_INLINE void
452 {
453  PORT0->OMR = 0x1800000;
454  PORT0->IOCR4 &= 0x80FFFFFF;
455  PORT0->IOCR4 |= 0x80000000;
456  PORT0->IOCR8 &= 0xFFFFFF80;
457  PORT0->IOCR8 |= 0x80;
458 }
459 
460 /*---------------------------------------------------------------------------*/
461 #ifndef DOXYGEN_SKIP
462 __attribute__((section(".ram_code")))
463 #endif
464 __STATIC_INLINE void
466 {
467  PORT0->IOCR4 &= 0xA0FFFFFF;
468  PORT0->IOCR4 |= 0xA0000000;
469  PORT0->IOCR8 &= 0xFFFFFFA0;
470  PORT0->IOCR8 |= 0xA0;
471 }
472 
473 
474 /*---------------------------------------------------------------------------*/
475 #ifndef DOXYGEN_SKIP
476 __attribute__((section(".ram_code")))
477 #endif
478 __STATIC_INLINE void
480 {
481  PORT0->OMR = 0x2;
482 }
483 
484 /*---------------------------------------------------------------------------*/
485 #ifndef DOXYGEN_SKIP
486 __attribute__((section(".ram_code")))
487 #endif
488 __STATIC_INLINE void
490 {
491  PORT0->OMR = 0x20000;
492 }
493 
494 /*---------------------------------------------------------------------------*/
495 #ifndef DOXYGEN_SKIP
496 __attribute__((section(".ram_code")))
497 #endif
498 __STATIC_INLINE void
500 {
501  PORT1->OMR = 0x8;
502  PORT2->OMR = 0x2;
503 }
504 
505 /*---------------------------------------------------------------------------*/
506 #ifndef DOXYGEN_SKIP
507 __attribute__((section(".ram_code")))
508 #endif
509 __STATIC_INLINE void
511 {
512  PORT1->OMR = 0x80000;
513  PORT2->OMR = 0x20000;
514 }
515 
516 /*---------------------------------------------------------------------------*/
517 #ifndef DOXYGEN_SKIP
518 __attribute__((section(".ram_code")))
519 #endif
520 __STATIC_INLINE void
522 {
523  XMC_GPIO_SetOutputHigh(enable_sec.gpio_port,enable_sec.gpio_pin);
524 }
525 
526 /*---------------------------------------------------------------------------*/
527 #ifndef DOXYGEN_SKIP
528 __attribute__((section(".ram_code")))
529 #endif
530 __STATIC_INLINE void
532 {
533  XMC_GPIO_SetOutputLow(enable_sec.gpio_port,enable_sec.gpio_pin);
534 }
535 
536 
537 /*---------------------------------------------------------------------------*/
538 #ifndef DOXYGEN_SKIP
539 __attribute__((section(".ram_code")))
540 #endif
541 __STATIC_INLINE void
543 {
544  // Over-voltage protection --> latch the converter if the output voltage reaches 14V.
545  if ((status_reg) && ((LLC.q12V > VOUT_OVP_LATCH)||(LLC.q12V_oring > VOUT_OVP_LATCH)))
546  {
547  PWM_OFF();
548  sync_OFF();
549  ORING_OFF();
550 
551  // Set alarm and go to state with no decision (latch operation)
553  fault_reg |= F_OVP;
554  }
555 }
556 
557 
558 /*---------------------------------------------------------------------------*/
559 #ifndef DOXYGEN_SKIP
560 __attribute__((section(".ram_code")))
561 #endif
562 __STATIC_INLINE void
564 {
565  // Over-current protection --> latch type with restarting based on Vdc; Trigger the protection after
566  // a defined number of consecutive cycles with overcurrent
567  if (status_reg >= ST_SOFT_START)
568  {
569  // Set the different current level protections
571  if ((LLC.qIout > IOUT_OCP_LATCH_HARD) && (status_reg == ST_RUNNING)) //Immediate OFF if current over HARD limit
572  {
573  // Counter based filter. Reset of counter if sensed current under the hard limit
574  OCP_hard_count++;
575  if (OCP_hard_count > 100)
576  {
577  PWM_OFF();
578  sync_OFF();
579  ORING_OFF();
580 
581  // Set alarm and go to state with no decision (latch operation)
583  fault_reg |= F_OCP_H;
584  }
585  }
586  else if ((LLC.qIout > IOUT_OCP_LATCH_MED) && !(fault_reg & F_OCP_M))//10s OFF if current over MED limit
587  {
588  // Set the fault and 10s timer
589  time_OCP_M_100ms = 100;
590  fault_reg |= F_OCP_M;
591 
592  // Reset the counter based filter for hard detection
593  OCP_hard_count = 0;
594  }
595  else if (LLC.qIout > IOUT_OCP_LATCH_SOFT) //((LLC.qIout > IOUT_OCP_LATCH_SOFT) && !(fault_reg & F_OCP_S))//30s OFF if current over MED limit
596  {
597  if ((fault_reg & F_OCP_M) && (LLC.qIout < IOUT_OCP_LATCH_MED))
598  {
599  // Reset 10s timer and clear OCP_MED fault
600  time_OCP_M_100ms = 0;
601  fault_reg &= ~F_OCP_M;
602  }
603 
604  if (!(fault_reg & F_OCP_S))
605  {
606  // Set the fault and 30s timer
607  time_OCP_S_100ms = 300;
608  fault_reg |= F_OCP_S;
609  }
610 
611  // Reset the counter based filter for hard detection
612  OCP_hard_count = 0;
613  }
614  else if (LLC.qIout < IOUT_OCP_LATCH_SOFT)
615  {
616  // Reset S and M timers and faults
617  time_OCP_M_100ms = 0;
618  fault_reg &= ~F_OCP_M;
619 
620  time_OCP_S_100ms = 0;
621  fault_reg &= ~F_OCP_S;
622 
623  // Reset the counter based filter for hard detection
624  OCP_hard_count = 0;
625  }
626 
627  // Decision after OCP_M and OCP_S set time
628  if ((fault_reg & F_OCP_M) && (!time_OCP_M_100ms))
629  {
630  // Converter off
631  PWM_OFF();
632  sync_OFF();
633  ORING_OFF();
634 
635  // Set alarm and go to state with no decision (latch operation)
637  fault_reg |= F_OCP_H;
638  }
639 
640  if ((fault_reg & F_OCP_S) && (!time_OCP_S_100ms))
641  {
642  // Converter off
643  PWM_OFF();
644  sync_OFF();
645  ORING_OFF();
646 
647  // Set alarm and go to state with no decision (latch operation)
649  fault_reg |= F_OCP_H;
650  }
651  }
652 }
653 
654 #endif /* INTERRUPTS_CONTROL_H_ */
655