//----------------------------------------------------------------------------------
// FILE: BridgelessPFC-Main.C
//
// Description: Bridgeless PFC
// The file drives duty on PWM1A and PWM2A using C28x
// C28x ISR is triggered by the PWM 1 interrupt
//
// Version: 1.0
//
// Target: TMS320F2803x(PiccoloB),
//
//----------------------------------------------------------------------------------
// Copyright Texas Instruments � 2004-2010
//----------------------------------------------------------------------------------
// Revision History:
//----------------------------------------------------------------------------------
// Date | Description / Status
//----------------------------------------------------------------------------------
// July 29 , 2010 - File created (DC)
//----------------------------------------------------------------------------------
//
// PLEASE READ - Useful notes about this Project
// Although this project is made up of several files, the most important ones are:
// "BridgelessPFC-Main.C" - this file
// - Application Initialization, Peripheral config,
// - Application management
// - Slower background code loops and Task scheduling
// "BridgelessPFC-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,
// "BridgelessPFC-DPL-ISR.asm
// - Assembly level library Macros and any cycle critical functions are found here
// "BridgelessPFC-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 "BridgelessPFC-Settings.h". Note: "Rebuild All" compile
// tool bar button must be used if this file is modified.
//----------------------------------------------------------------------------------
#include "PeripheralHeaderIncludes.h"
#include "DSP2803x_EPWM_defines.h"
#include "BridgelessPFC-Settings.h"
#include "IQmathLib.h"
//#include "Solar_SineAnalyzer.h"
#include "SineAnalyzer.h"
#include "DPlib.h"
#include <math.h>
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTION PROTOTYPES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Add protoypes of functions being used in the project here
void DeviceInit(void);
void SCIA_Init();
void SerialHostComms();
#ifdef FLASH
void InitFlash();
#endif
void MemCopy();
//-------------------------------- DPLIB --------------------------------------------
void PWM_1ch_UpDwnCnt_CNF(int16 n, int16 period, int16 mode, int16 phase);
void ADC_SOC_CNF(int ChSel[], int TrigSel[], int ACQPS[], int IntChSel, int mode);
interrupt void SECONDARY_ISR(void);
// -------------------------------- 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
void C2(void); //state C2
void C3(void); //state C3
void C4(void); //state C4
// 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
//Solar_SineAnalyzer sine_mainsV = Solar_SineAnalyzer_DEFAULTS;
SineAnalyzer sine_mainsV = SineAnalyzer_DEFAULTS;
//----------------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
int16 VTimer0[4]; // Virtual Timers slaved off CPU Timer 0
int16 VTimer1[4]; // Virtual Timers slaved off CPU Timer 1
int16 VTimer2[4]; // 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 ChannelEnable; // Enable PFC, [ 0="off", 1="on" ]
//int16 AC_Phase; // AC line +/- phase, [ 0="+", 1="-" ]
int16 RelayEnable;
long Vbus_set; // Control loop target
//long Pgain; // PID P gain
//long Igain; // PID I gain
//long Dgain; // PID D gain
long Dmax_I;
//Solar_SineAnalyzer RMSCalc = Solar_SineAnalyzer_DEFAULTS;
// ---------------------------- DPLIB Net Pointers ---------------------------------
// Declare net pointers that are used to connect the DP Lib Macros here
//extern volatile long *CNTL_2P2Z_Ref1, *CNTL_2P2Z_Fdbk1, *CNTL_2P2Z_Out1;
//extern volatile long *CNTL_2P2Z_Coef1;
// ADC
extern volatile long *ADCDRV_1ch_Rlt1; // instance #1, IpfcA
extern volatile long *ADCDRV_1ch_Rlt2; // instance #2, IpfcB
extern volatile long *ADCDRV_1ch_Rlt3; // instance #3, Vbus
extern volatile long *ADCDRV_1ch_Rlt4; // instance #4, VL_fb
extern volatile long *ADCDRV_1ch_Rlt5; // instance #5, VN_fb
// CONTROL_2P2Z
extern volatile long *CNTL_2P2Z_Ref1; // instance #1
extern volatile long *CNTL_2P2Z_Out1; // instance #1
extern volatile long *CNTL_2P2Z_Fdbk1; // instance #1
extern volatile long *CNTL_2P2Z_Coef1; // instance #1
extern volatile long CNTL_2P2Z_DBUFF1[5];
// CONTROL_2P2Z
extern volatile long *CNTL_2P2Z_Ref2; // instance #2
extern volatile long *CNTL_2P2Z_Out2; // instance #2
extern volatile long *CNTL_2P2Z_Fdbk2; // instance #2
extern volatile long *CNTL_2P2Z_Coef2; // instance #2
extern volatile long CNTL_2P2Z_DBUFF2[5];
// PFC-ch1
extern volatile long *PWMDRV_1ch_UpDwnCnt_Duty1; // instance #1, EPWM1
// PFC-ch2
extern volatile long *PWMDRV_1ch_UpDwnCnt_Duty2; // instance #2, EPWM2
// Instrumentation-ch4
extern volatile long *PWMDRV_1ch_UpDwnCnt_Duty4; // instance #3, EPWM4
extern volatile long *PFC_BL_ICMD_Vcmd1;
extern volatile long *PFC_BL_ICMD_VinvSqr1;
extern volatile long *PFC_BL_ICMD_VacRect1;
extern volatile long *PFC_BL_ICMD_Out1;
extern volatile long PFC_BL_ICMD_VmaxOverVmin1;
extern volatile long *PFC_BL_ICMD_Vpfc1;
extern volatile long *PFC_BL_ICMD_Duty1;
extern volatile long PFC_BL_ICMD_VoutMaxOverVinMax1;
//MATH_AVG - instance #1
extern volatile long *MATH_EMAVG_In1;
extern volatile long *MATH_EMAVG_Out1;
extern volatile long MATH_EMAVG_Multiplier1;
//MATH_AVG - instance #2
extern volatile long *MATH_EMAVG_In2;
extern volatile long *MATH_EMAVG_Out2;
extern volatile long MATH_EMAVG_Multiplier2;
//PFC_INVSQR - instance #1
//extern volatile long *PFC_INVSQR_In1;
//extern volatile long *PFC_INVSQR_Out1;
//extern volatile long PFC_INVSQR_VminOverVmax1;
//extern volati
评论4