3.3kW Totem-pole PFC with CoolMOS and XMC1402
control_interrupts.h File Reference

Interrupts code. More...

#include <DAVE.h>
#include "init_bckgnd_funct.h"
#include "communication.h"

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
 

Detailed Description

Interrupts code.

Author
Meneses Herrera, David; Escudero Rodriguez, Manuel
Date
28.12.2020

Macro Definition Documentation

◆ AC_400V

#define AC_400V   3268

Limit of AC voltage for duty feed-forward calculation.

◆ AC_LCDO_DETECT

#define AC_LCDO_DETECT   (130)

Number of samples of AC voltage under OFF_THRSLD to consider AC lost. [Tsw].

◆ ACCOMP_TO_Q15

#define ACCOMP_TO_Q15   21

Shifting for AC sensing compensation in current reference calculation: Qx to Q15

◆ ADC_TO_IIR

#define ADC_TO_IIR   (IIR_QFORMAT+ADC_TO_Q15)

Shift for RMS filter input

◆ ADC_TO_Q15

#define ADC_TO_Q15   3

ADC normalization shift (Q15)

◆ AFTER_ACLOST_TIME

#define AFTER_ACLOST_TIME   (2600)

Counting time limit after AC lost is detected. [Tsw].

◆ COEFF_a0_INEG_Q

#define COEFF_a0_INEG_Q   (3373)

Current coefficient when negative current detected: a0 at max. allowed negative current (around 10A)

◆ COEFF_MIN_3k_Q

#define COEFF_MIN_3k_Q   (473)

Current coefficient slope of single linear region, considering linear variation of the inductance

◆ COEFF_OFFSET_3k_Q

#define COEFF_OFFSET_3k_Q   (4140)

Current coefficient offset of single linear region (coefficient for 0A operation)

◆ COEFF_SLOPE_3k_Q

#define COEFF_SLOPE_3k_Q   (5928)

Current coefficient slope of single linear region, considering linear variation of the inductance

◆ CURRENT_REF_TO_Q15

#define CURRENT_REF_TO_Q15   19

Current reference adaptation to Q15 representation

◆ DT_CONST_ILIMIT_Q15

#define DT_CONST_ILIMIT_Q15   1788

Dead time is constant (maximum) until certain current, from which linear variation of dead time is applied.

◆ DT_D2S

#define DT_D2S   5

Constant dead time is applied in the diode to switch (ST falling) transition.

◆ DT_REG1_ILIMIT_Q15

#define DT_REG1_ILIMIT_Q15   4172

Limit of the first region of linear approximation for dead time calculation.

◆ DT_REG1_OFFSET

#define DT_REG1_OFFSET   17

Offset value (0A) of the first region of linear approximation for dead time calculation.

◆ DT_REG1_SLOPEQ15

#define DT_REG1_SLOPEQ15   82

Slope of the first region of linear approximation for dead time calculation.

◆ DT_REG2_ILIMIT_Q15

#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.

◆ DT_REG2_OFFSET

#define DT_REG2_OFFSET   10

Offset value (0A) of the second region of linear approximation for dead time calculation.

◆ DT_REG2_SLOPEQ15

#define DT_REG2_SLOPEQ15   27

Slope of the second region of linear approximation for dead time calculation.

◆ DT_S2D_MAX

#define DT_S2D_MAX   12

Maximum dead time applied in the switch to diode (ST rising) transition.

◆ DT_S2D_MIN

#define DT_S2D_MIN   4

Minimum dead time applied in the switch to diode (ST rising) transition.

◆ DT_SLOPE_Q

#define DT_SLOPE_Q   15

Shifting for dead time calculation; slope is codified in Q15

◆ IIR_QFORMAT

#define IIR_QFORMAT   14

RMS filter coefficient format

◆ IL_AVG_GAIN

#define IL_AVG_GAIN   31129

SW current gain: 1.9.

