This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/LAUNCHXL-F28377S: Sine wave and graph

Part Number: LAUNCHXL-F28377S

Tool/software: Code Composer Studio

Hello everyone, I was trying to do a program like the (C2000 F28379D Dual-Core LaunchPad Technical Overview with a Demonstration of Inter-Processor Communi to read a sinewave on the launchXL-F28377s). I make a sinewave with the EPWM-DAC1 (PIN32) , this is connected with a wire with the ADCINA0. The program works ok, but on the debug seccion on CCS , i was trying to graph the AdcaResults. The problem is the graph of the sinewave dont sincronize ok like in the video and a deformation appears when the graph is updated. I try changing the graph properities and the size of the buffer.I do not know if it's a problem of the CCS configuration or a problem with the code.
I would appreciate any suggestions or help. I leave the code for you to try.

#include "F28x_Project.h"

//
// Function Prototypes
//
//defines del seno ==================================================================================================
#define EPWM11_TIMER_TBPRD 200 // Period register
#define EPWM11_MAX_CMPA 195
#define EPWM11_MIN_CMPA 5
#define EPWM11_MAX_CMPB 195
#define EPWM11_MIN_CMPB 5
#define EPWM_CMP_UP 1
#define EPWM_CMP_DOWN 0
#define SINE_PTS 80

/*SENO 80 PTS mas y menos con offset 100 */int QuadratureTable4[SINE_PTS] = {100,107,115,123,130,138,145,152,158,164,170,176,180,185,189,192,195,197,198,199,
199,199,198,197,195,192,189,185,180,176,170,164,158,152,145,138,130,123,115,107,
100,92,84,76,69,61,54,47,41,35,29,24,19,14,10,7,4,3,2,1,
2,3,4,5,6,7,10,14,19,24,29,35,41,47,54,61,69,76,84,92,};

// Globals
//
typedef struct
{
volatile struct EPWM_REGS *EPwmRegHandle;
Uint16 EPwm_CMPA_Direction;
Uint16 EPwm_CMPB_Direction;
Uint16 EPwmTimerIntCount;
Uint16 EPwmMaxCMPA;
Uint16 EPwmMinCMPA;
Uint16 EPwmMaxCMPB;
Uint16 EPwmMinCMPB;
}EPWM_INFO;

EPWM_INFO epwm11_info;
//FIN defines seno================================================================================================

// Function Prototypes SENO==============================================================================
void InitEPwm11Example(void);
__interrupt void epwm11_isr(void);
void update_compare(EPWM_INFO*);
void update_seno(EPWM_INFO*);
//========FIN FUNCIONES PROTOTIPO SENO===================================================

void ConfigureADC(void);
void ConfigureEPWM(void);
void SetupADCEpwm(Uint16 channel);
interrupt void adca1_isr(void);

//
// Defines
//
#define RESULTS_BUFFER_SIZE 512
//
// Globals
//
Uint16 AdcaResults[RESULTS_BUFFER_SIZE];
Uint16 resultsIndex;
volatile Uint16 bufferFull;

void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
InitSysCtrl();

//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio(); // Skipped for this example

CpuSysRegs.PCLKCR2.bit.EPWM11=1;
//
InitEPwm11Gpio();
//
// 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 F2837xS_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 F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
//
InitPieVectTable();

EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EPWM11_INT = &epwm11_isr;
EDIS; // This is needed to disable write to EALLOW protected registers

EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;

InitEPwm11Example();

EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
// Map ISR functions
//
IER |= M_INT3;

EALLOW;
PieVectTable.ADCA1_INT = &adca1_isr; //function for ADCA interrupt 1
EDIS;

PieCtrlRegs.PIEIER3.bit.INTx11 = 1;
//
// Configure the ADC and power it up
ConfigureADC();
// Configure the ePWM
ConfigureEPWM();
// Setup the ADC for ePWM triggered conversions on channel 0
SetupADCEpwm(0);
// 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++)
{
AdcaResults[resultsIndex] = 0;
}
resultsIndex = 0;
bufferFull = 0;
// enable PIE interrupt
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
// sync ePWM
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;

//
//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, AdcaResults[] contains a sequence of conversions
//from the selected channel
}while(1);
}

