【玩转C2000 Launchpad】节日呼吸灯

ddllxxrr   2012-12-28 22:39 楼主
大家知道C2000 Launchpad是四个蓝色LED,为指示灯,我换了绿,红LED,的做了呼吸灯。亮时是呼吸灯似的亮,由于本人的拍摄水平不太好,所以象着和实际不太象,实际好多了,清楚多了。

还有几天就元旦了,我把它放在身边不错哟。

原理是利用PWM的向上和向下方式。实现
IMG_0421.JPG



程序:

#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"
typedef struct
{
//    volatile struct EPWM_REGS *EPwmRegHandle;
    PWM_Handle myPwmHandle;
    uint16_t EPwm_CMPA_Direction;
    uint16_t EPwm_CMPB_Direction;
    uint16_t EPwmTimerIntCount;
    uint16_t EPwmMaxCMPA;
    uint16_t EPwmMinCMPA;
    uint16_t EPwmMaxCMPB;
    uint16_t EPwmMinCMPB;
}EPWM_INFO;

// Prototype statements for functions found within this file.
void InitEPwm4Example(void);
void InitEPwm1Example(void);
void InitEPwm2Example(void);
void InitEPwm3Example(void);
interrupt void epwm4_isr(void);
interrupt void epwm1_isr(void);
interrupt void epwm2_isr(void);
interrupt void epwm3_isr(void);
void update_compare(EPWM_INFO*);
// Global variables used in this example
EPWM_INFO epwm4_info;
EPWM_INFO epwm1_info;
EPWM_INFO epwm2_info;
EPWM_INFO epwm3_info;
// Configure the period for each timer
#define EPWM4_TIMER_TBPRD  200  // Period register
#define EPWM4_MAX_CMPA     199
#define EPWM4_MIN_CMPA       1
#define EPWM4_MAX_CMPB     159
#define EPWM4_MIN_CMPB       1

#define EPWM1_TIMER_TBPRD  200  // Period register
#define EPWM1_MAX_CMPA     199
#define EPWM1_MIN_CMPA       1
#define EPWM1_MAX_CMPB     199
#define EPWM1_MIN_CMPB       1
#define EPWM2_TIMER_TBPRD  200  // Period register
#define EPWM2_MAX_CMPA     199
#define EPWM2_MIN_CMPA       1
#define EPWM2_MAX_CMPB     199
#define EPWM2_MIN_CMPB       1
#define EPWM3_TIMER_TBPRD  200  // Period register
#define EPWM3_MAX_CMPA     199
#define EPWM3_MIN_CMPA       1
#define EPWM3_MAX_CMPB     199
#define EPWM3_MIN_CMPB       1
// To keep track of which way the compare value is moving
#define EPWM_CMP_UP   1
#define EPWM_CMP_DOWN 0
CLK_Handle myClk;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;
PWM_Handle myPwm1, myPwm2, myPwm3,myPwm4;
uint16_t count1;
uint16_t count2;
uint16_t count3;
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));
    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)();
    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
    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
    // Initalize GPIO
    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_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_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);
    // 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_4, (intVec_t)&epwm4_isr);
    PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_1, (intVec_t)&epwm1_isr);
    PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_2, (intVec_t)&epwm2_isr);
    PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_3, (intVec_t)&epwm3_isr);
    CLK_disableTbClockSync(myClk);
    InitEPwm4Example();
    InitEPwm1Example();
    InitEPwm2Example();
    InitEPwm3Example();
    CLK_enableTbClockSync(myClk);
    // Enable CPU INT3 which is connected to EPWM1-3 INT:
    CPU_enableInt(myCpu, CPU_IntNumber_3);

    // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
    PIE_enablePwmInt(myPie, PWM_Number_4);
    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);
    for(;;) {
     asm(" NOP");
    }
}