◆ IL_AVG_GAIN_Q

#define IL_AVG_GAIN_Q   14

SW current gain Q representation

◆ ILOOP_COEFF_Q

#define ILOOP_COEFF_Q   (14)

Current coefficient Q representation

◆ INEG_FAULT_Q15

#define INEG_FAULT_Q15   (-4238)

Negative current for fast converter turn off

◆ LPF_TO_2ADC

#define LPF_TO_2ADC   (ADC_TO_IIR-1)

Shift of RMS filter for Iref calculation

◆ NOTCH_TO_Q15

#define NOTCH_TO_Q15   14

Shift of DC filter output (notch) in voltage loop

◆ OFFSET_END

#define OFFSET_END   0xFFFF

Count value when the offset calculation is done.

◆ OFFSET_SAMPLES

#define OFFSET_SAMPLES   256

Number of samples to be acquire for zero current offset calculation.

◆ OFFSET_SAMPLES_2

#define OFFSET_SAMPLES_2   8

Number of samples to be acquire for zero current offset calculation, in power of 2.

◆ OFFSET_VAC

#define OFFSET_VAC   432

Vac voltage under which the current offset measurement is allowed, to avoid capacitor charge current.

◆ PFC_RUNNING

#define PFC_RUNNING   (0x04|0x08)

PWM is on during converter operation, e.g. soft-start and running operation.

◆ PR_MAX

#define PR_MAX   1475

Switching period to be applied in nominal and high voltage input voltage operation.

◆ PWM_TRANSITION_DLY

#define PWM_TRANSITION_DLY   (18)

Limitation of Vac ON/OFF detection delay after Vac OFF/ON detection. [Tsw].

◆ REG1_ILIMIT_Q15

#define REG1_ILIMIT_Q15   (20267)

Current limit for single linear variation of the inductance

◆ SR_DELAY_SWCYC

#define SR_DELAY_SWCYC   2

Number of switching cycles to delay the starting of the PWM/SR.

◆ ST_SFTSTRT_END

#define ST_SFTSTRT_END   (ST_STB_BOP_END+7)

Number of cycles set to high value after soft-start process is done.

◆ ST_STB_BOP_CHECK_BULK

#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.

◆ ST_STB_BOP_END

#define ST_STB_BOP_END   (ST_STB_BOP_SFTSTRT_WAIT+1)

Cycle after waiting time the converter operation can start.

◆ ST_STB_BOP_SFTSTRT_WAIT

#define ST_STB_BOP_SFTSTRT_WAIT   (20+ST_STB_BOP_CHECK_BULK)

Number of cycles before starting the converter after closing the relay.

◆ TO_QiLOOP

#define TO_QiLOOP   15

Shifting for coefficient calculation: Q29 to Q14

◆ VDC_START_MAX_INV

#define VDC_START_MAX_INV   26798

Inverter starts with bulk voltage lower than 410V (Q15).

◆ VDC_START_MIN_INV

#define VDC_START_MIN_INV   25490

Inverter starts with bulk voltage higher than 390V (Q15).

◆ VDC_STOP_MAX_INV

#define VDC_STOP_MAX_INV   29412

Inverter stops with bulk voltage higher than 430V (Q15).

◆ VDC_STOP_MIN_INV

#define VDC_STOP_MIN_INV   22876

Inverter stops with bulk voltage lower than 370V (Q15).

◆ VIN_OFF_THRSLD

#define VIN_OFF_THRSLD   179

Input voltage for zero crossing detection. PFC is turned off. [ADC_units]

◆ VIN_ON_THRSLD

#define VIN_ON_THRSLD   98

Input voltage to resume operation after zero crossing. [ADC_units]

◆ VIN_ZERO_THRSLD

#define VIN_ZERO_THRSLD   65

Input voltage for zero crossing detection. Slope change detection. [ADC_units]

◆ VOLTAGE_OFFSET_NL_OFF

