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/TMS320F28027: SPWM closed loop control of a three phase inverter using ADC

Part Number: TMS320F28027
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

Hello,

I am using F28027 dsp and i am working on an university project of making 3-ph SPWM closed-loop inverter.

i have reached upto the generation of SPWM signals on the DSP but i don't know how to implement ADC in the project (only coding not concept).

i have seen some examples of ADC programs and tried to add them in single program but it doesn't works.

My code in which i tried to implement the ADC program is below. i can't find what is wrong in this.

any help is appreciated.

The user sets the frequency of the SPWM by setting appropriately the
//  EPWM1_TIMER_TBPRD variable. The frequency of the PWM,up and down mode,
//  obeys the equations: TPWM=2xTBPRDxTTBCLK, TTBCLK=SYSCLKOUT/(HSPCLKDIVxCLKDIV).
//  By default: HSPCLKDIV=2, CLKDIV=1.
//
//  The sine for the PWM is read by the chip ROM. The sine table consists of
//  512 elements.
//  The frequency of sinusoidal PWM is defined by the period of the timer0 interrupt.
//  For 50Hz the sine table must be read, entirely in 20msec. This means that the
//  timer0 interrupt must occur in every 20/512 msec.
//  The general type for the is Ttimer=Tsin*Fcpu/index.
//
//  The 120 degrees difference of the sine are set by the variables:
//  index = 0, zero degrees
//  index2= 170, 120 degrees
//  index3=340, for 240 degrees
//
//
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
#include <stdio.h>
#include <file.h>
#include "DSP28x_Project.h"   // DSP28x Headerfile
#include "f2802x_common/include/F2802x_GlobalPrototypes.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/wdog.h"
#include "f2802x_common/include/flash.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/adc.h"
#include "f2802x_common/include/sci.h"
#include "f2802x_common/include/sci_io.h"
#include "f2802x_common/include/pwm.h"
#include "f2802x_common/include/timer.h"
#include "f2802x_common/include/IQmathLib.h" //IQmath Library header file
extern void DSP28x_usDelay(Uint32 Count);
#pragma DATA_SECTION(sine_table,"IQmathTables"); //IQmath ROM sine table
_iq30 sine_table[512];
//Interrupt prototype function for timer0
interrupt void cpu_timer0_isr(void);
void update_compare(void);
//Global PWM variables
#define EPWM1_TIMER_TBPRD  14634 // Period register for 2050.2Hz
#define PHASE 120.0             // Defines the real in degrees phase between phases, 120deg
#define TTIMERREG 2343          // Timer interrupt for 50Hz SPWM
Uint16 EPWM_PHASE=(EPWM1_TIMER_TBPRD*PHASE/180.0); //The phase as seen from the EPWM module
Uint16 duty_cycle_A=1000;   // Set duty 50% initially
Uint16 duty_cycle_B=1000;   // Set duty 50% initially
Uint16 index=0;             // Zero degrees sine
Uint16 index2=170;          // 120 degrees sine difference
Uint16 index3=340;          // 240 degrees sine difffence
Uint16 DEADTIME_R=5.0;      // Deadtime 5usec
Uint16 DEADTIME_F=5.0;      // Deadtime 5usec
// Handles setup
CPU_Handle myCpu;
PLL_Handle myPll;
WDOG_Handle myWDog;
CLK_Handle myClk;
ADC_Handle myAdc;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;
// SCI_Handle mySci;
PWM_Handle PWMA,PWMB,PWMC;
TIMER_Handle myTimer0;

// ADC global variables used in this example:
uint16_t ADC0, ADC1, ADC2, ADC3, sp, mean;
double error, integral;
float ma = 0.8;
float kp = 0.5;
float ki = 0.5;


// Handles initialization
void setup_handles()
{
    myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
    myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
    myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
    myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
    myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
    myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
    myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
 //   mySci = SCI_init((void *)SCIA_BASE_ADDR, sizeof(SCI_Obj));
    myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
    PWMA = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj));
    PWMB = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj));
    PWMC = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj));
    myTimer0 = TIMER_init((void *)TIMER0_BASE_ADDR, sizeof(TIMER_Obj));
}
//System Initialization
void init_system()
{
  //Disable watchcdog
  WDOG_disable(myWDog);
  //Device calibration for the adc
  (*Device_cal)();
  //Sets the internal oscillator source
  CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
  // Setup the PLL for x10 /2 which will yield 60Mhz = 10Mhz * 12 / 2
  PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
  //Disable the PIE peripheral and all the interupts
  PIE_disable(myPie);
  PIE_disableAllInts(myPie);
  CPU_disableGlobalInts(myCpu);
  CPU_clearIntFlags(myCpu);
#ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
}


