Part Number: LAUNCHXL-F28027F
Other Parts Discussed in Thread: CONTROLSUITE
Tool/software: Code Composer Studio
Hi Friends,
I'm working on Sine wave generation coding utilizing ePWM and the controller I'm using is F28027F.
I'm following a code from this thread
https://e2e.ti.com/support/microcontrollers/c2000/f/171/p/553678/2025201
and altered the code in accordance with the Controller I'm using.
ISSUE:
When I try to build and debug, it fails and this error report generates
"C:/ti/controlSUITE/device_support/f2802x/v230/f2802x_common/cmd/F2802x_generic_ram.cmd", line 121: error:
program will not fit into available memory. placement with
alignment/blocking fails for section ".econst" size 0x100 page 1. Available
memory ranges:
RAMM1 size: 0x400 unused: 0xd6 max hole: 0xd6
.econst : > RAMM1, PAGE = 1
error: errors encountered during linking; "Example_2802xEPwmUpDownAQ.out" not
built
>> Compilation failure
gmake: *** [Example_2802xEPwmUpDownAQ.out] Error 1
gmake: Target `all' not remade because of errors.
My thoughts:
There's a float array named b[101] (plz observe it in the given code). From the error report I think build failed due to exceeding memory limits of the controller. Also I tried to reduced the number of Array to just 5 or replace float to Integers, then I can easily build the code, But by doing it is totally useless to me, can't achieve my target of sine wave generation. Kindly help me out of this. Isn't it possible to use F28027f for sine wave generation? If it is then kindly let me know the way.
Thanks in advance.
#include "DSP28x_Project.h"
#include "math.h"
#include "float.h" // Not sure whether it is needed or not
typedef struct
{
volatile struct EPWM_REGS *EPwmRegHandle;
}
EPWM_INFO;
#define EPWM2_TIMER_TBPRD 5000 // 5kHz PWM Period register
#define PI 3.14159265358979323846
void InitEPwm2Example(void);
__interrupt void epwm2_isr(void);
unsigned int i=0,m=0,k=0;
float a=0;
float b[101]={0}; //Here’s the b float array I’m talking about
void main(void)
{
#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
InitSysCtrl();
for(m=0;m<100;m++)
{
a=sin(PI*0.02*m);
if(a<=0)
{
a=-a;
}
b[m]=5000*a;
}
b[100]=0;
InitEPwm2Gpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.EPWM2_INT = &epwm2_isr;
EDIS
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
InitEPwm2Example();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
IER |= M_INT3;
PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
EALLOW;
SysCtrlRegs.PCLKCR1.bit.EPWM2ENCLK=1;
//Originally in the thread, this line was CpuSysRegs.PCLKCR2.bit.EPWM2=1; for F28377s
EDIS;
EINT;
ERTM;
for(;;)
{
__asm(" NOP");
}
}
__interrupt void epwm2_isr(void)
{
/*Here my code assign a new sin value into compare reg. For negative side of sin wave, pwm logic is inverted.*/
a=sin(PI*0.02*i);
if (a>=0){
EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR; // Clear PWM2A on event A, up
EPwm2Regs.AQCTLA.bit.CAD =AQ_SET; // Set PWM2A on event B, down
EPwm2Regs.CMPA.half.CMPA =b[i];
}
else {
EPwm2Regs.AQCTLA.bit.CAU =AQ_SET; // Set PWM2A on event A, up
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM2A on event B, down
EPwm2Regs.CMPA.half.CMPA =b[i]; //For F28027F bit is replaced with half
}
i++;
if (i==101){
i=0;
}
EPwm2Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void InitEPwm2Example()
{
EPwm2Regs.ETSEL.bit.INTSEL = 0;//ET_CTR_ZERO; // hem zero hemde TBPRD zamaninda intrrupt aliyo.
EPwm2Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm2Regs.ETPS.bit.INTPRD = 1;//ET_1ST; // Generate INT on 1st event
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV2;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = 1; //CC_IMMEDIATE;
//********* bit is replaced by half*********
EPwm2Regs.CMPA.half.CMPA =0;
EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD; // Set timer period 801 TBCLKs
//********* bit is replaced by half*********
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm2Regs.TBCTR = 0x0000; // Clear counter
}