Hi Guys,
I am using LaunchPad C2000. I tried one of the PWM examples. In this example, I can see EPWM1A is around 95% duty ratio and EPWM1B is 50% duty. I can understand EPWM1B. But can anyone help how to change the duty for EPWM1A based on this code. I am a new user of CCS, please write down the changed code.
Many thanks in advance.
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/flash.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/pwm.h"
#include "f2802x_common/include/wdog.h"
// Prototype statements for functions found within this file.
void InitEPwm1Example(void);
interrupt void epwm1_tzint_isr(void);
// Global variables used in this example
uint32_t EPwm1TZIntCount;
CLK_Handle myClk;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;
PWM_Handle myPwm1;
void main(void)
{
CPU_Handle myCpu;
PLL_Handle myPll;
WDOG_Handle myWDog;
// Initialize all the handles needed for this application
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));
myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
// Perform basic system initialization
WDOG_disable(myWDog);
CLK_enableAdcClock(myClk);
(*Device_cal)();
CLK_disableAdcClock(myClk);
//Select the internal oscillator 1 as the clock source
CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
// Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2, input clock is derived from the 10Mhz internal clock
PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2);
// 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
// For this case just init GPIO pins for ePWM1, ePWM2, and TZ pins
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);
// 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_2, PIE_SubGroupNumber_1, (intVec_t)&epwm1_tzint_isr);
CLK_disableTbClockSync(myClk);
InitEPwm1Example();
CLK_enableTbClockSync(myClk);
// Initalize counters:
EPwm1TZIntCount = 0;
// Enable CPU INT3 which is connected to EPWM1-3 INT:
CPU_enableInt(myCpu, CPU_IntNumber_2);
// Enable EPWM INTn in the PIE: Group 2 interrupt 1-3
PIE_enablePwmTzInt(myPie, PWM_Number_1);
PIE_enablePwmTzInt(myPie, PWM_Number_2);
// Enable global Interrupts and higher priority real-time debug events:
CPU_enableGlobalInts(myCpu);
CPU_enableDebugInt(myCpu);
// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;)
{
asm(" NOP");
}
}
interrupt void epwm1_tzint_isr(void)
{
EPwm1TZIntCount++;
PWM_clearTripZone(myPwm1, PWM_TripZoneFlag_DCAEVT1);
PWM_clearTripZone(myPwm1, PWM_TripZoneFlag_Global);
// Acknowledge this interrupt to receive more interrupts from group 2
PIE_clearInt(myPie, PIE_GroupNumber_2);
}
void InitEPwm1Example()
{
CLK_enablePwmClock(myClk, PWM_Number_1);
PWM_setPeriod(myPwm1, 2000); // Set timer period
PWM_setPhase(myPwm1, 0x0000); // Phase is 0
PWM_setCount(myPwm1, 0x0000); // Clear counter
// Setup TBCLK
PWM_setCounterMode(myPwm1, PWM_CounterMode_Up); // Count up
PWM_disableCounterLoad(myPwm1); // Disable phase loading
PWM_setHighSpeedClkDiv(myPwm1, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
PWM_setClkDiv(myPwm1, PWM_ClkDiv_by_1);
PWM_setShadowMode_CmpA(myPwm1, PWM_ShadowMode_Shadow); // Load registers every ZERO
PWM_setShadowMode_CmpB(myPwm1, PWM_ShadowMode_Shadow);
PWM_setLoadMode_CmpA(myPwm1, PWM_LoadMode_Zero);
PWM_setLoadMode_CmpB(myPwm1, PWM_LoadMode_Zero);
// Setup compare
PWM_setCmpA(myPwm1, 500);
// Set actions
PWM_setActionQual_CntUp_CmpA_PwmA(myPwm1, PWM_ActionQual_Clear); // Clear PWM1A on CAU
// Use EPWM1B as a reference
PWM_setActionQual_Zero_PwmB(myPwm1, PWM_ActionQual_Toggle); // TOGGLE PWM1B on Zero
// Define an event (DCAEVT1) based on TZ1 and TZ2
// For blanking we must use the filtered event
// Use the async path to avoid sync to TBCLK
PWM_setDigitalCompareInput(myPwm1, PWM_DigitalCompare_A_High, PWM_DigitalCompare_InputSel_TZ1); // DCAH = TZ1
PWM_setDigitalCompareInput(myPwm1, PWM_DigitalCompare_A_Low, PWM_DigitalCompare_InputSel_TZ2); // DCAL = TZ2
PWM_setTripZoneDCEventSelect_DCAEVT1(myPwm1, PWM_TripZoneDCEventSel_DCxHL_DCxLH); // DCAEVT1 = DCAH low, DCAL high
PWM_setDigitalCompareFilterSource(myPwm1, PWM_DigitalCompare_FilterSrc_DCAEVT1); // DCEVTFLT Filter Source = DCAEVT1
PWM_setDigitalCompareAEvent1(myPwm1, true, true, false, false); // DCAEVT1 = DCEVTFLT, Take asynch path
// What do we want the event (DCAEVT1) to do?
PWM_setTripZoneState_DCAEVT1(myPwm1, PWM_TripZoneState_EPWM_High); // force high on DCAEVT1
// Blank (block) the event during this window
// The window starts at TBCLK = 875 and is 250 TBCLK wide
PWM_setDigitalCompareBlankingPulse(myPwm1, PWM_DigitalCompare_PulseSel_CTR0);
PWM_setDigitalCompareFilterOffset(myPwm1, 875);
PWM_setDigitalCompareFilterWindow(myPwm1, 250);
PWM_enableDigitalCompareBlankingWindow(myPwm1);
PWM_disableDigitalCompareBlankingWindowInversion(myPwm1);
// Enable interrupt on the DCAEVT1
PWM_enableTripZoneInt(myPwm1, PWM_TripZoneFlag_DCAEVT1);
}