43 #ifndef CONTROL_INTERRUPTS_H_
44 #define CONTROL_INTERRUPTS_H_
64 #define IIR_QFORMAT 14
66 #define ADC_TO_IIR (IIR_QFORMAT+ADC_TO_Q15)
68 #define LPF_TO_2ADC (ADC_TO_IIR-1)
70 #define NOTCH_TO_Q15 14
75 #define CURRENT_REF_TO_Q15 19 //19 --> 5Vdd
77 #define ACCOMP_TO_Q15 21
85 #define OFFSET_SAMPLES_2 8
87 #define OFFSET_SAMPLES 256
89 #define OFFSET_END 0xFFFF
91 #define OFFSET_VAC 432 //432 --> 53Vac
94 #define IL_AVG_GAIN 31129 //31129-Q14 --> kI_SW = 1.9
96 #define IL_AVG_GAIN_Q 14 //31129-Q14 --> kI_SW = 1.9
104 #define ILOOP_COEFF_Q 14 //1P1Z/400V/5Vdd/65kHz/3kHzBW/zero=0.95/750R-47R-1.9SW: 3489 (PQ-HEL-60t)
107 #define COEFF_OFFSET_3k_Q 3986 //1P1Z/400V/5Vdd/65kHz/3kHzBW/zero=0.95/750R-47R-1.9SW: 3986 (PQ-HEL-60t)/4823 (PQ-HEL-66t)
109 #define COEFF_SLOPE_3k_Q 4901 //1P1Z/400V/5Vdd/65kHz/3kHzBW/zero=0.95/750R-47R-1.9SW: 4901 (PQ-HEL-60t)/6491 (PQ-HEL-66t)
111 #define COEFF_MIN_3k_Q 776 //1P1Z/400V/5Vdd/65kHz/3kHzBW/zero=0.95/750R-47R-1.9SW: 776 (PQ-HEL-60t)/572 (PQ-HEL-66t)
114 #define ZERO_LOC_3k_Q 15564 //1P1Z/400V/5Vdd/65kHz/3kHzBW/zero=0.95/750R-47R-1.9SW: 15564 (PQ-HEL-60t)/(PQ-HEL-66t)
117 #define REG1_ILIMIT_Q15 21459 //5Vdd/750R-47R-1.9SW --> 36A-21459 (PQ-HEL-60t)/4823 (PQ-HEL-66t)
120 #define COEFF_a0_INEG_Q 3349 //1P1Z/400V/5Vdd/65kHz/3kHzBW/zero=0.95/750R-47R-1.9SW: 3349 (PQ-HEL-60t)/3979 (PQ-HEL-66t)
122 #define INEG_FAULT_Q15 -4256 //-7.14A/5Vdd/750R-47R-1.9SW: -4256 (PQ-HEL-60t)/(PQ-HEL-66t)
130 #define DT_CONST_ILIMIT_Q15 1788 //5Vdd/750R-47R-1.9SW --> 3A-1788
132 #define DT_REG1_ILIMIT_Q15 4172 //5Vdd/750R-47R-1.9SW --> 7A-4172
134 #define DT_REG2_ILIMIT_Q15 6556 //5Vdd/750R-47R-1.9SW --> 11A-6556
137 #define DT_D2S 5 //5 --> 52ns
139 #define DT_S2D_MAX 12 //12 --> 125ns (65mOhm - 5R6)
141 #define DT_S2D_MIN 4 //4 --> 42ns (65mOhm - 5R6)
144 #define DT_REG1_OFFSET 17 //17 --> 177ns (65mOhm - 5R6)
146 #define DT_REG1_SLOPEQ15 82 //82 --> 15ns/A (65mOhm - 5R6)
148 #define DT_REG2_OFFSET 10 //10 --> 96ns (65mOhm - 5R6)
150 #define DT_REG2_SLOPEQ15 27 //27 --> 5ns/A (65mOhm - 5R6)
152 #define DT_SLOPE_Q 15
165 #define VOUT_OFFSET 392 //196 --> 3VDC/5Vdd
167 #define VOUT_OFFSET_LCDO 0
170 #define VOUT_STEADY 26144+VOUT_OFFSET // 26144 --> 400VDC/5Vdd // 25490 --> 390VDC/5Vdd // 24837 --> 380VDC/5Vdd // 22876 --> 350VDC/5Vdd // 19608 --> 300VDC/5Vdd // 16340 --> 250VDC/5Vdd // 13072 --> 200VDC/5Vdd
173 #define VOUT_OVP_STOP 29412+VOUT_OFFSET // 29412 --> 450V/5Vdd // 27451 --> 420V/5Vdd // 24837 --> 380V/5Vdd // 20915 --> 320V/5Vdd // 19608 --> 300V/5Vdd
174 #if (VOUT_OVP_STOP <= VOUT_STEADY)
175 #error "STOP threshold should be greater than steady state voltage"
179 #define VOUT_UVP_MIN 19608 //19608 --> 300VDC/5Vdd // 13072 --> 200VDC/5Vdd // 9804 --> 150VDC/5Vdd // 7843 --> 120VDC/5Vdd // 5228 --> 80VDC/5Vdd // 2614 --> 40VDC/5Vdd
182 #define VOUT_START_MIN 14789 // 14789 --> 226V(160Vrms)/5Vdd // 10167 --> 156V(110Vrms)/5Vdd // 6470 --> 99V(70Vrms)/5Vdd
185 #define VOLTAGE_OFFSET_NL_ON 23530 //23530 --> 360Vdc/5Vdd
187 #define VOLTAGE_OFFSET_NL_OFF 24837 //24837 --> 380Vdc/5Vdd
196 #define VDC_START_MIN_INV 25490 // 25490 --> 390VDC/5Vdd
198 #define VDC_START_MAX_INV 26798 // 26798 --> 410VDC/5Vdd
201 #define VDC_STOP_MIN_INV 22876 // 22876 --> 350VDC/5Vdd // 24183 --> 370VDC/5Vdd
203 #define VDC_STOP_MAX_INV 29412 // 29412 --> 450VDC/5Vdd // 28105 --> 430VDC/5Vdd
212 #define ST_STB_BOP_CHECK_BULK 190 //380
214 #define ST_STB_BOP_SFTSTRT_WAIT (20+ST_STB_BOP_CHECK_BULK) //(40+ST_STB_BOP_CHECK_BULK)
216 #define ST_STB_BOP_END (ST_STB_BOP_SFTSTRT_WAIT+1)
218 #define ST_SFTSTRT_END (ST_STB_BOP_END+7)
226 #define VIN_OFF_THRSLD 179 //245 //326 --> 40Vac //245 --> 30Vac //204 --> 25Vac //179 --> 22Vac //163 --> 20Vac
228 #define VIN_ON_THRSLD 98 //151 --> 18.5Vac //138 --> 17Vac //98 --> 12Vac //122 --> 15Vac
229 #if !(VIN_OFF_THRSLD >= VIN_ON_THRSLD)
230 #error "OFF threshold should be greater than ON threshold"
233 #define VIN_ZERO_THRSLD 65 //98 --> 12Vac //65 --> 8Vac //20 IS DEBUG VALUE!!!
234 #if !(VIN_ON_THRSLD >= VIN_ZERO_THRSLD)
235 #error "ON threshold should be greater than ZERO threshold"
239 #define PWM_TRANSITION_DLY (18) //(18) --> 65kHz(15.3us) rate, 277us; (14) --> 45kHz(22.2us) rate, 311us; (4) --> 10kHz(100us) rate, 400us;
241 #define AC_LCDO_DETECT (130) //(130) --> 65kHz(15.3us) rate, 2ms; (90) --> 45kHz(22.2us) rate, 2ms; (20) --> 10kHz(100us) rate, 2ms;
243 #define AFTER_ACLOST_TIME (2600) //(2600) --> 65kHz(15.3us) rate, 40ms;
246 #define SR_DELAY_SWCYC 2 //3 //6
249 #define AC_400V 3268 //3268 is 400V in qVin_AC units
262 ST_SOFT_START = 0x04,
271 #define PFC_RUNNING (0x04|0x08)
382 static volatile bool acok =
false;
438 PORT0->IOCR0 &= ~(uint32_t)(0x7c0000UL);
439 PORT1->IOCR0 &= ~(uint32_t)(0x7c000000UL);
447 PORT0->IOCR0 |= 0x009C0000;
448 PORT1->IOCR0 |= 0x94000000;
456 PORT0-> OMR = (uint32_t)((0x10000U << 8) | (0x10000U << 9));
464 PORT0-> OMR = (uint32_t)((0x1U << 8) | (0x10000U << 9));
472 PORT0-> OMR = (uint32_t)((0x1U << 9) | (0x10000U << 8));
480 PORT0->OMR = (uint32_t)0x1U << 11;
488 PORT0-> OMR = (uint32_t)0x10000U << 11;
493 __STATIC_INLINE __attribute__((section(
".ram_code"))) void
497 CCU80_CC81->CR1S = duty;
499 CCU80_CC81->CR2S = duty >> 1;
503 CCU80->GCSS |= (CCU8_GCSS_S1SE_Msk);
507 __STATIC_INLINE __attribute__((section(
".ram_code"))) void
511 CCU80_CC81->CR1S = duty;
514 CCU80_CC81->CR2S = duty >> 1;
517 CCU80_CC82->CR1S = (period + duty) >> 1;
531 CCU80->GCSS |= (CCU8_GCSS_S1SE_Msk | CCU8_GCSS_S2SE_Msk | CCU8_GCSS_S3SE_Msk);
535 __STATIC_INLINE __attribute__((section(
".ram_code"))) void
539 CCU80_CC81->CR1S = duty;
541 CCU80_CC81->CR2S = duty >> 1;
543 CCU80_CC82->CR1S = (period + duty) >> 1;
546 CCU80_CC81->PRS = period;
549 CCU80->GCSS |= (CCU8_GCSS_S1SE_Msk | CCU8_GCSS_S2SE_Msk);
559 __attribute__((section(
".ram_code")))
599 __attribute__((section(
".ram_code")))
652 __attribute__((section(
".ram_code")))
700 #if (ILOOP_COEFF_Q < 14)
752 __attribute__((section(
".ram_code")))
814 __attribute__((section(
".ram_code")))
837 else if (PFC.
qiL_k < 0)
862 __attribute__((section(
".ram_code")))
899 __attribute__((section(
".ram_code")))
954 __attribute__((section(
".ram_code")))
1012 #ifndef DOXYGEN_SKIP
1013 __attribute__((section(
".ram_code")))
1245 #ifndef DOXYGEN_SKIP
1246 __attribute__((section(
".ram_code")))
1309 #ifndef DOXYGEN_SKIP
1310 __attribute__((section(
".ram_code")))
1327 MATH ->DVD = 0x7FFFFFFF;
1357 while (MATH ->DIVST);
1370 #ifndef DOXYGEN_SKIP
1371 __attribute__((section(
".ram_code")))
1558 #ifndef DOXYGEN_SKIP
1559 __attribute__((section(
".ram_code")))
1563 static uint16_t plrty_transition_dly_OFF,plrty_transition_dly_ON;
1576 if(plrty_transition_dly_OFF == 0)
1677 if ((ac_polarity.gpio_port->IN) & 0x10)
1712 pwm_pfc.ccu8_slice_ptr->CHC |= ((1 << CCU8_CC8_CHC_OCS1_Pos) | (1 << CCU8_CC8_CHC_OCS2_Pos));
1715 peak_PWM_trap.eru->EXOCON[0] = 0x2004;
1720 pwm_pfc.ccu8_slice_ptr->CHC &= ~(CCU8_CC8_CHC_OCS1_Msk | CCU8_CC8_CHC_OCS2_Msk);
1723 peak_PWM_trap.eru->EXOCON[0] = 0x8004;
1734 pwm_pfc.ccu8_slice_ptr->CHC &= ~(CCU8_CC8_CHC_OCS1_Msk | CCU8_CC8_CHC_OCS2_Msk);
1737 peak_PWM_trap.eru->EXOCON[0] = 0x8004;
1742 pwm_pfc.ccu8_slice_ptr->CHC |= ((1 << CCU8_CC8_CHC_OCS1_Pos) | (1 << CCU8_CC8_CHC_OCS2_Pos));
1745 peak_PWM_trap.eru->EXOCON[0] = 0x2004;
1758 if(plrty_transition_dly_ON == 0)
1897 if(plrty_transition_dly_OFF)
1899 plrty_transition_dly_OFF--;
1902 if(plrty_transition_dly_ON)
1904 plrty_transition_dly_ON--;