#define VOLTAGE_OFFSET_NL_OFF   24837

Output voltage offset limit to stop applying non-linear loop error.

◆ VOLTAGE_OFFSET_NL_ON

#define VOLTAGE_OFFSET_NL_ON   23530

Output voltage offset limit to apply non-linear loop error.

◆ VOUT_OFFSET

#define VOUT_OFFSET   392

Adjustable offset for output voltage, Q15 representation

◆ VOUT_OFFSET_LCDO

#define VOUT_OFFSET_LCDO   0

Adjustable offset for output voltage after AC lost is detected, Q15 representation

◆ VOUT_OVP_STOP

#define VOUT_OVP_STOP   29412+VOUT_OFFSET

Maximum bulk voltage allowed, Q15 representation. Reaching this voltage starts "burst mode"

◆ VOUT_START_MIN

#define VOUT_START_MIN   14789

Output voltage before start-up must be higher than 160*sqrt(2) (Q15).

◆ VOUT_STEADY

#define VOUT_STEADY   26144+VOUT_OFFSET

Bulk voltage target, Q15 representation. Used for the control loop reference and resume value after OVP

◆ VOUT_UVP_MIN

#define VOUT_UVP_MIN   19608

Undervoltage protection (300V). Turns PFC off and open relay. (Q15)

◆ ZERO_LOC_3k_Q

#define ZERO_LOC_3k_Q   (15564)

Zero location of the current compensator (ILOOP_COEFF_Q format)

Typedef Documentation

◆ AC_monitoring_t

Structure for the PFC related variables

◆ fault_t

typedef enum fault fault_t

Defined fault states used to manage the converter protections.

◆ grid_voltage_t

Enum to hold the input voltage polarity

◆ PFC_var_t

typedef struct PFC_var PFC_var_t

Structure for the PFC related variables

◆ state_t

typedef enum state state_t

Defined states to be used in the starting sequence and state machine.

Enumeration Type Documentation

◆ AC_LCDO_t

enum AC_LCDO_t

Defined conditions for AC lost management

◆ comp_BW_t

enum comp_BW_t

Define applied current controller BW.

Enumerator
BW_L 

Low BW (3kHz) applied

BW_H 

High BW (6kHz) applied around AC zero crossing

◆ fault

enum fault

Defined fault states used to manage the converter protections.

Enumerator
F_INIT 

Initial status / NO FAULT.

F_OVP 

Bulk over-voltage triggered (PFC).

F_BOP 

RMS input voltage out of range.

F_UVP 

Bulk under-voltage triggered (PFC).

F_PEAK 

NOT USED in this implementation.

F_OTP 

NOT USED in this implementation.

F_NEG_I 

Negative current in respect to reference. Flag to turn off the converter.

F_DC_INV 

DC voltage is out of range in Inverter operation.

◆ grid_voltage

Enum to hold the input voltage polarity

◆ op_mode_t

enum op_mode_t

Operation mode, decided in application start.

Enumerator
PFC_MODE 

Converter operates as PFC - AC/DC.

INVERTER_MODE 

Converter operates as Inverter - DC/AC.

◆ state

enum state

Defined states to be used in the starting sequence and state machine.

Function Documentation

◆ bulk_monitoring()

static void bulk_monitoring ( )
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!

Returns
None
Todo:
include status_reg to know if the unit can restart or not?
Todo:
WHAT TO DO WITH THE RELAY IN INVERTER MODE AND BULK OUT OF RANGE

◆ iL_coeff()

static void iL_coeff ( )
inlinestatic

Current loop coefficients according to the sensed currents.
Single linear approximation.

Returns
None

◆ iL_deadtime()

static void iL_deadtime ( )
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.

Returns
None

◆ iL_loop()

static void iL_loop ( )
inlinestatic

Current loop and duty feed-forward (DFF) calculation.
DFF is calculated assuming fixed 400V output.

Returns
None

◆ iL_modif()

