|
3.3kW Totem-pole PFC with CoolMOS and XMC1402
|
Interrupts code. More...
Go to the source code of this file.
Data Structures | |
| struct | PFC_var |
| struct | AC_monitoring |
Macros | |
| #define | PFC_RUNNING (0x04|0x08) |
Shifting related macros | |
| #define | ADC_TO_Q15 3 |
| #define | IIR_QFORMAT 14 |
| #define | ADC_TO_IIR (IIR_QFORMAT+ADC_TO_Q15) |
| #define | LPF_TO_2ADC (ADC_TO_IIR-1) |
| #define | NOTCH_TO_Q15 14 |
| #define | TO_QiLOOP 15 |
| #define | CURRENT_REF_TO_Q15 19 |
| #define | ACCOMP_TO_Q15 21 |
Current offset and gain macros | |
| #define | OFFSET_SAMPLES_2 8 |
| #define | OFFSET_SAMPLES 256 |
| #define | OFFSET_END 0xFFFF |
| #define | OFFSET_VAC 432 |
| #define | IL_AVG_GAIN 31129 |
| #define | IL_AVG_GAIN_Q 14 |
Current loop coefficients calculation, CCM | |
| #define | ILOOP_COEFF_Q (14) |
| #define | COEFF_OFFSET_3k_Q (4140) |
| #define | COEFF_SLOPE_3k_Q (5928) |
| #define | COEFF_MIN_3k_Q (473) |
| #define | ZERO_LOC_3k_Q (15564) |
| #define | REG1_ILIMIT_Q15 (20267) |
| #define | COEFF_a0_INEG_Q (3373) |
| #define | INEG_FAULT_Q15 (-4238) |
Dead time and frequency modification | |
| #define | DT_CONST_ILIMIT_Q15 1788 |
| #define | DT_REG1_ILIMIT_Q15 4172 |
| #define | DT_REG2_ILIMIT_Q15 6556 |
| #define | DT_D2S 5 |
| #define | DT_S2D_MAX 12 |
| #define | DT_S2D_MIN 4 |
| #define | DT_REG1_OFFSET 17 |
| #define | DT_REG1_SLOPEQ15 82 |
| #define | DT_REG2_OFFSET 10 |
| #define | DT_REG2_SLOPEQ15 27 |
| #define | DT_SLOPE_Q 15 |
| #define | PR_MAX 1475 |
Bulk voltage PFC related macros | |
| #define | VOUT_OFFSET 392 |
| #define | VOUT_OFFSET_LCDO 0 |
| #define | VOUT_STEADY 26144+VOUT_OFFSET |
| #define | VOUT_OVP_STOP 29412+VOUT_OFFSET |
| #define | VOUT_UVP_MIN 19608 |
| #define | VOUT_START_MIN 14789 |
| #define | VOLTAGE_OFFSET_NL_ON 23530 |
| #define | VOLTAGE_OFFSET_NL_OFF 24837 |
Bulk voltage Inverter related macros | |
| #define | VDC_START_MIN_INV 25490 |
| #define | VDC_START_MAX_INV 26798 |
| #define | VDC_STOP_MIN_INV 22876 |
| #define | VDC_STOP_MAX_INV 29412 |
Soft start related macros | |
| #define | ST_STB_BOP_CHECK_BULK 190 |
| #define | ST_STB_BOP_SFTSTRT_WAIT (20+ST_STB_BOP_CHECK_BULK) |
| #define | ST_STB_BOP_END (ST_STB_BOP_SFTSTRT_WAIT+1) |
| #define | ST_SFTSTRT_END (ST_STB_BOP_END+7) |
AC input related macros | |
| #define | VIN_OFF_THRSLD 179 |
| #define | VIN_ON_THRSLD 98 |
| #define | VIN_ZERO_THRSLD 65 |
| #define | PWM_TRANSITION_DLY (18) |
| #define | AC_LCDO_DETECT (130) |
| #define | AFTER_ACLOST_TIME (2600) |
| #define | SR_DELAY_SWCYC 2 |
| #define | AC_400V 3268 |
Typedefs | |
| typedef enum state | state_t |
| typedef enum fault | fault_t |
| typedef struct PFC_var | PFC_var_t |
| typedef struct AC_monitoring | AC_monitoring_t |
| typedef enum grid_voltage | grid_voltage_t |
Enumerations | |
| enum | state { ST_INIT = 0x00, ST_STB = 0x01, ST_STB_BOP = 0x02, ST_SOFT_START = 0x04, ST_RUNNING = 0x08, ST_LATCH = 0x10, ST_START_EN = 0x20, ST_CLR_OVP = 0x40 } |
| enum | fault { F_INIT = 0x0, F_OVP = 0x1, F_BOP = 0x2, F_UVP = 0x4, F_PEAK = 0x8, F_OTP = 0x10, F_NEG_I = 0x20, F_DC_INV = 0x40 } |
| enum | comp_BW_t { BW_L = 0, BW_H = 1 } |
| enum | op_mode_t { PFC_MODE = 0, INVERTER_MODE = 1 } |
| enum | AC_LCDO_t { NO_LCDO = 0x0, LCDO_DETECTED = 0x1, AFTER_LCDO = 0x2 } |
| enum | grid_voltage { NEGATIVE, POSITIVE } |
Functions | |
| __STATIC_INLINE void | PWM_OFF () |
| __STATIC_INLINE void | PWM_ON () |
| __STATIC_INLINE void | SR_OFF () |
| __STATIC_INLINE void | SR_HS_ON () |
| __STATIC_INLINE void | SR_LS_ON () |
| __STATIC_INLINE void | relay_ON () |
| __STATIC_INLINE void | relay_OFF () |
| __STATIC_INLINE void | set_duty_ADC (int16_t duty, int16_t period) |
| __STATIC_INLINE void | set_period (int16_t period) |
| static void | iL_offset_calc () |
| Current offset calculation based on averaging ADC samples before start-up of the power stage. More... | |
| static void | iL_modif () |
| Current rectification according to polarity and offset removal. More... | |
| static void | iL_loop () |
| Current loop and duty feed-forward (DFF) calculation. DFF is calculated assuming fixed 400V output. More... | |
| static void | iL_ref () |
| Current reference calculation for next loop iteration. More... | |
| static void | iL_coeff () |
| Current loop coefficients according to the sensed currents. Single linear approximation. More... | |
| static void | iL_deadtime () |
| Dead time modification based on sensed current. Parameters for calculation can be changed through UART communication –> NOT USED IN THIS SW VERSION. Dead time has to be update in rising or falling edge depending of polarity since there is no change in timer pin configuration. More... | |
| static void | notch_filter_Vbulk () |
| Notch filter of bulk voltage for voltage loop. More... | |
| static void | lpf_filter_RMS () |
| LPF of AC voltage for "RMS" calculation. The result is the average of the AC voltage, which is proportional to the AC RMS value. More... | |
| static void | state_machine () |
| State machine for start up process. More... | |
| static void | Vbulk_ctrl_loop () |
| Voltage loop. More... | |
| static void | inv_RMS_acok () |
| 1/RMS^2 for line feed-forward in the current reference calculation. More... | |
| static void | bulk_monitoring () |
| Bulk voltage monitoring. OVP and UVP during operation for PFC. In inverter operation the DC range is monitored (hysteresis). Latching for debugging. NO INVERTER OPERATION IN THIS SW VERSION! More... | |
| static void | pseudo_pll () |
| AC zero crossing management. High-frequency and Low-frequency signals management. More... | |
Variables | |
| static volatile uint32_t | Vrms2 = 0 |
| static volatile int16_t | offset_detected = 0 |
| static volatile uint8_t | iDebug = 0 |
| __IO uint32_t * | ADCResult_iL |
| __IO uint32_t * | ADCResult_DCBus |
| __IO uint32_t * | ADCResult_VAC |
| __IO uint32_t * | ADCResult_Temp |
| __IO uint32_t * | ADCResult_BOP |
| volatile PFC_var_t | PFC |
| volatile state_t | status_reg |
| volatile fault_t | fault_reg |
Soft start. | |
| static volatile uint16_t | stb_bop_count = 0 |
AC lost detection (LCDO) | |
| static volatile uint8_t | acok_counter = 0 |
| static volatile bool | acok = false |
OVP variables | |
| static volatile uint8_t | count_Vout_OVP_stop = 0 |
| static volatile uint8_t | count_Vout_OVP_resume = 0 |
Input frequency and polarity check. | |
| static volatile grid_voltage_t | input_polarity [2] |
| static volatile uint8_t | input_polarity_count |
| static volatile AC_monitoring_t | AC_zero_cross |
Interrupts code.
| #define AC_400V 3268 |
Limit of AC voltage for duty feed-forward calculation.
| #define AC_LCDO_DETECT (130) |
Number of samples of AC voltage under OFF_THRSLD to consider AC lost. [Tsw].
| #define ACCOMP_TO_Q15 21 |
Shifting for AC sensing compensation in current reference calculation: Qx to Q15
| #define ADC_TO_IIR (IIR_QFORMAT+ADC_TO_Q15) |
Shift for RMS filter input
| #define ADC_TO_Q15 3 |
ADC normalization shift (Q15)
| #define AFTER_ACLOST_TIME (2600) |
Counting time limit after AC lost is detected. [Tsw].
| #define COEFF_a0_INEG_Q (3373) |
Current coefficient when negative current detected: a0 at max. allowed negative current (around 10A)
| #define COEFF_MIN_3k_Q (473) |
Current coefficient slope of single linear region, considering linear variation of the inductance
| #define COEFF_OFFSET_3k_Q (4140) |
Current coefficient offset of single linear region (coefficient for 0A operation)
| #define COEFF_SLOPE_3k_Q (5928) |
Current coefficient slope of single linear region, considering linear variation of the inductance
| #define CURRENT_REF_TO_Q15 19 |
Current reference adaptation to Q15 representation
| #define DT_CONST_ILIMIT_Q15 1788 |
Dead time is constant (maximum) until certain current, from which linear variation of dead time is applied.
| #define DT_D2S 5 |
Constant dead time is applied in the diode to switch (ST falling) transition.
| #define DT_REG1_ILIMIT_Q15 4172 |
Limit of the first region of linear approximation for dead time calculation.
| #define DT_REG1_OFFSET 17 |
Offset value (0A) of the first region of linear approximation for dead time calculation.
| #define DT_REG1_SLOPEQ15 82 |
Slope of the first region of linear approximation for dead time calculation.
| #define DT_REG2_ILIMIT_Q15 6556 |
Limit of the second region of linear approximation for dead time calculation. From this point constant (minimum) dead time is applied.
| #define DT_REG2_OFFSET 10 |
Offset value (0A) of the second region of linear approximation for dead time calculation.
| #define DT_REG2_SLOPEQ15 27 |
Slope of the second region of linear approximation for dead time calculation.
| #define DT_S2D_MAX 12 |
Maximum dead time applied in the switch to diode (ST rising) transition.
| #define DT_S2D_MIN 4 |
Minimum dead time applied in the switch to diode (ST rising) transition.
| #define DT_SLOPE_Q 15 |
Shifting for dead time calculation; slope is codified in Q15
| #define IIR_QFORMAT 14 |
RMS filter coefficient format
| #define IL_AVG_GAIN 31129 |
SW current gain: 1.9.
| #define IL_AVG_GAIN_Q 14 |
SW current gain Q representation
| #define ILOOP_COEFF_Q (14) |
Current coefficient Q representation
| #define INEG_FAULT_Q15 (-4238) |
Negative current for fast converter turn off
| #define LPF_TO_2ADC (ADC_TO_IIR-1) |
Shift of RMS filter for Iref calculation
| #define NOTCH_TO_Q15 14 |
Shift of DC filter output (notch) in voltage loop
| #define OFFSET_END 0xFFFF |
Count value when the offset calculation is done.
| #define OFFSET_SAMPLES 256 |
Number of samples to be acquire for zero current offset calculation.
| #define OFFSET_SAMPLES_2 8 |
Number of samples to be acquire for zero current offset calculation, in power of 2.
| #define OFFSET_VAC 432 |
Vac voltage under which the current offset measurement is allowed, to avoid capacitor charge current.
| #define PFC_RUNNING (0x04|0x08) |
PWM is on during converter operation, e.g. soft-start and running operation.
| #define PR_MAX 1475 |
Switching period to be applied in nominal and high voltage input voltage operation.
| #define PWM_TRANSITION_DLY (18) |
Limitation of Vac ON/OFF detection delay after Vac OFF/ON detection. [Tsw].
| #define REG1_ILIMIT_Q15 (20267) |
Current limit for single linear variation of the inductance
| #define SR_DELAY_SWCYC 2 |
Number of switching cycles to delay the starting of the PWM/SR.
| #define ST_SFTSTRT_END (ST_STB_BOP_END+7) |
Number of cycles set to high value after soft-start process is done.
| #define ST_STB_BOP_CHECK_BULK 190 |
Number of state-machine cycles (approx. 1.6ms - 5Khz/8) before checking the bulk voltage after input voltage is in range and the decision of closing the relay is taken.
| #define ST_STB_BOP_END (ST_STB_BOP_SFTSTRT_WAIT+1) |
Cycle after waiting time the converter operation can start.
| #define ST_STB_BOP_SFTSTRT_WAIT (20+ST_STB_BOP_CHECK_BULK) |
Number of cycles before starting the converter after closing the relay.
| #define TO_QiLOOP 15 |
Shifting for coefficient calculation: Q29 to Q14
| #define VDC_START_MAX_INV 26798 |
Inverter starts with bulk voltage lower than 410V (Q15).
| #define VDC_START_MIN_INV 25490 |
Inverter starts with bulk voltage higher than 390V (Q15).
| #define VDC_STOP_MAX_INV 29412 |
Inverter stops with bulk voltage higher than 430V (Q15).
| #define VDC_STOP_MIN_INV 22876 |
Inverter stops with bulk voltage lower than 370V (Q15).
| #define VIN_OFF_THRSLD 179 |
Input voltage for zero crossing detection. PFC is turned off. [ADC_units]
| #define VIN_ON_THRSLD 98 |
Input voltage to resume operation after zero crossing. [ADC_units]
| #define VIN_ZERO_THRSLD 65 |
Input voltage for zero crossing detection. Slope change detection. [ADC_units]
| #define VOLTAGE_OFFSET_NL_OFF 24837 |
Output voltage offset limit to stop applying non-linear loop error.
| #define VOLTAGE_OFFSET_NL_ON 23530 |
Output voltage offset limit to apply non-linear loop error.
| #define VOUT_OFFSET 392 |
Adjustable offset for output voltage, Q15 representation
| #define VOUT_OFFSET_LCDO 0 |
Adjustable offset for output voltage after AC lost is detected, Q15 representation
| #define VOUT_OVP_STOP 29412+VOUT_OFFSET |
Maximum bulk voltage allowed, Q15 representation. Reaching this voltage starts "burst mode"
| #define VOUT_START_MIN 14789 |
Output voltage before start-up must be higher than 160*sqrt(2) (Q15).
| #define VOUT_STEADY 26144+VOUT_OFFSET |
Bulk voltage target, Q15 representation. Used for the control loop reference and resume value after OVP
| #define VOUT_UVP_MIN 19608 |
Undervoltage protection (300V). Turns PFC off and open relay. (Q15)
| #define ZERO_LOC_3k_Q (15564) |
Zero location of the current compensator (ILOOP_COEFF_Q format)
| typedef struct AC_monitoring AC_monitoring_t |
Structure for the PFC related variables
| typedef enum grid_voltage grid_voltage_t |
Enum to hold the input voltage polarity
| enum AC_LCDO_t |
Defined conditions for AC lost management
| enum comp_BW_t |
| enum fault |
Defined fault states used to manage the converter protections.
| enum grid_voltage |
Enum to hold the input voltage polarity
| enum op_mode_t |
| enum state |
Defined states to be used in the starting sequence and state machine.
|
inlinestatic |
Bulk voltage monitoring.
OVP and UVP during operation for PFC.
In inverter operation the DC range is monitored (hysteresis). Latching for debugging. NO INVERTER OPERATION IN THIS SW VERSION!
|
inlinestatic |
Current loop coefficients according to the sensed currents.
Single linear approximation.
|
inlinestatic |
Dead time modification based on sensed current.
Parameters for calculation can be changed through UART communication –> NOT USED IN THIS SW VERSION.
Dead time has to be update in rising or falling edge depending of polarity since there is no change in timer pin configuration.
|
inlinestatic |
Current loop and duty feed-forward (DFF) calculation.
DFF is calculated assuming fixed 400V output.
|
inlinestatic |
Current rectification according to polarity and offset removal.
|
inlinestatic |
Current offset calculation based on averaging ADC samples before start-up of the power stage.
|
inlinestatic |
Current reference calculation for next loop iteration.
|
inlinestatic |
1/RMS^2 for line feed-forward in the current reference calculation.
|
inlinestatic |
LPF of AC voltage for "RMS" calculation.
The result is the average of the AC voltage, which is proportional to the AC RMS value.
|
inlinestatic |
Notch filter of bulk voltage for voltage loop.
|
inlinestatic |
| __STATIC_INLINE void PWM_OFF | ( | ) |
Configure P0.2 and P0.6 as GPIO
| __STATIC_INLINE void PWM_ON | ( | ) |
Configure P0.2 and P0.6 as PWM output
| __STATIC_INLINE void relay_OFF | ( | ) |
Relay off: P0.11 –> low
| __STATIC_INLINE void relay_ON | ( | ) |
Relay on: P0.11 –> high
| __STATIC_INLINE void set_duty_ADC | ( | int16_t | duty, |
| int16_t | period | ||
| ) |
Modify duty cycle of the PFC-PWM and the trigger of the ADC. Since the pin output config is not changed with polarity, ST must be propoerly set in this function
| __STATIC_INLINE void set_period | ( | int16_t | period | ) |
Modify switching frequency of the PFC-PWM.
| __STATIC_INLINE void SR_HS_ON | ( | ) |
Set P0.8 and Reset P0.9 GPIO
| __STATIC_INLINE void SR_LS_ON | ( | ) |
Set P0.9 and Reset P0.8 GPIO
| __STATIC_INLINE void SR_OFF | ( | ) |
Reset P0.8 and P0.9 GPIO
|
inlinestatic |
State machine for start up process.
|
inlinestatic |
Voltage loop.
|
static |
Instance of the AC zero crossing management
|
static |
AC lost detection variable
|
static |
Check if AC is valid
|
static |
Counter for time filtering of bulk voltage OVP operation resume
|
static |
Counter for time filtering of bulk voltage OVP detection
|
static |
Counter for debugging.
|
static |
Check the polarity to differentiate the AC zero edge and detect positive or negative input voltage.
|
static |
Time filter for polarity change detection.
|
static |
Error outside the defined slot is detected (LCDO)
|
static |
Counter for managing soft-start process in state machine after input voltage is in range.
|
static |
Vrms^2 calculation.