//
// 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 = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//Set pulse positions to late
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//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(Uint16 channel)
{
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.ADCSOC0CTL.bit.CHSEL = channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
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
//
interrupt void adca1_isr(void)
{
AdcaResults[resultsIndex++] = AdcaResultRegs.ADCRESULT0;
if(RESULTS_BUFFER_SIZE <= resultsIndex)
{
resultsIndex = 0;
bufferFull = 1;
}

AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//FUNCIONES SENO ====================================================================================
__interrupt void epwm11_isr(void)
{

//
// Update the CMPA and CMPB values
//
update_seno(&epwm11_info);

//
// Clear INT flag for this timer
//
EPwm11Regs.ETCLR.bit.INT = 1;

//
// Acknowledge this interrupt to receive more interrupts from group 3
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}


// InitEPwm1Example - Initialize EPWM1 configuration ========================================================
//
void InitEPwm11Example()
{
//
// Setup TBCLK
//
EPwm11Regs.TBPRD = EPWM11_TIMER_TBPRD; // Set timer period 801 TBCLKs
EPwm11Regs.TBPHS.bit.TBPHS = 0x0000; // Phase is 0
EPwm11Regs.TBCTR = 0x0000; // Clear counter

//
// Set Compare values
//
EPwm11Regs.CMPA.bit.CMPA = EPWM11_MIN_CMPA; // Set compare A value
EPwm11Regs.CMPB.bit.CMPB = EPWM11_MAX_CMPB; // Set Compare B value

//
// Setup counter mode
//
EPwm11Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
EPwm11Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm11Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm11Regs.TBCTL.bit.CLKDIV = TB_DIV1;

//
// Setup shadowing
//
EPwm11Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm11Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm11Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero
EPwm11Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

//
// Set actions
//
EPwm11Regs.AQCTLA.bit.CAD = AQ_SET; // Set PWM1A on event A, up
// count
EPwm11Regs.AQCTLA.bit.CAU = AQ_CLEAR; // Clear PWM1A on event A,
// down count

EPwm11Regs.AQCTLB.bit.CBU = AQ_SET; // Set PWM1B on event B, up
// count
EPwm11Regs.AQCTLB.bit.CBD = AQ_CLEAR; // Clear PWM1B on event B,
// down count

//
// Interrupt where we will change the Compare Values
//
EPwm11Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm11Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm11Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 3rd event

//
// Information this example uses to keep track
// of the direction the CMPA/CMPB values are
// moving, the min and max allowed values and
// a pointer to the correct ePWM registers
//
epwm11_info.EPwm_CMPA_Direction = EPWM_CMP_UP; // Start by increasing CMPA
epwm11_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN; // & decreasing CMPB
epwm11_info.EPwmTimerIntCount = 0; // Zero the interrupt counter
epwm11_info.EPwmRegHandle = &EPwm11Regs; // Set the pointer to the
// ePWM module
epwm11_info.EPwmMaxCMPA = EPWM11_MAX_CMPA; // Setup min/max CMPA/CMPB
// values
epwm11_info.EPwmMinCMPA = EPWM11_MIN_CMPA;
epwm11_info.EPwmMaxCMPB = EPWM11_MAX_CMPB;
epwm11_info.EPwmMinCMPB = EPWM11_MIN_CMPB;
}

//
// InitEPwm2Example - Initialize EPWM2 configuration
//

//============================================================================================================================================
void update_seno(EPWM_INFO *epwm_info)
{
static Uint16 iQuadratureTable = 0;

//
// Every 10'th interrupt, change the CMPA/CMPB values
//
if(epwm_info->EPwmTimerIntCount == 61)
{
epwm_info->EPwmTimerIntCount = 0;

epwm_info->EPwmRegHandle->CMPA.bit.CMPA = ((QuadratureTable4[iQuadratureTable++])*1);

if(iQuadratureTable > (SINE_PTS) - 1) // Wrap the index
{
iQuadratureTable = 0;

}
// else if(iQuadratureTable > ((SINE_PTS/2) - 1))
//{
//epwm_info->EPwmRegHandle->CMPA.bit.CMPA = ((QuadratureTable2[iQuadratureTable++])*1);
//}
//else if(iQuadratureTable > ((SINE_PTS) - 1))
//{
//}
}

else

{
epwm_info->EPwmTimerIntCount++;
}
return;
}