static void iL_modif ( )
inlinestatic

Current rectification according to polarity and offset removal.

Returns
None

◆ iL_offset_calc()

static void iL_offset_calc ( )
inlinestatic

Current offset calculation based on averaging ADC samples before start-up of the power stage.

Returns
None

◆ iL_ref()

static void iL_ref ( )
inlinestatic

Current reference calculation for next loop iteration.

Returns
None

◆ inv_RMS_acok()

static void inv_RMS_acok ( )
inlinestatic

1/RMS^2 for line feed-forward in the current reference calculation.

Returns
None

◆ lpf_filter_RMS()

static void lpf_filter_RMS ( )
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.

Returns
None

◆ notch_filter_Vbulk()

static void notch_filter_Vbulk ( )
inlinestatic

Notch filter of bulk voltage for voltage loop.

Returns
None

◆ pseudo_pll()

static void pseudo_pll ( )
inlinestatic

AC zero crossing management.
High-frequency and Low-frequency signals management.

Returns
None
Todo:
Include more info: graphs and "state machine" for better understanding
Todo:
What happens if it is because of wrong polarity?
Todo:
Duty soft-start after LCDO
Todo:
PFC MODE ONLY CONSIDERED

◆ PWM_OFF()

__STATIC_INLINE void PWM_OFF ( )

Configure P0.2 and P0.6 as GPIO

◆ PWM_ON()

__STATIC_INLINE void PWM_ON ( )

Configure P0.2 and P0.6 as PWM output

◆ relay_OFF()

__STATIC_INLINE void relay_OFF ( )

Relay off: P0.11 –> low

◆ relay_ON()

__STATIC_INLINE void relay_ON ( )

Relay on: P0.11 –> high

◆ set_duty_ADC()

__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

◆ set_period()

__STATIC_INLINE void set_period ( int16_t  period)

Modify switching frequency of the PFC-PWM.

◆ SR_HS_ON()

__STATIC_INLINE void SR_HS_ON ( )

Set P0.8 and Reset P0.9 GPIO

◆ SR_LS_ON()

__STATIC_INLINE void SR_LS_ON ( )

Set P0.9 and Reset P0.8 GPIO

◆ SR_OFF()

__STATIC_INLINE void SR_OFF ( )

Reset P0.8 and P0.9 GPIO

◆ state_machine()

static void state_machine ( )
inlinestatic

State machine for start up process.

Returns
None

◆ Vbulk_ctrl_loop()

static void Vbulk_ctrl_loop ( )
inlinestatic

Voltage loop.

Returns
None

Variable Documentation

◆ AC_zero_cross

volatile AC_monitoring_t AC_zero_cross
static

Instance of the AC zero crossing management

◆ acok

volatile bool acok = false
static

AC lost detection variable

◆ acok_counter

volatile uint8_t acok_counter = 0
static

Check if AC is valid

◆ count_Vout_OVP_resume

volatile uint8_t count_Vout_OVP_resume = 0
static

Counter for time filtering of bulk voltage OVP operation resume

◆ count_Vout_OVP_stop

volatile uint8_t count_Vout_OVP_stop = 0
static

Counter for time filtering of bulk voltage OVP detection

◆ iDebug

volatile uint8_t iDebug = 0
static

Counter for debugging.

◆ input_polarity

volatile grid_voltage_t input_polarity[2]
static

Check the polarity to differentiate the AC zero edge and detect positive or negative input voltage.

◆ input_polarity_count

volatile uint8_t input_polarity_count
static

Time filter for polarity change detection.

◆ offset_detected

volatile int16_t offset_detected = 0
static

Error outside the defined slot is detected (LCDO)

◆ stb_bop_count

volatile uint16_t stb_bop_count = 0
static

Counter for managing soft-start process in state machine after input voltage is in range.

◆ Vrms2

volatile uint32_t Vrms2 = 0
static

Vrms^2 calculation.