3.3kW Totem-pole PFC with SiC and XMC1404
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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   3986
 
#define COEFF_SLOPE_3k_Q   4901
 
#define COEFF_MIN_3k_Q   776
 
#define ZERO_LOC_3k_Q   15564
 
#define REG1_ILIMIT_Q15   21459
 
#define COEFF_a0_INEG_Q   3349
 
#define INEG_FAULT_Q15   -4256
 
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
}
 
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 (int16_t duty)
 
__STATIC_INLINE void set_duty_ADC (int16_t duty, int16_t period)
 
__STATIC_INLINE void set_duty_period (int16_t duty, int16_t period)
 
static void iL_offset_calc ()
 Current offset calculation based on averaging ADC samples without 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.
More...
 
static void iL_deadtime ()
 Dead time modification based on sensed current.
Parameters for calculation can be changed through UART communication. 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. 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
22.05.2019

Macro Definition Documentation

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

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

#define COEFF_MIN_3k_Q   776

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

#define COEFF_OFFSET_3k_Q   3986

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

#define COEFF_SLOPE_3k_Q   4901

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   -4256

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   21459

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 Documentation

Structure for the PFC related variables

typedef enum fault fault_t

Defined fault states used to manage the converter protections.

Enum to hold the input voltage polarity

typedef struct PFC_var PFC_var_t

Structure for the PFC related variables

typedef enum state state_t

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

Enumeration Type Documentation

enum AC_LCDO_t

Defined conditions for AC lost management

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

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.

Enum to hold the input voltage polarity

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.

enum state

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

Function Documentation

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.

Returns
None
Todo:
include status_reg to know if the unit can restart or not?
Todo:
If PWM will resume at AC zero cross and the duty is fixed at VAC_OFF Why to do this here?
Todo:
WHAT TO DO WITH THE RELAY IN INVERTER MODE AND BULK OUT OF RANGE
static void iL_coeff ( )
inlinestatic

Current loop coefficients according to the sensed currents.

Returns
None
static void iL_deadtime ( )
inlinestatic

Dead time modification based on sensed current.
Parameters for calculation can be changed through UART communication.

Returns
None
static void iL_loop ( )
inlinestatic

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

Returns
None
static void iL_modif ( )
inlinestatic

Current rectification according to polarity and offset removal.

Returns
None
static void iL_offset_calc ( )
inlinestatic

Current offset calculation based on averaging ADC samples without power stage.

Returns
None
static void iL_ref ( )
inlinestatic

Current reference calculation for next loop iteration.

Returns
None
static void inv_RMS_acok ( )
inlinestatic

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

Returns
None
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
static void notch_filter_Vbulk ( )
inlinestatic

Notch filter of bulk voltage for voltage loop.

Returns
None
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
__STATIC_INLINE void PWM_OFF ( )

Configure P0.2 and P1.3 as GPIO

__STATIC_INLINE void PWM_ON ( )

Configure P0.2 and P1.3 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 ( int16_t  duty)

Modify duty cycle of the PFC-PWM and the trigger of the 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

__STATIC_INLINE void set_duty_period ( int16_t  duty,
int16_t  period 
)

Modify duty cycle and 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

static void state_machine ( )
inlinestatic

State machine for start up process.

Returns
None
static void Vbulk_ctrl_loop ( )
inlinestatic

Voltage loop.

Returns
None

Variable Documentation

volatile AC_monitoring_t AC_zero_cross
static

Instance of the AC zero crossing management

volatile bool acok = false
static

AC lost detection variable

volatile uint8_t acok_counter = 0
static

Check if AC is valid

volatile uint8_t count_Vout_OVP_resume = 0
static

Counter for time filtering of bulk voltage OVP operation resume

volatile uint8_t count_Vout_OVP_stop = 0
static

Counter for time filtering of bulk voltage OVP detection

volatile uint8_t iDebug = 0
static

Counter for debugging.

volatile grid_voltage_t input_polarity[2]
static

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

volatile uint8_t input_polarity_count
static

Time filter for polarity change detection.

volatile int16_t offset_detected = 0
static

Error outside the defined slot is detected (LCDO)

volatile uint16_t stb_bop_count = 0
static

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

volatile uint32_t Vrms2 = 0
static

Vrms^2 calculation.