Question: i was trying to debug this code on code composer studio to view my signal on oscilloscope but the code does not debug past the

i was trying to debug this code on code composer studio to view my signal on oscilloscope but the code does not debug past the int main (void) line. how do i fix this? here is the code: /*
* pwm.c
*
* Created on: 23 May 2024
* Author: QD
*/
#include "F28x_Project.h"
#include // Include math.h for sinf and M_PI
#include "F2837xD_epwm.h"
#include "F2837xD_pievect.h"
#include "F2837xD_gpio.h"
#define PWM_PERIOD 10000// For 10 kHz carrier frequency with 100 MHz SYSCLK
#define SINE_TABLE_SIZE 256
#define PHASE_SHIFT (SINE_TABLE_SIZE /3)//120 degrees phase shift
#define SINE_UPDATE_INTERVAL 78//78.125 microseconds for 50 Hz fundamental frequency
// Sine wave lookup table
float sine_table[SINE_TABLE_SIZE];
// Function prototypes
void InitEPwm1();
void InitEPwm2();
void InitEPwm3();
void InitSineTable();
int main(void)
{
InitSysCtrl(); // Initialize system control
DINT; // Disable CPU interrupts
InitPieCtrl(); // Initialize the PIE control registers
IER =0x0000; // Disable CPU interrupts and clear all CPU interrupt flags
IFR =0x0000; // Clear all CPU interrupt flags
InitPieVectTable(); // Initialize the PIE vector table
InitGpio(); // Initialize GPIO for ePWM
InitSineTable(); // Initialize the sine table
InitEPwm1(); // Initialize ePWM1
InitEPwm2(); // Initialize ePWM2
InitEPwm3(); // Initialize ePWM3
while(1)
{
int i;
for(i =0; i < SINE_TABLE_SIZE; i++)
{
// Update ePWM1
EPwm1Regs.CMPA.bit.CMPA =(PWM_PERIOD /2)*(sine_table[i]+1);
// Update ePWM2(phase-shifted by 120 degrees)
int idx2=(i + PHASE_SHIFT)% SINE_TABLE_SIZE;
EPwm2Regs.CMPA.bit.CMPA =(PWM_PERIOD /2)*(sine_table[idx2]+1);
// Update ePWM3(phase-shifted by 240 degrees)
int idx3=(i +2* PHASE_SHIFT)% SINE_TABLE_SIZE;
EPwm3Regs.CMPA.bit.CMPA =(PWM_PERIOD /2)*(sine_table[idx3]+1);
DELAY_US(SINE_UPDATE_INTERVAL); // Delay to achieve the 50 Hz fundamental frequency
}
}
}
void InitEPwm1()
{
EALLOW;
// Set up ePWM1
EPwm1Regs.TBPRD = PWM_PERIOD -1; // Set the PWM period
EPwm1Regs.TBPHS.all =0x00000000; // Phase is 0
EPwm1Regs.TBCTR =0x0000; // Clear counter
// Set up compare values
EPwm1Regs.CMPA.bit.CMPA =0; // Set the initial compare A value
// Set up the counter mode
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// Set up the action qualifier
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on event A, up count
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM1A on event A, down count
EDIS;
}
void InitEPwm2()
{
EALLOW;
// Set up ePWM2
EPwm2Regs.TBPRD = PWM_PERIOD -1; // Set the PWM period
EPwm2Regs.TBPHS.all = PWM_PERIOD /3; // Phase shift for 120 degrees
EPwm2Regs.TBCTR =0x0000; // Clear counter
// Set up compare values
EPwm2Regs.CMPA.bit.CMPA =0; // Set the initial compare A value
// Set up the counter mode
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Synchronize with ePWM1
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// Set up the action qualifier
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM2A on event A, up count
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM2A on event A, down count
EDIS;
}
void InitEPwm3()
{
EALLOW;
// Set up ePWM3
EPwm3Regs.TBPRD = PWM_PERIOD -1; // Set the PWM period
EPwm3Regs.TBPHS.all =(2* PWM_PERIOD)/3; // Phase shift for 240 degrees
EPwm3Regs.TBCTR =0x0000; // Clear counter
// Set up compare values
EPwm3Regs.CMPA.bit.CMPA =0; // Set the initial compare A value
// Set up the counter mode
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
EPwm3Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Synchronize with ePWM1
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// Set up the action qualifier
EPwm3Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM3A on event A, up count
EPwm3Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM3A on event A, down count
EDIS;
}
void InitSineTable()
{
int i;
for(i =0; i < SINE_TABLE_SIZE; i++)
{
sine_table[i]= sinf((2* M_PI * i)/ SINE_TABLE_SIZE);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!