//----------------------------------------------------------------------------------
// FILE: HVLLC-Main.C
//
// Description: Half-Bridge LLC Resonant DC/DC Converter with Synchronous Rectification
//
// Version: 1.0
//
// Target: TMS320F2802x (PiccoloA),
//
//----------------------------------------------------------------------------------
// Copyright Texas Instruments � 2004-2010
//----------------------------------------------------------------------------------
// Revision History:
//----------------------------------------------------------------------------------
// Date | Description / Status
//----------------------------------------------------------------------------------
// May 15, 2011 - Release 1.0 (DC)
//----------------------------------------------------------------------------------
//
// PLEASE READ - Useful notes about this Project
// Although this project is made up of several files, the most important ones are:
// "HVLLC-Main.C" - this file
// - Application Initialization, Peripheral config,
// - Application management
// - Slower background code loops and Task scheduling
// "HVLLC-DevInit_F28xxx.C
// - Device Initialization, e.g. Clock, PLL, WD, GPIO mapping
// - Peripheral clock enables
// - DevInit file will differ per each F28xxx device series, e.g. F280x, F2833x,
// "HVLLC-DPL-ISR.asm
// - Assembly level library Macros and any cycle critical functions are found here
// "HVLLC-Settings.h"
// - Global defines (settings) project selections are found here
// - This file is referenced by both C and ASM files.
//
// Code is made up of sections, e.g. "FUNCTION PROTOTYPES", "VARIABLE DECLARATIONS" ,..etc
// each section has FRAMEWORK and USER areas.
// FRAMEWORK areas provide useful ready made "infrastructure" code which for the most part
// does not need modification, e.g. Task scheduling, ISR call, GUI interface support,...etc
// USER areas have functional example code which can be modified by USER to fit their appl.
//
// Code can be compiled with various build options (Incremental Builds IBx), these
// options are selected in file "HVLLC-Settings.h". Note: "Rebuild All" compile
// tool bar button must be used if this file is modified.
//----------------------------------------------------------------------------------
#include "PeripheralHeaderIncludes.h"
#include "DSP2802x_EPWM_defines.h"
#include "HVLLC-Settings.h"
#include "DPlib.h"
#include "IQmathLib.h"
#include <math.h>
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTION PROTOTYPES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Add protoypes of functions being used in the project here
extern interrupt void CNTL_ISR(void);
extern interrupt void PWM_ISR(void);
void DeviceInit(void);
#ifdef FLASH
void InitFlash();
#endif
void MemCopy();
void SCIA_Init();
void SerialHostComms();
//-------------------------------- DPLIB --------------------------------------------
void PWM_ComplPairDB_CNF(int16 n, int16 period, int16 mode, int16 phase);
void PWM_ComplPairDB_UpdateDB(int16 n, int16 dbRED, int16 dbFED);
void PWM_1ch_UpCntDB_CNF(int16 n, int16 period, int16 mode, int16 phase);
void PWM_1ch_UpCntDB_UpdateDB(int16 n, int16 dbRED, int16 dbFED);
void PWM_1ch_UpCntDB_Compl_CNF(int16 n, int16 period, int16 mode, int16 phase);
void PWM_1ch_UpCntDB_Compl_UpdateDB(int16 n, int16 dbRED, int16 dbFED);
void PWM_1ch_CNF(int16 n, int16 period, int16 mode, int16 phase);
void ADC_SOC_CNF(int ChSel[], int TrigSel[], int ACQPS[], int IntChSel, int mode);
// -------------------------------- FRAMEWORK --------------------------------------
// State Machine function prototypes
//----------------------------------------------------------------------------------
// Alpha states
void A0(void); //state A0
void B0(void); //state B0
void C0(void); //state C0
// A branch states
void A1(void); //state A1
void A2(void); //state A2
// B branch states
void B1(void); //state B1
void B2(void); //state B2
// C branch states
void C1(void); //state C1
// Variable declarations
void (*Alpha_State_Ptr)(void); // Base States pointer
void (*A_Task_Ptr)(void); // State pointer A branch
void (*B_Task_Ptr)(void); // State pointer B branch
void (*C_Task_Ptr)(void); // State pointer C branch
//----------------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
#define numTimers 1
int16 VTimer0[numTimers]; // Virtual Timers slaved off CPU Timer 0
int16 VTimer1[numTimers]; // Virtual Timers slaved off CPU Timer 1
int16 VTimer2[numTimers]; // Virtual Timers slaved off CPU Timer 2
int16 SerialCommsTimer;
int16 CommsOKflg;
// Used for running BackGround in flash, and ISR in RAM
extern Uint16 *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
// Used for ADC Configuration
int ChSel[16]; // = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int TrigSel[16]; // = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int ACQPS[16]; // = {6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6};
// ---------------------------------- USER -----------------------------------------
int16 LLC_Enable; // 1 = Enable, 0 = Disable
int16 SR_Enable; // 1 = Enable, 0 = Disable
int16 Comp_Enable; // 1 = Enable, 0 = Disable
int16 Pgain; // PID P gain (Q10)
int16 Igain; // PID I gain (Q10)
int16 Dgain; // PID D gain (Q10)
int16 use_2P2Z; // use 2P2Z coefficients instead of PID
int16 update_coeffs; // flag used to trigger update of 2P2Z coefficients
long b2_coeff;
long b1_coeff;
long b0_coeff;
long a2_coeff;
long a1_coeff;
// ---------------------------- DPLIB Net Pointers ---------------------------------
// Declare net pointers that are used to connect the DP Lib Macros here
// ADC
extern volatile long *ADCDRV_1ch_Rlt7; // Vout
// 2P2Z
extern volatile long *CNTL_2P2Z_Ref1;
extern volatile long *CNTL_2P2Z_Fdbk1;
extern volatile long *CNTL_2P2Z_Out1;
extern volatile long *CNTL_2P2Z_Coef1;
// PWM
extern volatile long *PWMDRV_LLC_ComplPairDB_Duty1;
extern volatile long *PWMDRV_LLC_ComplPairDB_Period1;
extern volatile long *PWMDRV_LLC_1ch_UpCntDB_Compl_Duty2;
extern volatile long *PWMDRV_LLC_1ch_UpCntDB_Compl_Period2;
extern volatile long *PWMDRV_LLC_1ch_UpCntDB_Duty3;
extern volatile long *PWMDRV_LLC_1ch_UpCntDB_Period3;
// ---------------------------- DPLIB Variables ---------------------------------
// Declare the net variables being used by the DP Lib Macro here
volatile long Vout;
volatile long Duty1;
volatile long Duty2;
volatile long Duty3;
volatile long Period;
long Vset; // Control loop target
long Min_Period; // Minimum PWM period
long Max_Period; // Maximum PWM period
int16 RED; // Half-Bridge PWM1 Rising Edge Delay
int16 FED; // Half-Bridge PWM1 Falling Edge Delay
int16 REM1; // SR1 PWM2 Rising Edge Margin
int16 FEM1; // SR1 PWM2 Falling Edge Margin
int16 REM2; // SR2 PWM3 Rising Edge Margin
int16 FEM2; // SR2 PWM3 Falling Edge Margin
int16 COMP1; // SR1 Comparator Trip Value
int16 COMP2; // SR2 Comparator Trip Value
#pragma DATA_SECTION(CNTL_2P2Z_CoefStruct1, "CNTL_2P2Z_Coef");
struct CNTL_2P2Z_CoefStruct CNTL_2P2Z_CoefStruct1;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - CCS WatchWindow / GUI support
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
//GUI support variables
// sets a limit on the amount of external GUI
评论2