//GPIO initialization
void gpio_init()
{
    // Initialize GPIO for the EPWM1A and EPWM1B
    GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable);
    GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A);
    GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B);
    GPIO_setDirection(myGpio,GPIO_Number_0,GPIO_Direction_Output);
    GPIO_setDirection(myGpio,GPIO_Number_1,GPIO_Direction_Output);
    // Initialize GPIO for the EPWM2A and EPWM2B
    GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable);
    GPIO_setPullUp(myGpio, GPIO_Number_3, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_EPWM2A);
    GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_EPWM2B);
    GPIO_setDirection(myGpio,GPIO_Number_2,GPIO_Direction_Output);
    GPIO_setDirection(myGpio,GPIO_Number_3,GPIO_Direction_Output);
    // Initialize GPIO for the EPWM2A and EPWM2B
    GPIO_setPullUp(myGpio, GPIO_Number_4, GPIO_PullUp_Disable);
    GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A);
    GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_EPWM3B);
    GPIO_setDirection(myGpio,GPIO_Number_4,GPIO_Direction_Output);
    GPIO_setDirection(myGpio,GPIO_Number_5,GPIO_Direction_Output);
}
//PWM settings
void pwma_init()
{
    // PWMA initialization
    CLK_enablePwmClock(myClk, PWM_Number_1);
    //PWMA initialiazation
    // Setup TBCLK
    PWM_setCounterMode(PWMA,PWM_CounterMode_UpDown);  // Count up-down
    PWM_setPeriod(PWMA,EPWM1_TIMER_TBPRD);            // Set timer period
    PWM_disableCounterLoad(PWMA);                     // Disable phase loading
    PWM_setSyncMode(PWMA,PWM_SyncMode_Disable);
    PWM_setCount(PWMA, 0x0000);                       // Clear counter
    PWM_setClkDiv(PWMA, PWM_ClkDiv_by_1);
    PWM_setHighSpeedClkDiv(PWMA, PWM_HspClkDiv_by_1);     // Clock ratio to SYSCLKOUT
     // Setup shadowing
    PWM_setShadowMode_CmpA(PWMA, PWM_ShadowMode_Shadow);
    PWM_setShadowMode_CmpB(PWMA, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(PWMA, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(PWMA, PWM_LoadMode_Zero);
    PWM_setCmpA(PWMA,1000); //Initial duty cycle
    PWM_setCmpB(PWMA,1000);
    // Set actions
    PWM_setActionQual_CntUp_CmpA_PwmA(PWMA, PWM_ActionQual_Set);      // Set PWM1A on event A, up count
    PWM_setActionQual_CntDown_CmpA_PwmA(PWMA, PWM_ActionQual_Clear);  // Clear PWM1A on event A, down count
    PWM_setActionQual_CntUp_CmpB_PwmB(PWMA, PWM_ActionQual_Clear);      // Set PWM1B on event B, up count
    PWM_setActionQual_CntDown_CmpB_PwmB(PWMA, PWM_ActionQual_Set);  // Clear PWM1B on event B, down count
    //Set DeadBand Control
    PWM_setDeadBandOutputMode(PWMA, PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
    PWM_setDeadBandPolarity(PWMA, PWM_DeadBandPolarity_EPWMxB_Inverted);
    PWM_setDeadBandInputMode(PWMA, PWM_DeadBandInputMode_EPWMxA_Rising_and_Falling);
    PWM_setDeadBandRisingEdgeDelay(PWMA, DEADTIME_R);
    PWM_setDeadBandFallingEdgeDelay(PWMA, DEADTIME_F);
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
    //PWMB initialization
    CLK_enablePwmClock(myClk, PWM_Number_2);
     // Setup TBCLK
    PWM_setCounterMode(PWMB,PWM_CounterMode_UpDown);  // Count up-down
    PWM_setPeriod(PWMB,EPWM1_TIMER_TBPRD);  // Set timer period
    PWM_enableCounterLoad(PWMB);
    PWM_setPhaseDir(PWMB,PWM_PhaseDir_CountDown);
    PWM_setSyncMode(PWMB,PWM_SyncMode_Disable);
    PWM_setCount(PWMB, 0x0000);                       // Clear counter
    PWM_setClkDiv(PWMB, PWM_ClkDiv_by_1);
    PWM_setHighSpeedClkDiv(PWMB, PWM_HspClkDiv_by_1);     // Clock ratio to SYSCLKOUT
     // Setup shadowing
    PWM_setShadowMode_CmpA(PWMB, PWM_ShadowMode_Shadow);
    PWM_setShadowMode_CmpB(PWMB, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(PWMB, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(PWMB, PWM_LoadMode_Zero);
    PWM_setCmpA(PWMB,1000); //Initial duty cycle
    PWM_setCmpB(PWMB,1000);
    // Set actions
    PWM_setActionQual_CntUp_CmpA_PwmA(PWMB, PWM_ActionQual_Set);      // Set PWM2A on event A, up count
    PWM_setActionQual_CntDown_CmpA_PwmA(PWMB, PWM_ActionQual_Clear);  // Clear PWM2A on event A, down count
    PWM_setActionQual_CntUp_CmpB_PwmB(PWMB, PWM_ActionQual_Clear);      // Set PWM2B on event B, up count
    PWM_setActionQual_CntDown_CmpB_PwmB(PWMB, PWM_ActionQual_Set);  // Clear PWM2B on event B, down count
    //Set DeadBand Control
    PWM_setDeadBandOutputMode(PWMB, PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
    PWM_setDeadBandPolarity(PWMB, PWM_DeadBandPolarity_EPWMxB_Inverted);
    PWM_setDeadBandInputMode(PWMB, PWM_DeadBandInputMode_EPWMxA_Rising_and_Falling);
    PWM_setDeadBandRisingEdgeDelay(PWMB, DEADTIME_R);
    PWM_setDeadBandFallingEdgeDelay(PWMB, DEADTIME_F);
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
    //PWMC initialization
    CLK_enablePwmClock(myClk, PWM_Number_3);
     // Setup TBCLK
    PWM_setCounterMode(PWMC,PWM_CounterMode_UpDown);  // Count up-down
    PWM_setPeriod(PWMC,EPWM1_TIMER_TBPRD); // Set timer period
    PWM_enableCounterLoad(PWMC);
    PWM_setPhaseDir(PWMC,PWM_PhaseDir_CountUp);
    PWM_setSyncMode(PWMC,PWM_SyncMode_Disable);
    PWM_setCount(PWMC, 0x0000);                       // Clear counter
    PWM_setClkDiv(PWMC, PWM_ClkDiv_by_1);
    PWM_setHighSpeedClkDiv(PWMC, PWM_HspClkDiv_by_1);     // Clock ratio to SYSCLKOUT
     // Setup shadowing
    PWM_setShadowMode_CmpA(PWMC, PWM_ShadowMode_Shadow);
    PWM_setShadowMode_CmpB(PWMC, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(PWMC, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(PWMC, PWM_LoadMode_Zero);
    PWM_setCmpA(PWMC,1000); //Initial duty cycle
    PWM_setCmpB(PWMC,1000);
    // Set actions
    PWM_setActionQual_CntUp_CmpA_PwmA(PWMC, PWM_ActionQual_Set);      // Set PWM3A on event A, up count
    PWM_setActionQual_CntDown_CmpA_PwmA(PWMC, PWM_ActionQual_Clear);  // Clear PWM3A on event A, down count
    PWM_setActionQual_CntUp_CmpB_PwmB(PWMC, PWM_ActionQual_Clear);      // Set PWM3B on event B, up count
    PWM_setActionQual_CntDown_CmpB_PwmB(PWMC, PWM_ActionQual_Set);  // Clear PWM3B on event B, down count
    //Set DeadBand Control
    PWM_setDeadBandOutputMode(PWMC, PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
    PWM_setDeadBandPolarity(PWMC, PWM_DeadBandPolarity_EPWMxB_Inverted);
    PWM_setDeadBandInputMode(PWMC, PWM_DeadBandInputMode_EPWMxA_Rising_and_Falling);
    PWM_setDeadBandRisingEdgeDelay(PWMC, DEADTIME_R);
    PWM_setDeadBandFallingEdgeDelay(PWMC, DEADTIME_F);
    CLK_enableTbClockSync(myClk);
}
//PIE settings
void pie_init()
{
    PIE_enable(myPie);
    EALLOW;
    EDIS;
    PIE_registerPieIntHandler(myPie, PIE_GroupNumber_1, PIE_SubGroupNumber_7, (intVec_t)&cpu_timer0_isr);
    EDIS;
}
//Timer settings
void timer0_init()
{
    TIMER_stop(myTimer0);
    TIMER_setPeriod(myTimer0,TTIMERREG);
    TIMER_setPreScaler(myTimer0,0);
    TIMER_reload(myTimer0);
    TIMER_setEmulationMode(myTimer0, TIMER_EmulationMode_StopAfterNextDecrement);
    TIMER_enableInt(myTimer0);
    TIMER_start(myTimer0);
    /********** Enable ADC iterrupts **********/
       // Clear ADCINT1 flag reinitialize for next SOC
       ADC_clearIntFlag(myAdc, ADC_IntNumber_1);
       // Enables the specified ADC interrupt
       PIE_enableAdcInt(myPie, ADC_IntNumber_1);

       /********** Enable timer iterrupts **********/
       // Enables a specified interrupt number
       CPU_enableInt(myCpu, CPU_IntNumber_1);  // CPU int1 which triggers on CPU-Timer 0
       // Enables a specified interrupt number
     //  CPU_enableInt(myCpu, CPU_IntNumber_13); // CPU int13 which triggers on CPU-Timer 1
       // Enables the Cpu Timer 0 interrupt
       PIE_enableTimer0Int(myPie);

       // Enables global interrupts
       CPU_enableGlobalInts(myCpu);
}
// ADC initialization
void adc_init()
{
	/********** Initialize ADC **********/

	    // Enables the ADC band gap circuit
	    ADC_enableBandGap(myAdc);
	    // Enables the ADC reference buffers circuit
	    ADC_enableRefBuffers(myAdc);
	    // Powers up the ADC
	    ADC_powerUp(myAdc);
	    // Enables the ADC
	    ADC_enable(myAdc);
	    // Sets the voltage reference source
	    // ADCCTL1 - ADC_ADCCTL1_ADCREFSEL_BITS
	    ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int);


	    // Clear ADCINT1 flag reinitialize for next SOC
	    ADC_clearIntFlag(myAdc, ADC_IntNumber_1);
	    // Enables the specified ADC interrupt
	    PIE_enableAdcInt(myPie, ADC_IntNumber_1);
	    // Enables the ADC interrupt
	    ADC_enableInt(myAdc, ADC_IntNumber_1);


	    // Sets the interrupt pulse generation mode
	    // ADCCTL1 - ADC_ADCCTL1_INTPULSEPOS_BITS
	    // param[in] adcHandle  The ADC object handle
	    // param[in] pulseMode  The pulse generation mode
	    ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior);       //ADCINT1 trips after AdcResults latch

	    // Enables ADC interrupt
	    // INTSELxNy - ADC_INTSELxNy_INTE_BITS
	    // param[in] adcHandle  The ADC object handle
	    // param[in] intNumber  The interrupt number
	    ADC_enableInt(myAdc, ADC_IntNumber_1);

	    // Sets the interrupt mode
	    // INTSELxNy - ADC_INTSELxNy_INTCONT_BITS
	    // param[in] adcHandle  The ADC object handle
	    // param[in] intNumber  The interrupt number
	    // param[in] intMode    The interrupt mode
	    ADC_setIntMode(myAdc, ADC_IntNumber_1, ADC_IntMode_ClearFlag);  // Disable ADCINT1 Continuous mode

	    // Sets the interrupt source
	    // INTSELxNy - ADC_INTSELxNy_INTSEL_BITS
	    // param[in] adcHandle  The ADC object handle
	    // param[in] intNumber  The interrupt number
	    // param[in] intSrc     The interrupt source
	    ADC_setIntSrc(myAdc, ADC_IntNumber_1, ADC_IntSrc_EOC3);         // Setup EOC3 to trigger ADCINT1

	    // Sets the start-of-conversion (SOC) channel number
	    // ADCSOCxCTL - ADC_ADCSOCxCTL_CHSEL_BITS
	    // param[in] adcHandle   The ADC object handle
	    // param[in] socNumber   The SOC number
	    // param[in] chanNumber  The channel number
	    ADC_setSocChanNumber (myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A0);    // Set SOC0 channel select to ADCINA0
	    ADC_setSocChanNumber (myAdc, ADC_SocNumber_1, ADC_SocChanNumber_A1);    // Set SOC1 channel select to ADCINA1
	    ADC_setSocChanNumber (myAdc, ADC_SocNumber_2, ADC_SocChanNumber_A2);    // Set SOC2 channel select to ADCINA2
	    ADC_setSocChanNumber (myAdc, ADC_SocNumber_3, ADC_SocChanNumber_A3);    // Set SOC3 channel select to ADCINA3

	    // Sets the start-of-conversion (SOC) trigger source
	    // ADCSOCxCTL - ADC_ADCSOCxCTL_TRIGSEL_BITS
	    // param[in] adcHandle   The ADC object handle
	    // param[in] socNumber   The SOC number
	    // param[in] chanNumber  The channel number
	    ADC_setSocTrigSrc(myAdc, ADC_SocNumber_0, ADC_SocTrigSrc_CpuTimer_0);    // Set SOC0 start trigger on CpuTimer_0, due to round-robin SOC0 converts first then SOC1
	    ADC_setSocTrigSrc(myAdc, ADC_SocNumber_1, ADC_SocTrigSrc_CpuTimer_0);    // Set SOC1 start trigger on CpuTimer_0, due to round-robin SOC1 converts first then SOC2
	    ADC_setSocTrigSrc(myAdc, ADC_SocNumber_2, ADC_SocTrigSrc_CpuTimer_0);    // Set SOC2 start trigger on CpuTimer_0, due to round-robin SOC2 converts first then SOC3
	    ADC_setSocTrigSrc(myAdc, ADC_SocNumber_3, ADC_SocTrigSrc_CpuTimer_0);    // Set SOC4 start trigger on CpuTimer_0

	    // Sets the start-of-conversion (SOC) sample delay
	    // ADCSOCxCTL - ADC_ADCSOCxCTL_ACQPS_BITS
	    // param[in] adcHandle    The ADC object handle
	    // param[in] socNumber    The SOC number
	    // param[in] sampleDelay  The sample delay
	    ADC_setSocSampleWindow(myAdc, ADC_SocNumber_0, ADC_SocSampleWindow_7_cycles);   // Set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
	    ADC_setSocSampleWindow(myAdc, ADC_SocNumber_1, ADC_SocSampleWindow_7_cycles);   // Set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
	    ADC_setSocSampleWindow(myAdc, ADC_SocNumber_2, ADC_SocSampleWindow_7_cycles);   // Set SOC2 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
	    ADC_setSocSampleWindow(myAdc, ADC_SocNumber_3, ADC_SocSampleWindow_7_cycles);   // Set SOC3 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)

	/************************************************************************************************************************/

	    // Wait for ADC interrupt
	    while(1)
	    {
	        while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}  // Wait until ADCINT1 is tripped

	        ADC0 = AdcResult.ADCRESULT0;
	        ADC1 = AdcResult.ADCRESULT1;
	        ADC2 = AdcResult.ADCRESULT2;
	        ADC3 = AdcResult.ADCRESULT3;

	        AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;   // Clear ADCINT1

	        // Clear ADCINT1 flag reinitialize for next SOC
	        //ADC_clearIntFlag(myAdc, ADC_IntNumber_1);
	    }
}
void main()
{
  setup_handles();
  init_system();
  gpio_init();
  pwma_init();
  pie_init();
  timer0_init();


  //Enables the CPU interrupt
  CPU_enableInt(myCpu, CPU_IntNumber_1);
  //Enables the interrupt  of the Timer0 for the PIE module
  PIE_enableTimer0Int(myPie);
  CPU_enableGlobalInts(myCpu);
  CPU_enableDebugInt(myCpu);
  adc_init();

  //Forever Loop to see the results
  for(;;)
    {
    }
}
interrupt void cpu_timer0_isr(void)
{
   mean = (ADC0 + ADC1 + ADC2)/3;
   error = sp - mean;
   integral = error + integral;
   ma = (kp*error) + (ki*integral);
	update_compare();
   // Acknowledge this interrupt to receive more interrupts from group 1
   PIE_clearInt(myPie, PIE_GroupNumber_1);
}
void update_compare(void)
{
    PWM_setCmpA(PWMA,_IQsat(_IQ30mpy((sine_table[index]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
    PWM_setCmpB(PWMA,_IQsat(_IQ30mpy((sine_table[index]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
    PWM_setCmpA(PWMB,_IQsat(_IQ30mpy((sine_table[index2]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
    PWM_setCmpB(PWMB,_IQsat(_IQ30mpy((sine_table[index2]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
    PWM_setCmpA(PWMC,_IQsat(_IQ30mpy((sine_table[index3]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
    PWM_setCmpB(PWMC,_IQsat(_IQ30mpy((sine_table[index3]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
    if (index++ >511) index = 0;
    if (index2++ >511) index2 = 0;
    if (index3++ >511) index3 = 0;
}
//---------------------------------------------

  • Maharshi,

    1. What are you trying to do with the ADC?
    2. What examples have you looked at, have you downloaded and looked through controlSUITE?
      1. If you haven't looked yet, there are several good ADC examples in controlSUITE!

    3. Have you done any debug?
      1. What is working?
      2. What isn't working?

    Regards,
    Cody 

  • firstly i am trying to measure the output voltages of the inverter by a sensor card i have .

    i have looked at the controlSUITE examples and i use controlsuit for adding the header files and definition files for the software driver functions.
    I have looked EPWM examples and ADC examples and also tried to combine them togather but it didn't work properly. so i tried above example from the TI e2e forum. it worked but i am getting some errors with ADC registers definition.

    yes, i have debuged the SPWM program without ADC, and it worked decent. i have also checked its waveforms in DSO.


    and then i found a new problem
    its sine wave frequency is unable to reach at 50Hz (in my region).

    so, I am stuck here...
  • Maharshi,
    With regards to your PWM frequency issue have you checked the clock source, multipliers, and dividers?

    Do you have XCLKOUT configured?

    Are you using the Clock divider (TBCTL.CLKDIV) in the PWM's Time Base submodule?


    Verify the settings mentioned above and use XCLKOUT to determine what your SYSCLK frequency, if that doesn't point out an issue then post the results back here.

    Regards,
    Cody
  • Cody,

    yes , I have configured the clock dividers and PLL. In above program the PLL is set to 60MHz with this speed i am having max sine wave frequency of 19Hz.

      // Setup the PLL for x10 /2 which will yield 60Mhz = 10Mhz * 12 / 2
      PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);

    and setting the PLL divider to 1 gives me 120MHz of speed but with that i am having max sine wave frequency of 38Hz.

    but in the direct register access method i am having 50Hz sine wave and also around 30KHz of switching frequency. But ony drawback is that the ADC is not working in that , whenever i try to add the ADC code, the output SPWM pulses stops working (no output pulses).

  • From the controlSUIT examples i made one program combining the ADC and EPWM examples.

    without adding the ADC code the SPWM output works decent but when i add the ADC code, the output stops working.

    My code is shown below,

    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    #include "math.h"
    
    // Configure which ePWM timer interrupts are enabled at the PIE level:
    // 1 = enabled,  0 = disabled
    #define PWM1_INT_ENABLE  1
    #define PWM2_INT_ENABLE  1
    #define PWM3_INT_ENABLE  1
    
    void Adc_Config(void);
    Uint16 index=0;             // Zero degrees sine
    Uint16 index2=170;          // 120 degrees sine difference
    Uint16 index3=340;          // 240 degrees sine difffence
    // Global variables used in this example:
    uint16_t LoopCount;
    uint16_t ConversionCount;
    uint16_t Voltage1[10];
    uint16_t Voltage2[10];
    
    // Configure the period for each timer
    #define PWM1_TIMER_TBPRD   7000
    #define PWM2_TIMER_TBPRD   7000
    #define PWM3_TIMER_TBPRD   7000
    #define EPWM1_TIMER_TBPRD   7000 //for the IQ sine tables
    //#define PI 3.141592654
    #include "f2802x_common/include/IQmathLib.h" //IQmath Library header file
    extern void DSP28x_usDelay(Uint32 Count);
    #pragma DATA_SECTION(sine_table,"IQmathTables"); //IQmath ROM sine table
    _iq30 sine_table[512];
    
    
    // Prototype statements for functions found within this file.
    interrupt void epwm1_timer_isr(void);
    interrupt void epwm2_timer_isr(void);
    interrupt void epwm3_timer_isr(void);
    void InitEPwmTimer(void);
    
    // Global variables used in this example
    uint32_t  EPwm1TimerIntCount;
    uint32_t  EPwm2TimerIntCount;
    uint32_t  EPwm3TimerIntCount;
    //Uint16 a=1500,b=1500,c=1500;
    Uint16 a,b,c;
    //float ma=0.8;
    double th=0,f=50,ma=1;
    //Uint16 i=0;
    //Uint16 sinewave1[100],sinewave2[100];
    
    void main(void)
    {
       int i;
    
    // WARNING: Always ensure you call memcpy before running any functions from RAM
    // InitSysCtrl includes a call to a RAM based function and without a call to
    // memcpy first, the processor will go "into the weeds"
       #ifdef _FLASH
    	memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
       #endif
    
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the f2802x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initialize GPIO:
    // This example function is found in the f2802x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio();  // Skipped for this example
       InitEPwmGpio();
    // 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 f2802x_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 f2802x_DefaultIsr.c.
    // This function is found in f2802x_PieVect.c.
       InitPieVectTable();
    
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
       EALLOW;  // This is needed to write to EALLOW protected registers
       PieVectTable.EPWM1_INT = &epwm1_timer_isr;
       PieVectTable.EPWM2_INT = &epwm2_timer_isr;
       PieVectTable.EPWM3_INT = &epwm3_timer_isr;
       EDIS;    // This is needed to disable write to EALLOW protected registers
    
    // Step 4. Initialize all the Device Peripherals:
       InitEPwmTimer();    // For this example, only initialize the ePWM Timers
       InitAdc();  // For this example, init the ADC
       AdcOffsetSelfCal();
    // Step 5. User specific code, enable interrupts:
    
    // Initialize counters:
       EPwm1TimerIntCount = 0;
       EPwm2TimerIntCount = 0;
       EPwm3TimerIntCount = 0;
    
    // Enable CPU INT3 which is connected to EPWM1-6 INT:
       IER |= M_INT3;
    
       // Configure ADC
       //Note: Channel ADCINA4  will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errata
          EALLOW;
          AdcRegs.ADCCTL1.bit.INTPULSEPOS	= 1;	//ADCINT1 trips after AdcResults latch
          AdcRegs.INTSEL1N2.bit.INT1E     = 1;	    //Enabled ADCINT1
          AdcRegs.INTSEL1N2.bit.INT1CONT  = 0;	    //Disable ADCINT1 Continuous mode
          AdcRegs.INTSEL1N2.bit.INT1SEL	= 2;	//setup EOC2 to trigger ADCINT1 to fire
          AdcRegs.ADCSOC0CTL.bit.CHSEL 	= 4;	//set SOC0 channel select to ADCINA4
          AdcRegs.ADCSOC1CTL.bit.CHSEL 	= 4;	//set SOC1 channel select to ADCINA4
          AdcRegs.ADCSOC2CTL.bit.CHSEL 	= 2;	//set SOC1 channel select to ADCINA2
          AdcRegs.ADCSOC0CTL.bit.TRIGSEL 	= 5;	//set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
          AdcRegs.ADCSOC1CTL.bit.TRIGSEL 	= 5;	//set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
          AdcRegs.ADCSOC2CTL.bit.TRIGSEL 	= 5;	//set SOC2 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1, then SOC2
          AdcRegs.ADCSOC0CTL.bit.ACQPS 	= 6;	//set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
          AdcRegs.ADCSOC1CTL.bit.ACQPS 	= 6;	//set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
          AdcRegs.ADCSOC2CTL.bit.ACQPS 	= 6;	//set SOC2 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
          EDIS;
    
    // Enable EPWM INTn in the PIE: Group 3 interrupt 1-6
       PieCtrlRegs.PIEIER3.bit.INTx1 = PWM1_INT_ENABLE;
       PieCtrlRegs.PIEIER3.bit.INTx2 = PWM2_INT_ENABLE;
       PieCtrlRegs.PIEIER3.bit.INTx3 = PWM3_INT_ENABLE;
    
     /*PieCtrlRegs.PIEIFR3.bit.INTx1 = 1;
     PieCtrlRegs.PIEIFR3.bit.INTx2 = 1;
     PieCtrlRegs.PIEIFR3.bit.INTx3 = 1;*/
    
    
    // Enable global Interrupts and higher priority real-time debug events:
       EINT;   // Enable Global interrupt INTM
       ERTM;   // Enable Global realtime interrupt DBGM
    
    // Step 6. IDLE loop. Just sit and loop forever (optional):
       for(;;)
       {
           __asm("          NOP");
           for(i=1;i<=10;i++)
           {}
       }
    }
    
    void InitEPwmTimer()
    {
       EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;      // Stop all the TB clocks
       EDIS;
    
       // Setup Sync
       EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;  // Pass through
       EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;  // Pass through
       EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;  // Pass through
    
       // Allow each timer to be sync'ed
    
       EPwm1Regs.TBCTL.bit.PHSEN = TB_ENABLE;
       EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE;
       EPwm3Regs.TBCTL.bit.PHSEN = TB_ENABLE;
    
       EPwm1Regs.TBPHS.half.TBPHS = 0;
       EPwm2Regs.TBPHS.half.TBPHS = 0;
       EPwm3Regs.TBPHS.half.TBPHS = 0;
    //EPwm1Regs.PCCTL.bit.CHPFREQ = 1;
    //EPwm1Regs.PCCTL.bit.CHPEN = 1;
       EPwm1Regs.TBPRD = PWM1_TIMER_TBPRD;
       EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
       // Count up For UPDOWN Write TB_COUNT_UPDOWN
       // EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
       //EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
       EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;     // Select INT on Zero event
       EPwm1Regs.ETSEL.bit.INTEN = PWM1_INT_ENABLE;  // Enable INT
       EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;// Generate INT on 1st event
       EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // enable Dead-band module
       EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi complementary
       EPwm1Regs.DBFED = 150; // FED = 20 micro sec=606 TBCLKs
       EPwm1Regs.DBRED = 150;
    
       EPwm2Regs.TBPRD = PWM2_TIMER_TBPRD;
      // EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Slave module
      // EPwm2Regs.TBCTL.bit.PHSDIR = TB_UP;
       EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;     // Count up
       EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;      // Enable INT on Zero event
       EPwm2Regs.ETSEL.bit.INTEN = PWM2_INT_ENABLE;   // Enable INT
       EPwm2Regs.ETPS.bit.INTPRD = ET_1ST;            // Generate INT on 2nd event
    //EPwm2Regs.ETPS.bit.INTPRD = ET_1ST;
       EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // enable Dead-band module
       EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi complementary
       EPwm2Regs.DBFED = 150; // FED = 20 TBCLKs
       EPwm2Regs.DBRED = 150;
    
    
       EPwm3Regs.TBPRD = PWM3_TIMER_TBPRD;
       //EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Slave module
       //EPwm2Regs.TBCTL.bit.PHSDIR = TB_DOWN;
       EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;     // Count up
       EPwm3Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;      // Enable INT on Zero event
       EPwm3Regs.ETSEL.bit.INTEN = PWM3_INT_ENABLE;   // Enable INT
       EPwm3Regs.ETPS.bit.INTPRD = ET_1ST;            // Generate INT on 3rd event
    // EPwm3Regs.ETPS.bit.INTPRD = ET_1ST;
       EPwm3Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // enable Dead-band module
       EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi complementary
       EPwm3Regs.DBFED = 150; // FED = 20 TBCLKs
       EPwm3Regs.DBRED = 150;
    
       EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;    // Load registers every ZERO
         EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
         EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
         EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
         EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;    // Load registers every ZERO
           EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
           EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
           EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
           EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;    // Load registers every ZERO
             EPwm3Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
             EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
             EPwm3Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
       EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;         // Start all the timers synced
       EDIS;
    }
    
    
    // Interrupt routines uses in this example:
    interrupt void epwm1_timer_isr(void)
    {
    
    
    	th = th + 6.2832 * f / 1115; // fsw = 5000
    
    	if(th>=6.2832)
    	{
    
    		th = th - 6.2832;
    	}
    
    	a = (unsigned int)(3500 + 3500 * ma * sin(th));
    	b = (unsigned int)(3500 + 3500 * ma * sin(th - 2.094395));
    	c = (unsigned int)(3500 + 3500 * ma * sin(th + 2.094395));
    
    
    //	a = _IQsat(_IQ30mpy((sine_table[index]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0);
    //	b = _IQsat(_IQ30mpy((sine_table[index2]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0);
    //	c = _IQsat(_IQ30mpy((sine_table[index3]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0);
    //    if (index++ >511) index = 0;
    //    if (index2++ >511) index2 = 0;
    //    if (index3++ >511) index3 = 0;
    
    	/*sinewave1[i]=b;
    	sinewave2[i]=c;
    	i++;
    	if(i==200)
    	{
    		i=0;
    
    	}*/
    
       EPwm1Regs.CMPA.half.CMPA = a;
       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;             // Set PWM1A on Zero
          EPwm1Regs.AQCTLA.bit.CAD = AQ_SET;
    
          EPwm1Regs.AQCTLB.bit.CAU = AQ_SET;          // Set PWM1A on Zero
          EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR;
    
         EPwm2Regs.CMPA.half.CMPA = b;
    
          	EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;             // Set PWM1A on Zero
          	   EPwm2Regs.AQCTLA.bit.CAD = AQ_SET;
    
          	   EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;          // Set PWM1A on Zero
          	   EPwm2Regs.AQCTLB.bit.CAD = AQ_CLEAR;
    
          	 EPwm3Regs.CMPA.half.CMPA = c;
    
          	 	EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;             // Set PWM1A on Zero
          	 	   EPwm3Regs.AQCTLA.bit.CAD = AQ_SET;
    
          	 	   EPwm3Regs.AQCTLB.bit.CAU = AQ_SET;          // Set PWM1A on Zero
          	 	   EPwm3Regs.AQCTLB.bit.CAD = AQ_CLEAR;
    
    
    	EPwm1TimerIntCount++;
    
    
    	 Voltage1[ConversionCount] = AdcResult.ADCRESULT1;  //discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0
    	  Voltage2[ConversionCount] = AdcResult.ADCRESULT2;
    
    	  // If 20 conversions have been logged, start over
    	  if(ConversionCount == 9)
    	  {
    	     ConversionCount = 0;
    	  }
    	  else
    	  {
    	      ConversionCount++;
    	  }
    
    	  AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;		//Clear ADCINT1 flag reinitialize for next SOC
    	  PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;   // Acknowledge interrupt to PIE
    
    
    
    
       // Clear INT flag for this timer
       EPwm1Regs.ETCLR.bit.INT = 1;
    
       // Acknowledge this interrupt to receive more interrupts from group 3
       //PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    }
    
    interrupt void epwm2_timer_isr(void)
    {
    	/*EPwm2Regs.CMPA.half.CMPA = b;
    
    	EPwm2Regs.AQCTLA.bit.CAU = AQ_CLEAR;             // Set PWM1A on Zero
    	   EPwm2Regs.AQCTLA.bit.CAD = AQ_SET;
    
    	   EPwm2Regs.AQCTLB.bit.CAU = AQ_SET;          // Set PWM1A on Zero
    	   EPwm2Regs.AQCTLB.bit.CAD = AQ_CLEAR;*/
    
    	EPwm2TimerIntCount++;
    
       // Clear INT flag for this timer
       EPwm2Regs.ETCLR.bit.INT = 1;
    
       // Acknowledge this interrupt to receive more interrupts from group 3
       //PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    }
    
    interrupt void epwm3_timer_isr(void)
    {
    	/*EPwm3Regs.CMPA.half.CMPA = c;
    
    	EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;             // Set PWM1A on Zero
    	   EPwm3Regs.AQCTLA.bit.CAD = AQ_SET;
    
    	   EPwm3Regs.AQCTLB.bit.CAU = AQ_SET;          // Set PWM1A on Zero
    	   EPwm3Regs.AQCTLB.bit.CAD = AQ_CLEAR;*/
    
    
    	EPwm3TimerIntCount++;
    
       // Clear INT flag for this timer
       EPwm3Regs.ETCLR.bit.INT = 1;
    
       // Acknowledge this interrupt to receive more interrupts from group 3
       //PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    }

  • Maharshi,

    Sorry, I previously misunderstood your issue...

    I highly recommend that you incrementally add, build and test when merging code. It will make debugging much easier. It sounds like the PWM configuration has either not been completed or has been changed after you add the ADC code.

    1. Step through your code ensure that the PWM initialization code being executed
      1. At the same time verify that the configuration is being written to the registers using the memory browswer, you may have an EALLOW issue
    2. After all configurations are correctly configured allow the code to run freely.
      1. Pause the code after a few seconds and use the memory browser to verify the PWMs configuration again. (you may have other code in memory that is messing up your configuration.
    3. Check if the PWMs ISRs are correctly configured
      1. Are they executing as expected? Is it possible that you have a high priority interrupt preempting your code?

    Regards,
    Cody 

  • From your advice i checked the program and i started building a new program from example. I started with an example program from the c2000 ware examples . i have modified its epwm timer interrupt program. the program was working fine until it was only SPWM then i added the ADC code to it with an ADC isr. after that the problem started, i got two ADC channels working but it seems like the pwm pulse is stuck at one instance and its duty is not changing .

    I am using EPWM4 to trigger the ADC SOC and EPWM1 to EPWM3 are used for SPWM generation.

    The code that i modified is bellow.

    Regards,

    Maharshi

    //#############################################################################
    //
    //  File:   Example_F2802xEPwmTimerInt.c
    //
    //  Title:  F2802x ePWM Timer Interrupt example.
    //
    //! \addtogroup example_list
    //!  <h1>PWM Timer Interrupt</h1>
    //!
    //!   This example configures the ePWM Timers and increments
    //!   a counter each time an interrupt is taken.
    //!
    //!   As supplied:
    //!    - All ePWM's are initialized.
    //!    - All timers have the same period.
    //!    - The timers are started sync'ed.
    //!
    //!   An interrupt is taken on a zero event for each ePWM timer.
    //!    - ePWM1: takes an interrupt every event \n
    //!    - ePWM2: takes an interrupt every 2nd event \n
    //!    - ePWM3: takes an interrupt every 3rd event
    //!
    //!   Thus the Interrupt count for ePWM1 and ePWM4 should be equal.
    //!   The interrupt count for ePWM2 should be about half that of ePWM1,
    //!   and the interrupt count for ePWM3 should be about 1/3 that of ePWM1
    //!
    //!   Watch Variables:
    //!   - EPwm1TimerIntCount
    //!   - EPwm2TimerIntCount
    //!   - EPwm3TimerIntCount
    //
    //#############################################################################
    // $TI Release: F2802x Support Library v3.02.00.00 $
    // $Release Date: Sun Mar 25 13:23:09 CDT 2018 $
    // $Copyright:
    // Copyright (C) 2009-2018 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without 
    // modification, are permitted provided that the following conditions 
    // are met:
    // 
    //   Redistributions of source code must retain the above copyright 
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the 
    //   documentation and/or other materials provided with the   
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    #include "common/include/adc.h"
    #include "common/include/clk.h"
    #include "common/include/flash.h"
    #include "common/include/gpio.h"
    #include "common/include/pie.h"
    #include "common/include/pll.h"
    #include "common/include/pwm.h"
    #include "common/include/wdog.h"
    #include "IQmathLib.h" //IQmath Library header file
    #pragma DATA_SECTION(sine_table,"IQmathTables"); //IQmath ROM sine table
    _iq30 sine_table[512];
    Uint16 index=0;             // Zero degrees sine
    Uint16 index2=170;          // 120 degrees sine difference
    Uint16 index3=340;          // 240 degrees sine difffence
    //
    // Defines that configure which ePWM timer interrupts are enabled at the PIE 
    // level: 1 = enabled,  0 = disabled
    //
    #define PWM1_INT_ENABLE  1
    #define PWM2_INT_ENABLE  1
    #define PWM3_INT_ENABLE  1
    
    //
    // Defines that configure the period for each timer
    //
    #define PWM1_TIMER_TBPRD   0x1FFF
    #define PWM2_TIMER_TBPRD   0x1FFF
    #define PWM3_TIMER_TBPRD   0x1FFF
    #define PWM4_TIMER_TBPRD   0x1FFF
    #define EPWM1_TIMER_TBPRD  11000 // Period register for 2050.2Hz
    //
    // Function Prototypes
    //
    __interrupt void adc_isr(void);
    __interrupt void epwm1_timer_isr(void);
    __interrupt void epwm2_timer_isr(void);
    __interrupt void epwm3_timer_isr(void);
    void InitEPwmTimer(void);
    
    //
    // Globals
    //
    uint32_t  EPwm1TimerIntCount;
    uint32_t  EPwm2TimerIntCount;
    uint32_t  EPwm3TimerIntCount;
    uint16_t LoopCount;
    uint16_t ConversionCount;
    uint16_t TempSensorVoltage[10];
    uint16_t ADC0, ADC1, ADC2, ADC3, sp, mean;
    Uint16 DEADTIME_R=1000;      // Deadtime 5usec
    Uint16 DEADTIME_F=1000;      // Deadtime 5usec
    
    ADC_Handle myAdc;
    CLK_Handle myClk;
    FLASH_Handle myFlash;
    GPIO_Handle myGpio;
    PIE_Handle myPie;
    PWM_Handle myPwm1, myPwm2, myPwm3, myPwm4;
    
    void gpio_init()
    {
        // Initialize GPIO for the EPWM1A and EPWM1B
        GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable);
        GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable);
        GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A);
        GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B);
        GPIO_setDirection(myGpio,GPIO_Number_0,GPIO_Direction_Output);
        GPIO_setDirection(myGpio,GPIO_Number_1,GPIO_Direction_Output);
        // Initialize GPIO for the EPWM2A and EPWM2B
        GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable);
        GPIO_setPullUp(myGpio, GPIO_Number_3, GPIO_PullUp_Disable);
        GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_EPWM2A);
        GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_EPWM2B);
        GPIO_setDirection(myGpio,GPIO_Number_2,GPIO_Direction_Output);
        GPIO_setDirection(myGpio,GPIO_Number_3,GPIO_Direction_Output);
        // Initialize GPIO for the EPWM2A and EPWM2B
        GPIO_setPullUp(myGpio, GPIO_Number_4, GPIO_PullUp_Disable);
        GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Disable);
        GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A);
        GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_EPWM3B);
        GPIO_setDirection(myGpio,GPIO_Number_4,GPIO_Direction_Output);
        GPIO_setDirection(myGpio,GPIO_Number_5,GPIO_Direction_Output);
    }
    
    
    //
    // Main
    //
    void main(void)
    {
        int i;
        CPU_Handle myCpu;
        PLL_Handle myPll;
        WDOG_Handle myWDog;
    
        //
        // Initialize all the handles needed for this application
        //
        myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
        myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
        myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
        myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
        myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
        myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
        myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
        myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj));
        myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj));
        myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj));
        myPwm4 = PWM_init((void *)PWM_ePWM4_BASE_ADDR, sizeof(PWM_Obj));
        myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
    
        //
        // Perform basic system initialization
        //
        WDOG_disable(myWDog);
        CLK_enableAdcClock(myClk);
        (*Device_cal)();
    
        //
        // Select the internal oscillator 1 as the clock source
        //
        CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
    
        //
        // Setup the PLL for x10 /1 which will yield 120Mhz = 10Mhz * 12 / 1
        //
        PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_1);
    
        //
        // Disable the PIE and all interrupts
        //
        PIE_disable(myPie);
        PIE_disableAllInts(myPie);
        CPU_disableGlobalInts(myCpu);
        CPU_clearIntFlags(myCpu);
    
        //
        // If running from flash copy RAM only functions to RAM
        //
    #ifdef _FLASH
        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    #endif
    
        //
        // Setup a debug vector table and enable the PIE
        //
        PIE_setDebugIntVectorTable(myPie);
        PIE_enable(myPie);
    
        //
        // Register interrupt handlers in the PIE vector table
        //
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_1,
                                  (intVec_t)&epwm1_timer_isr);
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_2,
                                  (intVec_t)&epwm2_timer_isr);
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_3,
                                  (intVec_t)&epwm3_timer_isr);
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_10, PIE_SubGroupNumber_1,
                                      (intVec_t)&adc_isr);
        //
        // For this example, only initialize the ePWM Timers
        //
    
        //
        // Initialize the ADC
        //
        ADC_enableBandGap(myAdc);
        ADC_enableRefBuffers(myAdc);
        ADC_powerUp(myAdc);
        ADC_enable(myAdc);
        ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int);
    
        ADC_disableTempSensor(myAdc);
    
        ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior);
        ADC_enableInt(myAdc, ADC_IntNumber_1);
        ADC_setIntMode(myAdc, ADC_IntNumber_1, ADC_IntMode_ClearFlag);
        ADC_setIntSrc(myAdc, ADC_IntNumber_1, ADC_IntSrc_EOC1);
        ADC_setSocChanNumber (myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A0);
        ADC_setSocChanNumber (myAdc, ADC_SocNumber_1, ADC_SocChanNumber_A4);
        ADC_setSocTrigSrc(myAdc, ADC_SocNumber_0, ADC_SocTrigSrc_EPWM4_ADCSOCA);
        ADC_setSocTrigSrc(myAdc, ADC_SocNumber_1, ADC_SocTrigSrc_EPWM4_ADCSOCA);
        ADC_setSocSampleWindow(myAdc, ADC_SocNumber_0,
                               ADC_SocSampleWindow_37_cycles);
        ADC_setSocSampleWindow(myAdc, ADC_SocNumber_1,
                               ADC_SocSampleWindow_37_cycles);
    
        PIE_enableAdcInt(myPie, ADC_IntNumber_1);
        CPU_enableInt(myCpu, CPU_IntNumber_10);
        CPU_enableGlobalInts(myCpu);
        CPU_enableDebugInt(myCpu);
    
        LoopCount = 0;
        ConversionCount = 0;
    
        CLK_enablePwmClock(myClk, PWM_Number_4);
    
        PWM_enableSocAPulse(myPwm4);
        PWM_setSocAPulseSrc(myPwm4, PWM_SocPulseSrc_CounterEqualCmpAIncr);
        PWM_setSocAPeriod(myPwm4, PWM_SocPeriod_FirstEvent);
        ((PWM_Obj *)myPwm4)->CMPA = 0x0800;
        PWM_setPeriod(myPwm4, 0xFFFF);
        PWM_setCounterMode(myPwm4, PWM_CounterMode_Up);
    
    
        InitEPwmTimer();
    
        //
        // Initialize counters
        //
        EPwm1TimerIntCount = 0;
        EPwm2TimerIntCount = 0;
        EPwm3TimerIntCount = 0;
        gpio_init();
        //
        // Enable CPU INT3 which is connected to EPWM1-6 INT
        //
        CPU_enableInt(myCpu, CPU_IntNumber_3);
    
        //
        // Enable EPWM INTn in the PIE: Group 3 interrupt 1-6
        //
        PIE_enablePwmInt(myPie, PWM_Number_1);
        PIE_enablePwmInt(myPie, PWM_Number_2);
        PIE_enablePwmInt(myPie, PWM_Number_3);
    
        //
        // Enable global Interrupts and higher priority real-time debug events
        //
        CPU_enableGlobalInts(myCpu);
        CPU_enableDebugInt(myCpu);
        CLK_enableTbClockSync(myClk);
        for(;;)
        {
            __asm(" NOP");
            for(i=1;i<=10;i++)
            {
                
            }
        }
    }
    
    //
    // InitEPwmTimer -
    //
    void
    InitEPwmTimer()
    {
        //
        // Stop all the TB clocks
        //
        CLK_disableTbClockSync(myClk);
    
        CLK_enablePwmClock(myClk, PWM_Number_1);
        CLK_enablePwmClock(myClk, PWM_Number_2);
        CLK_enablePwmClock(myClk, PWM_Number_3);
        CLK_enablePwmClock(myClk, PWM_Number_4);
    
        //
        // Setup Sync
        //
        PWM_setSyncMode(myPwm1, PWM_SyncMode_EPWMxSYNC);
        PWM_setSyncMode(myPwm2, PWM_SyncMode_EPWMxSYNC);
        PWM_setSyncMode(myPwm3, PWM_SyncMode_EPWMxSYNC);
        PWM_setSyncMode(myPwm4, PWM_SyncMode_EPWMxSYNC);
    
        //
        // Allow each timer to be sync'ed
        //
        PWM_enableCounterLoad(myPwm1);
        PWM_enableCounterLoad(myPwm2);
        PWM_enableCounterLoad(myPwm3);
        PWM_enableCounterLoad(myPwm4);
    
        PWM_setPhase(myPwm1, 0);
        PWM_setPhase(myPwm2, 0);
        PWM_setPhase(myPwm3, 0);
    
        PWM_setPeriod(myPwm1, PWM1_TIMER_TBPRD);
        PWM_setCounterMode(myPwm1, PWM_CounterMode_Up);      // Count up
        
        //
        // Select INT on Zero event
        //
        PWM_setIntMode(myPwm1, PWM_IntMode_CounterEqualZero);
        
        PWM_enableInt(myPwm1);                               // Enable INT
        
        //
        // Generate INT on 1st event
        //
        PWM_setIntPeriod(myPwm1, PWM_IntPeriod_FirstEvent);
    
        PWM_setPeriod(myPwm2, PWM2_TIMER_TBPRD);
        PWM_setCounterMode(myPwm2, PWM_CounterMode_Up);         // Count up
        
        //
        // Enable INT on Zero event
        //
        PWM_setIntMode(myPwm2, PWM_IntMode_CounterEqualZero);
        
        PWM_enableInt(myPwm2);                                  // Enable INT
        
        //
        // Generate INT on 2nd event
        //
        PWM_setIntPeriod(myPwm2, PWM_IntPeriod_SecondEvent);
    
        PWM_setPeriod(myPwm3, PWM3_TIMER_TBPRD);
        PWM_setCounterMode(myPwm3, PWM_CounterMode_Up);         // Count up
        
        //
        // Enable INT on Zero event
        //
        PWM_setIntMode(myPwm3, PWM_IntMode_CounterEqualZero);
        
        PWM_enableInt(myPwm3);                                  // Enable INT
        
        //
        // Generate INT on 3rd event
        //
        PWM_setIntPeriod(myPwm3, PWM_IntPeriod_ThirdEvent);
        // Count up
        PWM_setActionQual_CntUp_CmpA_PwmA(myPwm1, PWM_ActionQual_Set);      // Set PWM1A on event A, up count
        PWM_setActionQual_CntDown_CmpA_PwmA(myPwm1, PWM_ActionQual_Clear);  // Clear PWM1A on event A, down count
        PWM_setActionQual_CntUp_CmpB_PwmB(myPwm1, PWM_ActionQual_Clear);      // Set PWM1B on event B, up count
        PWM_setActionQual_CntDown_CmpB_PwmB(myPwm1, PWM_ActionQual_Set);  // Clear PWM1B on event B, down count
        //Set DeadBand Control
        PWM_setDeadBandOutputMode(myPwm1, PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
        PWM_setDeadBandPolarity(myPwm1, PWM_DeadBandPolarity_EPWMxB_Inverted);
        PWM_setDeadBandInputMode(myPwm1, PWM_DeadBandInputMode_EPWMxA_Rising_and_Falling);
        PWM_setActionQual_CntUp_CmpA_PwmA(myPwm2, PWM_ActionQual_Set);      // Set PWM1A on event A, up count
        PWM_setActionQual_CntDown_CmpA_PwmA(myPwm2, PWM_ActionQual_Clear);  // Clear PWM1A on event A, down count
        PWM_setActionQual_CntUp_CmpB_PwmB(myPwm2, PWM_ActionQual_Clear);      // Set PWM1B on event B, up count
        PWM_setActionQual_CntDown_CmpB_PwmB(myPwm2, PWM_ActionQual_Set);  // Clear PWM1B on event B, down count
        //Set DeadBand Control
        PWM_setDeadBandOutputMode(myPwm2, PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
        PWM_setDeadBandPolarity(myPwm2, PWM_DeadBandPolarity_EPWMxB_Inverted);
        PWM_setDeadBandInputMode(myPwm2, PWM_DeadBandInputMode_EPWMxA_Rising_and_Falling);
        PWM_setActionQual_CntUp_CmpA_PwmA(myPwm3, PWM_ActionQual_Set);      // Set PWM1A on event A, up count
        PWM_setActionQual_CntDown_CmpA_PwmA(myPwm3, PWM_ActionQual_Clear);  // Clear PWM1A on event A, down count
        PWM_setActionQual_CntUp_CmpB_PwmB(myPwm3, PWM_ActionQual_Clear);      // Set PWM1B on event B, up count
        PWM_setActionQual_CntDown_CmpB_PwmB(myPwm3, PWM_ActionQual_Set);  // Clear PWM1B on event B, down count
        //Set DeadBand Control
        PWM_setDeadBandOutputMode(myPwm3, PWM_DeadBandOutputMode_EPWMxA_Rising_EPWMxB_Falling);
        PWM_setDeadBandPolarity(myPwm3, PWM_DeadBandPolarity_EPWMxB_Inverted);
        PWM_setDeadBandInputMode(myPwm3, PWM_DeadBandInputMode_EPWMxA_Rising_and_Falling);
        PWM_setDeadBandRisingEdgeDelay(myPwm1, DEADTIME_R);
        PWM_setDeadBandFallingEdgeDelay(myPwm1, DEADTIME_F);
        PWM_setDeadBandRisingEdgeDelay(myPwm2, DEADTIME_R);
        PWM_setDeadBandFallingEdgeDelay(myPwm2, DEADTIME_F);
        PWM_setDeadBandRisingEdgeDelay(myPwm3, DEADTIME_R);
        PWM_setDeadBandFallingEdgeDelay(myPwm3, DEADTIME_F);
        //
        // Start all the timers synced
        //
        CLK_enableTbClockSync(myClk);
    }
    
    //
    // Interrupt routines uses in this example
    //
    
    //
    // epwm1_timer_isr - 
    //
    __interrupt void
    epwm1_timer_isr(void)
    {
        EPwm1TimerIntCount++;
    
        //
        // Clear INT flag for this timer
        //
        //
        // Acknowledge this interrupt to receive more interrupts from group 3
        //
        PIE_clearInt(myPie, PIE_GroupNumber_3);
    }
    
    //
    // epwm2_timer_isr - 
    //
    __interrupt void
    epwm2_timer_isr(void)
    {
        EPwm2TimerIntCount++;
    
        //
        // Clear INT flag for this timer
        //
        PWM_clearIntFlag(myPwm2);
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 3
        //
        PIE_clearInt(myPie, PIE_GroupNumber_3);
    }
    
    //
    // epwm3_timer_isr -
    //
    __interrupt void
    epwm3_timer_isr(void)
    {
        EPwm3TimerIntCount++;
    
        //
        // Clear INT flag for this timer
        //
        PWM_clearIntFlag(myPwm3);
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 3
        //
        PIE_clearInt(myPie, PIE_GroupNumber_3);
    }
    
    __interrupt void
    adc_isr(void)
    {
        TempSensorVoltage[ConversionCount] = ADC_readResult(myAdc,
                                                            ADC_ResultNumber_1);
        		PWM_setCmpA(myPwm1,_IQsat(_IQ30mpy((sine_table[index]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
                PWM_setCmpB(myPwm1,_IQsat(_IQ30mpy((sine_table[index]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
                PWM_setCmpA(myPwm2,_IQsat(_IQ30mpy((sine_table[index2]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
                PWM_setCmpB(myPwm2,_IQsat(_IQ30mpy((sine_table[index2]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
                PWM_setCmpA(myPwm3,_IQsat(_IQ30mpy((sine_table[index3]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
                PWM_setCmpB(myPwm3,_IQsat(_IQ30mpy((sine_table[index3]+_IQ30(0.9999))/2,EPWM1_TIMER_TBPRD),EPWM1_TIMER_TBPRD,0));
                index++;
                index2++;
                index3++;
                if (index++ >511) index = 0;
                if (index2++ >511) index2 = 0;
                if (index3++ >511) index3 = 0;
        //
        // If 20 conversions have been logged, start over
        //
        if(ConversionCount == 9)
        {
            ConversionCount = 0;
        }
        else
        {
            ConversionCount++;
        }
    
        PWM_clearIntFlag(myPwm1);
        ADC_clearIntFlag(myAdc, ADC_IntNumber_1);
           PIE_clearInt(myPie, PIE_GroupNumber_10);
        return;
    }
    //
    // End of File
    //
    
    

  • Maharshi,
    How long is your ISR code? Is it possible that your ISR takes so long to execute that it has already received another interrupt before the ISR has returned?
    It may keep the rest of you code from executing. Is your PWM initialization code still running when you add in the ADC parts. Read your PWM configuration using the memory browser and confirm that is OK.

    Regards,
    Cody