Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE
Tool/software: Code Composer Studio
I have problem related to CLAMATH library synchronization with PLL code written by me. I have problems The code is here.
// Included Files
//
#include <stdint.h>
///#include "F2837xD_device.h"
//#include "F2837xD_Examples.h"
#include "F28x_Project.h"
//include "DSP28x_Project.h"
//#include "PI_CLA.h"
//#include "Solar_CLA.h"
#include "CLAmath.h"
//#include "IQmath.h"
//#include "IQmathCPP.h"
//
// Function Prototypes
//
void ConfigureADC(void);
void ConfigureEPWM(void);
void SetupADCEpwm(void);
//interrupt void adca1_isr(MPPT *v);
///void MPPT_PNO_IQ_FUNC();
//interrupt void adca1_isr();
//int MPP1;
//
// Defines
//
///#define RESULTS_BUFFER_SIZE 512
//
// Globals
//
//int32 MPP.Vpv[RESULTS_BUFFER_SIZE];
/////Uint16 resultsIndex;
volatile Uint16 bufferFull;
long resultsIndex;
long resultsIndex1;
////////////////////////////////////////// ###################### //////////////////////////
/////////// For PI Control //////////////////////////
float Ref_q = 0; // Input: reference set-point
float Fbk = 0; // Input: feedback
///float error;
float pi_out = 0; // Output: controller output
float Kp = 0.001; // Parameter: proportional loop gain
float Ki = 0; // Parameter: integral gain
///float Umax; // Parameter: upper saturation limit
///float Umin; // Parameter: lower saturation limit
///float up; // Data: proportional term
///float ui; // Data: integral term
///float v1; // Data: pre-saturated controller output
///float i1; // Data: integrator storage: ui(k-1)
///float w1;
float err_present;
float err_past = 0;
float proportional_term;
float integral_term;
float z;
float w = 0;
///////////////////////////////////////// ############################ /////////////////////
//////////////////////////////////////// ABC_DQ0 /////////////////////////////////
float a = 0;
float b = 0;
float c = 0;
float alpha = 0;
float beta = 0;
float sin = 0;
float cos = 0;
float d = 0;
float q = 0;
float z = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SRF_PLL_3_ph /////////////////////////////////////
float B1;
float B0;
float A1;
//float32 v_q[2];
float v_q_0;
float v_q_1;
//float32 ylf[2];
float ylf_0;
float ylf_1;
extern float fo; // output frequency of PLL
float fn = 50; //nominal frequency
float wn = (float)(2*3.1415926*50);
float w_lp;
//float32 theta[2];
float theta_0;
float theta_1;
float delta_T;
//float DELTA_T = 0;
///v_q_0=(float32)(0.0);
float v_q_0=(float)(0.0);
///v_q_1=(float32)(0.0);
float v_q_1=(float)(0.0);
//ylf_0=(float32)(0.0);
float ylf_0=(float)(0.0);
///ylf_1=(float32)(0.0);
float ylf_1=(float)(0.0);
///fo=(float32)(0.0);
float fo=(float)(0.0);
///fn=(float32)(Grid_freq);
/// float fn=(float)(Grid_freq);
///theta_0=(float32)(0.0);
float theta_0=(float)(0.0);
///theta_1=(float32)(0.0);
float theta_1=(float)(0.0);
/*loop filter coefficients for 20kHz*/
///B0_lf=(float32)(166.9743);
float B0 = (float)(166.9743);
///B1_lf=(float32)(-166.266);
float B1=(float)(-166.266);
///A1_lf=(float32)(-1.0);
float A1=(float)(-1.0);
///delta_T=(float32)DELTA_T;
float delta_T = (float)(0.0);
interrupt void adca1_isr();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
//
InitSysCtrl();
//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio(); // Skipped for this example
//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;
//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
//
InitPieCtrl();
//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
IER = 0x0000;
IFR = 0x0000;
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
//
InitPieVectTable();
//
// Map ISR functions
//
EALLOW;
PieVectTable.ADCA1_INT = &adca1_isr; //function for ADCA interrupt 1
EDIS;
//
// Configure the ADC and power it up
//
ConfigureADC();
//
// Configure the ePWM
//
ConfigureEPWM();
//
// Setup the ADC for ePWM triggered conversions on channel 0
//
SetupADCEpwm();
//
// Enable global Interrupts and higher priority real-time debug events:
//
IER |= M_INT1; //Enable group 1 interrupts
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//
// Initialize results buffer
//
///for(resultsIndex = 0; resultsIndex < RESULTS_BUFFER_SIZE; resultsIndex++)
///{
////////////////////////////////////////////////////////////////////////////////////////////// MPP1->Vpv = 0;
///}
/// resultsIndex = 0;
/// bufferFull = 0;
//
// enable PIE interrupt
//
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
//
// sync ePWM
//
// EALLOW;
// CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
// EDIS;
//
///PI_CLA_INIT(v);
//take conversions indefinitely in loop
//
do
{
//
//start ePWM
//
EPwm1Regs.ETSEL.bit.SOCAEN = 1; //enable SOCA
EPwm1Regs.TBCTL.bit.CTRMODE = 0; //unfreeze, and enter up count mode
//
//wait while ePWM causes ADC conversions, which then cause interrupts,
//which fill the results buffer, eventually setting the bufferFull
//flag
//
while(!bufferFull);
bufferFull = 0; //clear the buffer full flag
//
//stop ePWM
//
EPwm1Regs.ETSEL.bit.SOCAEN = 0; //disable SOCA
EPwm1Regs.TBCTL.bit.CTRMODE = 3; //freeze counter
//
//at this point, Vpv[] contains a sequence of conversions
//from the selected channel
//
//
//software breakpoint, hit run again to get updated conversions
//
// asm(" ESTOP0");
}while(1);
// MPPT_PNO_IQ_FUNC(v);
}
//
// ConfigureADC - Write ADC configurations and power up the ADC for both
// ADC A and ADC B
//
void ConfigureADC(void)
{
EALLOW;
//
//write configurations
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 0; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//
//Set pulse positions to late
//
//AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
///////////AdcaRegs.ADCSOCPRICTL.bit.SOCPRIORITY = 0;
////AdcaRegs.ADCSOCPRICTL.bit.RRPOINTER = 15;
//
//power up the ADC
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
//
//delay for 1ms to allow ADC time to power up
//
DELAY_US(1000);
EDIS;
}
//
// ConfigureEPWM - Configure EPWM SOC and compare values
//
void ConfigureEPWM(void)
{
EALLOW;
// Assumes ePWM clock is already enabled
EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group //////////////////////////////////////////////////////////////
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC on up-count
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts
EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts
EPwm1Regs.TBCTL.bit.CTRMODE = 3; // freeze counter
EDIS;
}
//
// SetupADCEpwm - Setup ADC EPWM acquisition window
//
void SetupADCEpwm(void)
{
///////Uint16 acqps;
//
//determine minimum acquisition window (in SYSCLKS) based on resolution
//
///////////// if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION)
/////////////// {
/////////////// acqps = 14; //75ns
////////////////// }
/////////////////else //resolution is 16-bit
////////////////////// {
/////////////////// acqps = 63; //320ns
///////////// }
//
//Select the channels to convert and end of conversion flag
//
EALLOW;
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcaRegs.ADCBURSTCTL.bit.BURSTEN = 1; //Enable ADC burst mode
AdcaRegs.ADCBURSTCTL.bit.BURSTTRIGSEL = 5; //SOFTWARE will trigger burst of conversions
AdcaRegs.ADCBURSTCTL.bit.BURSTSIZE = 2; //conversion bursts are 1 + 1 = 2 conversions long
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; //SOC0 will convert pin A0
AdcaRegs.ADCSOC0CTL.bit.ACQPS = 9; //sample window is 100 SYSCLK cycles
///AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
////////////////////////////////////////////////////////////////
AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC0 will convert pin A0
AdcaRegs.ADCSOC1CTL.bit.ACQPS = 9; //sample window is 100 SYSCLK cycles
///AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
//DELAY_US(1);
/////////////////////////////////////////////////////////////
AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; //SOC0 will convert pin A0
AdcaRegs.ADCSOC2CTL.bit.ACQPS = 9; //sample window is 100 SYSCLK cycles
///AdcaRegs.ADCSOC2CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
//DELAY_US(1);
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0;
AdcaRegs.ADCINTSEL1N2.bit.INT1CONT = 1;
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
///DELAY_US(1000);
///////AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1;
//////////AdcaRegs.ADCINTSEL1N2.bit.INT1CONT = 1;
//////////////AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
//////////AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
//////////////DELAY_US(1000);
//////////AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 2; //end of SOC0 will set INT1 flag
//////////AdcaRegs.ADCINTSEL1N2.bit.INT1CONT = 1;
////////////AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
/////////////AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
//////////////////////////////////////////////////////////////
EDIS;
}
//
// adca1_isr - Read ADC Buffer in ISR
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////// LOC /////////////////////////////////////////////////////////////
//
// End of file
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////************************************** ????/////////////////////////////
//*********** Structure Init Function ****//
//*********** Function Definition ********//
interrupt void adca1_isr()
{
//////////////////// Receive data in ADC ///////////////////////
a = AdcaResultRegs.ADCRESULT0;
b = AdcaResultRegs.ADCRESULT1;
c = AdcaResultRegs.ADCRESULT2;
delta_T = AdcaResultRegs.ADCRESULT3;
////////////// ABC to DQO positive sequence ////////////////
alpha=(0.6666666667)*(a - 0.5*(b + c)); \
beta=(0.57735026913)*(b - c); \
z = 0.57735026913*(a + b + c); \
d= alpha*cos + beta*sin; \
q= -alpha*sin + beta*cos; \
//////////////// PI and SELF_WRITTEN_CODE_PLL //////////////
err_present = Ref_q - q;
proportional_term = Kp*(err_present-err_past);
integral_term = Ki* err_present;
pi_out = proportional_term + integral_term;
z = w + pi_out;
w = z;
//
w_lp = w + wn; /// Output angular freq in rad/sec = error from PI + nominal angular freq (=100*pi)
fo = CLAdiv(w_lp,(2*3.1415926)); /// Output frequency in Hz
theta_0 = theta_1 + (float)((w_lp*delta_T));
/// theta_0 = theta_1 + ((fo*delta_T)*(float)(2*3.1415926));
if(theta_0 > (float)(2*3.1415926)) \
theta_0 = theta_0 - (float)(2*3.1415926); \
theta_1 = theta_0;
cos= CLAcos(theta_1);
sin= CLAsin(theta_1);
err_past = err_present;
///////////////////////// PLL Execution by Manish Bharadwaz /////////////////////////////
/// ylf_0=ylf_1 + (B0*v_q_0) + (B1*v_q_1); \
ylf_1=ylf_0; \
v_q_1=v_q_0; \
ylf_0=(ylf_0>(float32)(200.0))?(float)(200.0):ylf_0; \
fo=fn + ylf_0; \
theta_0=theta_1 + ((fo*delta_T)*(float)(2*3.1415926)); \
if(theta_0 > (float)(2*3.1415926)) \
theta_0=theta_0 - (float)(2*3.1415926); \
theta_1=theta_0;
/////////////////////// SELF_WRITTEN_CODE_PLL //////////////////////
/// w_lp = w + (2*3.1415926*fn); \
theta_0=theta_1 + ((fo*delta_T)*(float)(2*3.1415926)); \
if(theta_0 > (float)(2*3.1415926)) \
theta_0=theta_0 - (float)(2*3.1415926); \
theta_1=theta_0;
///v.Ipv = AdcaResultRegs.ADCRESULT1;
////////////////////////////////////////////////////////////////
//PI_CLA_MACRO(v);
///////////////////////////////////////////////////////////////////////
// MPPT_PNO_IQ_FUNC(v);
// resultsIndex = v.Vpv*v.Ipv;
//resultsIndex = _IQmpy(v->Vpv,v->Ipv);
//resultsIndex = _IQmpy(1,1);
//resultsIndex1 = v.VmppOut*v.Ipv;
/// if(RESULTS_BUFFER_SIZE <= resultsIndex)
/// {
/// resultsIndex = 0;
/// bufferFull = 1;
/// }
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////// LOC /////////////////////////////////////////
While running, the code I am facing the following listed warnings
1) #10247-D: creating output section "Cla1Prog" without a SECTIONS
specification
2) #10247-D: creating output section ".scratchpad" without a SECTIONS
specification
3) #10247-D: creating output section "CLA1mathTables" without a SECTIONS
specification
I have already added related CLA headers and assembly files according to CLA Math Library User's Guide. I am confused, how to incorporate trigonometric and division operation in a code. Especially the code demands sin, cos and division operation.