interrupt void epwm4_isr(void)
{
    // Update the CMPA and CMPB values
    update_compare(&epwm4_info);
    // Clear INT flag for this timer
    PWM_clearIntFlag(myPwm4);
    // Acknowledge this interrupt to receive more interrupts from group 3
    PIE_clearInt(myPie, PIE_GroupNumber_3);
}
interrupt void epwm1_isr(void)
{
  count1++;
  if(count1%6==0)
  {
  count1 = 0;
// Update the CMPA and CMPB values
    update_compare(&epwm1_info);
  }
    // Clear INT flag for this timer
    PWM_clearIntFlag(myPwm1);
    // Acknowledge this interrupt to receive more interrupts from group 3
    PIE_clearInt(myPie, PIE_GroupNumber_3);
}

interrupt void epwm2_isr(void)
{
    count2 ++;
    if(count2%3==0)
    {
count2 = 0;
    // Update the CMPA and CMPB values
    update_compare(&epwm2_info);
    }
    // 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);
}
interrupt void epwm3_isr(void)
{
count3 ++;
if(count3%10==0)
{
    count3 = 0;
// Update the CMPA and CMPB values
    update_compare(&epwm3_info);
}
    // 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);
}

void InitEPwm1Example()
{
    CLK_enablePwmClock(myClk, PWM_Number_1);
   
    // Setup TBCLK
    PWM_setPeriod(myPwm1, EPWM1_TIMER_TBPRD);   // Set timer period 801 TBCLKs
    PWM_setPhase(myPwm1, 0x0000);               // Phase is 0
    PWM_setCount(myPwm1, 0x0000);               // Clear counter
    // Set Compare values
    PWM_setCmpA(myPwm1, EPWM1_MIN_CMPA);    // Set compare A value
    PWM_setCmpB(myPwm1, EPWM1_MIN_CMPB);    // Set Compare B value
    // Setup counter mode
    PWM_setCounterMode(myPwm1, PWM_CounterMode_UpDown); // 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);
    // Setup shadowing
    PWM_setShadowMode_CmpA(myPwm1, PWM_ShadowMode_Shadow);
    PWM_setShadowMode_CmpB(myPwm1, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(myPwm1, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(myPwm1, PWM_LoadMode_Zero);

    // Set actions
    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_Set);      // Set PWM1B on event B, up count
    PWM_setActionQual_CntDown_CmpB_PwmB(myPwm1, PWM_ActionQual_Clear);  // Clear PWM1B on event B, down count
    // Interrupt where we will change the Compare Values
    PWM_setIntMode(myPwm1, PWM_IntMode_CounterEqualZero);   // Select INT on Zero event
    PWM_enableInt(myPwm1);                                  // Enable INT
    PWM_setIntPeriod(myPwm1, PWM_IntPeriod_ThirdEvent);     // 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
    epwm1_info.EPwm_CMPA_Direction = EPWM_CMP_UP;   // Start by increasing CMPA &
    epwm1_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN; // decreasing CMPB
    epwm1_info.EPwmTimerIntCount = 0;               // Zero the interrupt counter
    epwm1_info.myPwmHandle = myPwm1;                // Set the pointer to the ePWM module
    epwm1_info.EPwmMaxCMPA = EPWM1_MAX_CMPA;        // Setup min/max CMPA/CMPB values
    epwm1_info.EPwmMinCMPA = EPWM1_MIN_CMPA;
    epwm1_info.EPwmMaxCMPB = EPWM1_MAX_CMPB;
    epwm1_info.EPwmMinCMPB = EPWM1_MIN_CMPB;
}

void InitEPwm2Example()
{
    CLK_enablePwmClock(myClk, PWM_Number_2);
    // Setup TBCLK
    PWM_setPeriod(myPwm2, EPWM2_TIMER_TBPRD);   // Set timer period 801 TBCLKs
    PWM_setPhase(myPwm2, 0x0000);               // Phase is 0
    PWM_setCount(myPwm2, 0x0000);               // Clear counter
    // Set Compare values
    PWM_setCmpA(myPwm2, EPWM2_MIN_CMPA);        // Set compare A value
    PWM_setCmpB(myPwm2, EPWM2_MIN_CMPB);        // Set Compare B value
    // Setup counter mode
    PWM_setCounterMode(myPwm2, PWM_CounterMode_UpDown); // Count up
    PWM_disableCounterLoad(myPwm2);                     // Disable phase loading
    PWM_setHighSpeedClkDiv(myPwm2, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setClkDiv(myPwm2, PWM_ClkDiv_by_1);
    // Setup shadowing
    PWM_setShadowMode_CmpA(myPwm2, PWM_ShadowMode_Shadow);
    PWM_setShadowMode_CmpB(myPwm2, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(myPwm2, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(myPwm2, PWM_LoadMode_Zero);

    // Set actions
    PWM_setActionQual_CntUp_CmpA_PwmA(myPwm2, PWM_ActionQual_Set);      // Set PWM2A on event A, up count
    PWM_setActionQual_CntDown_CmpB_PwmA(myPwm2, PWM_ActionQual_Clear);  // Clear PWM2A on event B, down count
    PWM_setActionQual_Zero_PwmB(myPwm2, PWM_ActionQual_Set);            // Clear PWM2B on zero
    PWM_setActionQual_Period_PwmB(myPwm2, PWM_ActionQual_Clear);        // Set PWM2B on period
    // Interrupt where we will change the Compare Values
    PWM_setIntMode(myPwm2, PWM_IntMode_CounterEqualZero);   // Select INT on Zero event
    PWM_enableInt(myPwm2);                                  // Enable INT
    PWM_setIntPeriod(myPwm2, PWM_IntPeriod_ThirdEvent);     // 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
    epwm2_info.EPwm_CMPA_Direction = EPWM_CMP_UP;   // Start by increasing CMPA &
    epwm2_info.EPwm_CMPB_Direction = EPWM_CMP_UP;   // increasing CMPB
    epwm2_info.EPwmTimerIntCount = 0;               // Zero the interrupt counter
    epwm2_info.myPwmHandle = myPwm2;                // Set the pointer to the ePWM module
    epwm2_info.EPwmMaxCMPA = EPWM2_MAX_CMPA;        // Setup min/max CMPA/CMPB values
    epwm2_info.EPwmMinCMPA = EPWM2_MIN_CMPA;
    epwm2_info.EPwmMaxCMPB = EPWM2_MAX_CMPB;
    epwm2_info.EPwmMinCMPB = EPWM2_MIN_CMPB;
}
void InitEPwm3Example(void)
{
    CLK_enablePwmClock(myClk, PWM_Number_3);
    // Setup TBCLK
    PWM_setCounterMode(myPwm3, PWM_CounterMode_UpDown); // Count up/down
    PWM_setPeriod(myPwm3, EPWM3_TIMER_TBPRD);           // Set timer period
    PWM_disableCounterLoad(myPwm3);                     // Disable phase loading
    PWM_setPhase(myPwm3, 0x0000);                       // Phase is 0
    PWM_setCount(myPwm3, 0x0000);                       // Clear counter
    PWM_setHighSpeedClkDiv(myPwm3, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setClkDiv(myPwm3, PWM_ClkDiv_by_1);
    // Setup shadow register load on ZERO
    PWM_setShadowMode_CmpA(myPwm3, PWM_ShadowMode_Shadow);
    PWM_setShadowMode_CmpB(myPwm3, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(myPwm3, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(myPwm3, PWM_LoadMode_Zero);
    // Set Compare values
    PWM_setCmpA(myPwm3, EPWM3_MIN_CMPA);    // Set compare A value
    PWM_setCmpB(myPwm3, EPWM3_MIN_CMPB);    // Set Compare B value
    // Set Actions
    PWM_setActionQual_Period_PwmA(myPwm3, PWM_ActionQual_Set);          // Set PWM3A on period
    PWM_setActionQual_CntDown_CmpB_PwmA(myPwm3, PWM_ActionQual_Clear);  // Clear PWM3A on event B, down count
    PWM_setActionQual_Period_PwmB(myPwm3, PWM_ActionQual_Clear);        // Clear PWM3A on period
    PWM_setActionQual_CntUp_CmpA_PwmB(myPwm3, PWM_ActionQual_Set);      // Set PWM3A on event A, up count
    // Interrupt where we will change the Compare Values
    PWM_setIntMode(myPwm3, PWM_IntMode_CounterEqualZero);   // Select INT on Zero event
    PWM_enableInt(myPwm3);                                  // Enable INT
    PWM_setIntPeriod(myPwm3, PWM_IntPeriod_ThirdEvent);     // 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
    epwm3_info.EPwm_CMPA_Direction = EPWM_CMP_UP;   // Start by increasing CMPA &
    epwm3_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN; // decreasing CMPB
    epwm3_info.EPwmTimerIntCount = 0;               // Zero the interrupt counter
    epwm3_info.myPwmHandle = myPwm3;                // Set the pointer to the ePWM module
    epwm3_info.EPwmMaxCMPA = EPWM3_MAX_CMPA;        // Setup min/max CMPA/CMPB values
    epwm3_info.EPwmMinCMPA = EPWM3_MIN_CMPA;
    epwm3_info.EPwmMaxCMPB = EPWM3_MAX_CMPB;
    epwm3_info.EPwmMinCMPB = EPWM3_MIN_CMPB;
}

void InitEPwm4Example(void)
{
    CLK_enablePwmClock(myClk, PWM_Number_4);
    // Setup TBCLK
    PWM_setCounterMode(myPwm4, PWM_CounterMode_UpDown); // Count up/down
    PWM_setPeriod(myPwm4, EPWM4_TIMER_TBPRD);           // Set timer period
    PWM_disableCounterLoad(myPwm4);                     // Disable phase loading
    PWM_setPhase(myPwm4, 0x0000);                       // Phase is 0
    PWM_setCount(myPwm4, 0x0000);                       // Clear counter
    PWM_setHighSpeedClkDiv(myPwm4, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setClkDiv(myPwm4, PWM_ClkDiv_by_1);
    // Setup shadow register load on ZERO
    PWM_setShadowMode_CmpA(myPwm4, PWM_ShadowMode_Shadow);
    PWM_setShadowMode_CmpB(myPwm4, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(myPwm4, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(myPwm4, PWM_LoadMode_Zero);
    // Set Compare values
    PWM_setCmpA(myPwm4, EPWM4_MIN_CMPA);    // Set compare A value
    PWM_setCmpB(myPwm4, EPWM4_MIN_CMPB);    // Set Compare B value
    // Set Actions
    PWM_setActionQual_Period_PwmA(myPwm4, PWM_ActionQual_Set);          // Set PWM3A on period
    PWM_setActionQual_CntDown_CmpB_PwmA(myPwm4, PWM_ActionQual_Clear);  // Clear PWM3A on event B, down count
    PWM_setActionQual_Period_PwmB(myPwm4, PWM_ActionQual_Clear);        // Clear PWM3A on period
    PWM_setActionQual_CntUp_CmpA_PwmB(myPwm4, PWM_ActionQual_Set);      // Set PWM3A on event A, up count
    // Interrupt where we will change the Compare Values
    PWM_setIntMode(myPwm4, PWM_IntMode_CounterEqualZero);   // Select INT on Zero event
    PWM_enableInt(myPwm4);                                  // Enable INT
    PWM_setIntPeriod(myPwm4, PWM_IntPeriod_ThirdEvent);     // 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
    epwm4_info.EPwm_CMPA_Direction = EPWM_CMP_UP;   // Start by increasing CMPA &
    epwm4_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN; // decreasing CMPB
    epwm4_info.EPwmTimerIntCount = 0;               // Zero the interrupt counter
    epwm4_info.myPwmHandle = myPwm4;                // Set the pointer to the ePWM module
    epwm4_info.EPwmMaxCMPA = EPWM4_MAX_CMPA;        // Setup min/max CMPA/CMPB values
    epwm4_info.EPwmMinCMPA = EPWM4_MIN_CMPA;
    epwm4_info.EPwmMaxCMPB = EPWM4_MAX_CMPB;
    epwm4_info.EPwmMinCMPB = EPWM4_MIN_CMPB;
}

void update_compare(EPWM_INFO *epwm_info)
{

    // Every 10'th interrupt, change the CMPA/CMPB values
    if(epwm_info->EPwmTimerIntCount == 10) {
        epwm_info->EPwmTimerIntCount = 0;
        // If we were increasing CMPA, check to see if
        // we reached the max value.  If not, increase CMPA
        // else, change directions and decrease CMPA
        if(epwm_info->EPwm_CMPA_Direction == EPWM_CMP_UP) {
            if(PWM_getCmpA(epwm_info->myPwmHandle) < epwm_info->EPwmMaxCMPA) {
                PWM_setCmpA(epwm_info->myPwmHandle, PWM_getCmpA(epwm_info->myPwmHandle) + 1);
            }
            else {
                epwm_info->EPwm_CMPA_Direction = EPWM_CMP_DOWN;
                PWM_setCmpA(epwm_info->myPwmHandle, PWM_getCmpA(epwm_info->myPwmHandle) - 1);
            }
        }
        // If we were decreasing CMPA, check to see if
        // we reached the min value.  If not, decrease CMPA
        // else, change directions and increase CMPA
        else {
            if(PWM_getCmpA(epwm_info->myPwmHandle) == epwm_info->EPwmMinCMPA) {
                epwm_info->EPwm_CMPA_Direction = EPWM_CMP_UP;
                PWM_setCmpA(epwm_info->myPwmHandle, PWM_getCmpA(epwm_info->myPwmHandle) + 1);
            }
            else {
                PWM_setCmpA(epwm_info->myPwmHandle, PWM_getCmpA(epwm_info->myPwmHandle) - 1);
            }
        }
        // If we were increasing CMPB, check to see if
        // we reached the max value.  If not, increase CMPB
        // else, change directions and decrease CMPB
        if(epwm_info->EPwm_CMPB_Direction == EPWM_CMP_UP) {
            if(PWM_getCmpB(epwm_info->myPwmHandle) < epwm_info->EPwmMaxCMPB) {
                PWM_setCmpB(epwm_info->myPwmHandle, PWM_getCmpB(epwm_info->myPwmHandle) + 1);
            }
            else {
                epwm_info->EPwm_CMPB_Direction = EPWM_CMP_DOWN;
                PWM_setCmpB(epwm_info->myPwmHandle, PWM_getCmpB(epwm_info->myPwmHandle) - 1);
            }
        }
        // If we were decreasing CMPB, check to see if
        // we reached the min value.  If not, decrease CMPB
        // else, change directions and increase CMPB
        else {
            if(PWM_getCmpB(epwm_info->myPwmHandle) == epwm_info->EPwmMinCMPB) {
                epwm_info->EPwm_CMPB_Direction = EPWM_CMP_UP;
                PWM_setCmpB(epwm_info->myPwmHandle, PWM_getCmpB(epwm_info->myPwmHandle) + 1);
            }
            else {
                PWM_setCmpB(epwm_info->myPwmHandle, PWM_getCmpB(epwm_info->myPwmHandle) - 1);
            }
        }
    }
    else {
        epwm_info->EPwmTimerIntCount++;
    }
    return;
}

唯一让我感到疑惑的是ePwm4好像没中断,据体原因仍在查。。。。。
http://shop34182318.taobao.com/ https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr

回复评论 (5)

IMG_0427.JPG
http://shop34182318.taobao.com/ https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
点赞  2012-12-28 22:44
PWM呼吸灯 支持版主
点赞  2012-12-29 10:26
楼主用新库了
点赞  2012-12-29 11:05
最近刚学习这款,楼主真牛
点赞  2014-7-26 15:38
楼主用的是哪个库呢?
点赞  2018-9-30 16:47
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复