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 
41 #ifndef INTERRUPTS_CONTROL_H_
42 #define INTERRUPTS_CONTROL_H_
43 
44 
45 /***********************************************************************************************************************
46  * HEADER FILES
47  **********************************************************************************************************************/
48 #include <DAVE.h>
49 #include <XMC4200.h>
50 
51 #include <init_bckgnd.h>
52 
53 
54 /*********************************************************************************************************************
55  * MACROS
56  ********************************************************************************************************************/
57 
59 #define CSG_rise_ISR IRQ_Hdlr_75
60 
61 
67 #define LLC_PERIOD_MAX 1600 //1600 --> 50kHz (80MHz CLK)
68 
70 #define LLC_PERIOD_MIN 266 //266 --> 300kHz (80MHz CLK)
71 
73 #define LINEAR_PR_STEP 3 //2
74 
76 #define LLC_COMP_TIME 22//22//11
77 
79 #define DEADTIME_TEST 12
80 
82 #define MIN_DEADTIME 13U
83 
85 #define DEADTIME_SLOPE 2457
86 
88 #define DEADTIME_0Hz 43
89 
91 #define DEADTIME_BURST 28
92 
94 #define START_FREQ 177 //177 --> 450kHz
95 
97 #define PR_START 152
98 
100 #define DUTY_START 28
101 
103 #define PR_START_SEQ 111
104 
106 #define DUTY_START_SEQ1 39
107 
109 #define DUTY_START_SEQ2 47
110 
112 #define ADC_START 14
113 
115 #define DEADTIME_R_COMP 9 //8
116 
118 #define DEADTIME_R_START 10
119 
121 #define DEADTIME_F_COMP -9 //0
122 
124 #define DEADTIME_F_START 10
125 
127 #define DRIVER_DELAY_COMP -9
128 
130 #define DELAY_SR_ON 26
131 
133 #define BELOW_FREQ 888 //888 --> 90kHz
134 
135 #define RES_FREQ 536 //536 --> 149kHz
136 
138 #define DELAY_SR_OFF_BELOW_1 263+26 //+2
139 
140 #define DELAY_SR_OFF_BELOW_2 225+30
141 
143 #define DELAY_SR_OFF_ABOVE 37-24 //-12
144 
146 #define PERIOD_LLC_TEST 200
147 
149 #define SHADOW_TRANSFER_LLC_SR (CCU8_GCSS_S2SE_Msk|CCU8_GCSS_S1SE_Msk|CCU8_GCSS_S0SE_Msk)
150 
152 #define SHADOW_TRANSFER_LLC_SR_CLEAR (CCU8_GCSC_S2SC_Msk|CCU8_GCSC_S1SC_Msk|CCU8_GCSC_S0SC_Msk)
153 
160 #define CHARGE_HS_TOTAL 6
161 
163 #define CHARGE_HS_LOW 1
164 
171 #define VDC_BUS_START 11288 // 11288 --> 390Vbulk/3.3VddXMC13
172 
174 #define VDC_BUS_START_HYST 11344 // 11344 --> 392Vbulk/3.3VddXMC13
175 
177 #define VDC_BUS_STOP 9640 // 9264 --> 320Vbulk/3.3VddXMC13
178 
180 #define VDC_BUS_DATA_OK 1448 // 1448 --> 50Vbulk/3.3VddXMC13
181 
189 #define VOUT_TARGET 16055 // 2.5V REF: 12.2V*.1/2.49 = 0.4899 => 16055(Q15)
190 
192 #define VOUT_ORING_ON 15457 // 2.5V REF: 11.9V*11/111/2.5 = 0.4717 => 15457(Q15)
193 
195 #define VOUT_SR_ON 13248 // 2.5V REF: 10.2V*11/111/2.5 = 0.404 => 13248(Q15)
196 
198 #define VOUT_OVP_LATCH 18350 // 2.5V REF: 14V*.1/2.5 = 0.56 => 18350(Q15)
199 
201 #define VOUT_BURST_DIFF 197 // 2.5V REF: 0.15V*.1/2.5 = 0.006 => 197(Q15)
202 
204 #define VOUT_F_JUMP_DIFF 0 // 2.5V REF: 0.3V*.1/2.5 = 0.012 => 394(Q15)
205 
207 #define VOUT_BURST VOUT_TARGET+VOUT_BURST_DIFF
208 
210 #define VOUT_F_JUMP VOUT_TARGET+VOUT_F_JUMP_DIFF
211 
218 #define IOUT_OCP_LATCH_HARD 3194 // 2.5V REF, offset: 83A*250uR*50+offset = 1.95V => 3194(12bit)
219 
221 #define IOUT_OCP_LATCH_MED 3010 // 2.5V REF, offset: 74A*250uR*50+offset = 1.85V => 3031(12bit)
222 
224 #define IOUT_OCP_LATCH_SOFT 2928 // 2.5V REF, offset: 70A*250uR*50+offset = 1.78V => 2928(12bit)
225 
227 #define IOUT_OCP_LATCH_SOFT_CLEAR 2887 // 2.5V REF, offset: 68A*250uR*50+offset = 1.76V => 2887(12bit)
228 
230 #define LS1_HS0_PWM 0x100 // P0.7 = 0; P0.8 = 1 --> P0_IN = 0x100;
231 
233 #define LS0_HS1_PWM 0x80 // P0.7 = 1; P0.8 = 0 --> P0_IN = 0x80;
234 
241 #define Q15_PRODUCT_SHIFT 15
242 
244 #define ADC_TO_Q15 3
245 
247 #define V_TARGET_STEP 7
248 
254 #define a1_peak -1.98622f //-1.99032f
255 #define a2_peak 0.9862674721f //0.990367553344f
256 
257 #define b1_peak 1.99858f //1.9972f
258 #define b2_peak -0.99862772985841f //-0.99724769140625f
259 
262 /*********************************************************************************************************************
263  * Enum / type definition
264  ********************************************************************************************************************/
266 typedef union
267 {
268  struct
269  {
270  uint8_t _fill[3];
271  uint8_t command;
272  union
273  {
274  uint32_t ui32[4];
275  uint16_t ui16[8];
276  uint8_t ui8[16];
277  } payload;
278  } msg;
279  struct
280  {
281  uint8_t _fill[3];
282  uint8_t ui8[18];
283  } raw;
284 } msg_t;
285 
287 typedef enum
288 {
289  ST_INIT = 0x0,
290  ST_STB = 0x01,
291  ST_CHARGE = 0x02,
292 // ST_COMP = 0x04,
293 // ST_LINEAR_PR = 0x08,
296  ST_RUNNING = 0x10,
297  ST_BURST = 0x20,
298  ST_OCP = 0x100,
299  ST_LATCH = 0x200
300  //ST_CHARGE = 0x80,
301 
302 } state_t;
303 
305 typedef enum fault
306 {
307  F_INIT = 0x0,
308  F_OVP = 0x01,
309  F_OCP_H = 0x02,
310  F_OCP_M = 0x04,
311  F_OCP_S = 0x08,
312  F_UVP = 0x10,
313  F_SC = 0x20
314 // F_PEAK = 8
315 } fault_t;
316 
318 typedef enum burst_mode
319 {
322 } burst_mode_t;
323 
325 typedef enum ramp_loop_mode
326 {
327  ramp = 0,
328  loop = 1
330 
332 typedef struct
333 {
334  uint16_t qiR;
335  uint16_t q12V;
336  uint16_t q12V_oring;
337  uint16_t qIout;
338  uint16_t *qVout;
339  uint16_t deadtime;
340  uint32_t SR1_on_timing;
341  uint32_t SR2_on_timing;
342  uint32_t SR1_off_timing;
343  uint32_t SR2_off_timing;
345 // uint16_t qVin_inv2_16b; /**< Inverse of the input voltage RMS square in 16-bit Q15 codification. */
346 // uint16_t qTemp; /**< Temperature sensing in power board. */
347 // uint16_t qTemp_amb; /**< Temperature sensing in TSE of XMC. */
348 } LLC_t;
349 
351 typedef struct
352 {
353  int16_t a[3];
354  int16_t b[3];
355  uint8_t qformat;
356  uint8_t shift_to_q15;
357  int16_t error[3];
358  int32_t state[3];
359  int32_t int_calc;
360  int32_t output_int;
361  int16_t *output_int_limit;
362  int16_t soft_start;
363  int16_t *output;
364  int16_t output_max;
365  uint16_t int_ref;
366  uint16_t int_ref_steady;
367  bool first_iter;
369 // float fCoeff_peak[3]; /**< Peaking filter coefficients. Float format. */
370  float fIn_peak[3];
371  float fOut_peak[3];
372  int16_t qOut_peak;
373 } controller_t;
374 
375 /*********************************************************************************************************************
376  * Variables
377  ********************************************************************************************************************/
378 
379 extern __IO uint32_t *ADCResult_iR;
380 extern __IO uint32_t *ADCResult_12V;
381 extern __IO uint32_t *ADCResult_12VOr;
382 extern __IO uint32_t *ADCResult_iOut;
383 
384 //extern volatile uint16_t VDC_bus;
385 
386 extern volatile controller_t voltage_int_ctr;
387 
388 extern volatile uint16_t time_count_100kHz;
389 extern volatile uint16_t time_IMON_100kHz;
390 
391 static volatile uint8_t OCP_hard_count = 0;
392 
393 extern volatile uint8_t start_sequence_count;
394 
395 extern volatile state_t status_reg;
396 extern volatile fault_t fault_reg;
397 extern volatile burst_mode_t burst_status;
398 
399 
400 extern volatile LLC_t LLC;
401 //extern LLC_t LLC;
402 
403 extern volatile uint16_t Temp_fan;
404 
405 
406 /*********************************************************************************************************************
407  * FUNCTIONS
408  ********************************************************************************************************************/
409 /*---------------------------------------------------------------------------*/
410 #ifndef DOXYGEN_SKIP
411 __attribute__((section(".ram_code")))
412 #endif
413 __STATIC_INLINE void
415 {
416  PORT0->OMR = 0x40000;
417  PORT0->IOCR0 &= 0xFF80FFFF;
418  PORT0->IOCR0 |= 0x800000;
419 
420  PORT2->OMR = 0x80000000;
421  PORT2->IOCR12 &= 0x80FFFFFF;
422  PORT2->IOCR12 |= 0x80000000;
423 }
424 
425 /*---------------------------------------------------------------------------*/
426 #ifndef DOXYGEN_SKIP
427 __attribute__((section(".ram_code")))
428 #endif
429 __STATIC_INLINE void
431 {
432  PORT0->IOCR0 &= 0xFF98FFFF;
433  PORT0->IOCR0 |= 0x980000;
434 
435  PORT2->IOCR12 &= 0x98FFFFFF;
436  PORT2->IOCR12 |= 0x98000000;
437 }
438 
439 /*---------------------------------------------------------------------------*/
440 #ifndef DOXYGEN_SKIP
441 __attribute__((section(".ram_code")))
442 #endif
443 __STATIC_INLINE void
445 {
446  PORT0->OMR = 0x1800000;
447  PORT0->IOCR4 &= 0x80FFFFFF;
448  PORT0->IOCR4 |= 0x80000000;
449  PORT0->IOCR8 &= 0xFFFFFF80;
450  PORT0->IOCR8 |= 0x80;
451 }
452 
453 /*---------------------------------------------------------------------------*/
454 #ifndef DOXYGEN_SKIP
455 __attribute__((section(".ram_code")))
456 #endif
457 __STATIC_INLINE void
459 {
460  PORT0->IOCR4 &= 0xA0FFFFFF;
461  PORT0->IOCR4 |= 0xA0000000;
462  PORT0->IOCR8 &= 0xFFFFFFA0;
463  PORT0->IOCR8 |= 0xA0;
464 }
465 
466 /*---------------------------------------------------------------------------*/
467 #ifndef DOXYGEN_SKIP
468 __attribute__((section(".ram_code")))
469 #endif
470 __STATIC_INLINE void
472 {
473  PORT0->OMR = 0x2;
474 }
475 
476 /*---------------------------------------------------------------------------*/
477 #ifndef DOXYGEN_SKIP
478 __attribute__((section(".ram_code")))
479 #endif
480 __STATIC_INLINE void
482 {
483  PORT0->OMR = 0x20000;
484 }
485 
486 /*---------------------------------------------------------------------------*/
487 #ifndef DOXYGEN_SKIP
488 __attribute__((section(".ram_code")))
489 #endif
490 __STATIC_INLINE void
492 {
493  PORT1->OMR = 0x8;
494  PORT2->OMR = 0x2;
495 }
496 
497 /*---------------------------------------------------------------------------*/
498 #ifndef DOXYGEN_SKIP
499 __attribute__((section(".ram_code")))
500 #endif
501 __STATIC_INLINE void
503 {
504  PORT1->OMR = 0x80000;
505  PORT2->OMR = 0x20000;
506 }
507 
508 /*---------------------------------------------------------------------------*/
509 #ifndef DOXYGEN_SKIP
510 __attribute__((section(".ram_code")))
511 #endif
512 __STATIC_INLINE void
514 {
515  XMC_GPIO_SetOutputHigh(enable_sec.gpio_port,enable_sec.gpio_pin);
516 }
517 
518 /*---------------------------------------------------------------------------*/
519 #ifndef DOXYGEN_SKIP
520 __attribute__((section(".ram_code")))
521 #endif
522 __STATIC_INLINE void
524 {
525  XMC_GPIO_SetOutputLow(enable_sec.gpio_port,enable_sec.gpio_pin);
526 }
527 
528 
529 /*---------------------------------------------------------------------------*/
530 #ifndef DOXYGEN_SKIP
531 __attribute__((section(".ram_code")))
532 #endif
533 __STATIC_INLINE void
535 {
536  // Over-voltage protection --> latch the converter if the output voltage reaches 14V.
537  if ((status_reg) && ((LLC.q12V > VOUT_OVP_LATCH)||(LLC.q12V_oring > VOUT_OVP_LATCH)))
538  {
539  PWM_OFF();
540  sync_OFF();
541  ORING_OFF();
542 
543  // Set alarm and go to state with no decision (latch operation)
545  fault_reg |= F_OVP;
546  }
547 }
548 
549 
550 /*---------------------------------------------------------------------------*/
551 #ifndef DOXYGEN_SKIP
552 __attribute__((section(".ram_code")))
553 #endif
554 __STATIC_INLINE void
556 {
557  // Over-current protection --> latch type with restarting based on Vdc; Trigger the protection after
558  // a defined number of consecutive cycles with overcurrent
559  if (status_reg >= ST_SOFT_START)
560  {
561  // Set the different current level protections
563  if ((LLC.qIout > IOUT_OCP_LATCH_HARD) && (status_reg == ST_RUNNING)) //Immediate OFF if current over HARD limit
564  {
565  // Counter based filter. Reset of counter if sensed current under the hard limit
566  OCP_hard_count++;
567  if (OCP_hard_count > 100)
568  {
569  PWM_OFF();
570  sync_OFF();
571  ORING_OFF();
572 
573  // Set alarm and go to state with no decision (latch operation)
575  fault_reg |= F_OCP_H;
576  }
577  }
578  else if ((LLC.qIout > IOUT_OCP_LATCH_MED) && !(fault_reg & F_OCP_M))//10s OFF if current over MED limit
579  {
580  // Set the fault and 10s timer
581  time_OCP_M_100ms = 100;
582  fault_reg |= F_OCP_M;
583 
584  // Reset the counter based filter for hard detection
585  OCP_hard_count = 0;
586  }
587  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
588  {
589  if ((fault_reg & F_OCP_M) && (LLC.qIout < IOUT_OCP_LATCH_MED))
590  {
591  // Reset 10s timer and clear OCP_MED fault
592  time_OCP_M_100ms = 0;
593  fault_reg &= ~F_OCP_M;
594  }
595 
596  if (!(fault_reg & F_OCP_S))
597  {
598  // Set the fault and 30s timer
599  time_OCP_S_100ms = 300;
600  fault_reg |= F_OCP_S;
601  }
602 
603  // Reset the counter based filter for hard detection
604  OCP_hard_count = 0;
605  }
606  else if (LLC.qIout < IOUT_OCP_LATCH_SOFT_CLEAR)
607  {
608  // Reset S and M timers and faults
609  time_OCP_M_100ms = 0;
610  fault_reg &= ~F_OCP_M;
611 
612  time_OCP_S_100ms = 0;
613  fault_reg &= ~F_OCP_S;
614 
615  // Reset the counter based filter for hard detection
616  OCP_hard_count = 0;
617  }
618 
619  // Decision after OCP_M and OCP_S set time
620  if ((fault_reg & F_OCP_M) && (!time_OCP_M_100ms))
621  {
622  // Converter off
623  PWM_OFF();
624  sync_OFF();
625  ORING_OFF();
626 
627  // Set alarm and go to state with no decision (latch operation)
629  fault_reg |= F_OCP_H;
630  }
631 
632  if ((fault_reg & F_OCP_S) && (!time_OCP_S_100ms))
633  {
634  // Converter off
635  PWM_OFF();
636  sync_OFF();
637  ORING_OFF();
638 
639  // Set alarm and go to state with no decision (latch operation)
641  fault_reg |= F_OCP_H;
642  }
643  }
644 }
645 
646 #endif /* INTERRUPTS_CONTROL_H_ */
647