打印

求DSPC2000 F28027eCAP完整项目文件

[复制链接]
3931|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wangjinlili|  楼主 | 2013-9-21 21:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
wangjinlili|  楼主 | 2013-9-21 21:43 | 只看该作者
高电平,求解决,代码如下:
void InitECapture()
{
   ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
   ECap1Regs.ECCLR.all = 0xFFFF;  // Clear all CAP interrupt flags
   ECap1Regs.ECCTL1.bit.CAPLDEN = 0; // Disable CAP1-CAP4 register loads
   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
   // Configure peripheral registers
   ECap1Regs.ECCTL2.bit.CAP_APWM = 0;  //CAP mode
   ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // continuous mode
   ECap1Regs.ECCTL2.bit.STOP_WRAP = 1;   // Stop at 2 events
   ECap1Regs.ECCTL1.bit.PRESCALE = 0;    // Divide by 1
   ECap1Regs.ECCTL1.bit.CAP1POL = 0;          // Rising edge
   ECap1Regs.ECCTL1.bit.CAP2POL = 0;          // Rising edge
   ECap1Regs.ECCTL1.bit.CTRRST1 = 1;          // Difference operation
   ECap1Regs.ECCTL1.bit.CTRRST2 = 0;          // Difference operation
   ECap1Regs.ECCTL2.bit.SYNCI_EN = 0;         // Enable sync in
   ECap1Regs.ECCTL2.bit.SYNCO_SEL = 3;        //  Disable sync out signal
   ECap1Regs.ECCTL1.bit.CAPLDEN = 1;          // Enable capture units
   ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;        // Start Counter
   ECap1Regs.ECEINT.bit.CEVT2 = 1;            // 2 events = interrupt
}
void main(void)
{
   InitSysCtrl();
   EALLOW;    //允许访问受保护的空间
      GpioCtrlRegs.GPADIR.bit.GPIO1=1;
      GpioDataRegs.GPADAT.bit.GPIO1=1;
      EDIS;
      InitECap1Gpio();
      InitECapture();
      EALLOW;  // This is needed to write to EALLOW protected registers
      PieVectTable.ECAP1_INT = &ecap1_isr;
      EDIS; // This is needed to disable write to EALLOW protected registers  // Enable CPU INT4 which is connected to ECAP1-4 INT:
      IER |= M_INT4;
      PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
      // Enable eCAP INTn in the PIE: Group 3 interrupt 1-6
      EINT;   // Enable Global interrupt INTM
      ERTM;   // Enable Global realtime interrupt DBGM
      while(1);
}
interrupt void ecap1_isr(void)
{
//ECap1Count = ECap1Regs.CAP1;
   ECap2Count = ECap1Regs.CAP2;
   GpioDataRegs.GPADAT.bit.GPIO1=0;
//ECap1Regs.ECCLR.all = 0xFFFF;
   ECap1Regs.ECCLR.bit.CEVT2 = 1;
   ECap1Regs.ECCLR.bit.CEVT1 = 1;
   ECap1Regs.ECCLR.bit.INT = 1;
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;

}

使用特权

评论回复
板凳
meishizhaoshi| | 2013-9-21 21:45 | 只看该作者
看一下你的InitECap1Gpio初始化 :   InitECap1Gpio()
我感觉你可能InitECap1Gpio初始化有问题

使用特权

评论回复
地板
gaochy1126| | 2013-9-21 23:30 | 只看该作者
controlsuit软件没有么?

使用特权

评论回复
5
gaochy1126| | 2013-9-21 23:32 | 只看该作者

#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/cap.h"
#include "f2802x_common/include/wdog.h"

// Configure the start/end period for the timer
#define PWM3_TIMER_MIN     10
#define PWM3_TIMER_MAX     8000

// Prototype statements for functions found within this file.
interrupt void ecap1_isr(void);
void InitECapture(void);
void InitEPwmTimer(void);
void Fail(void);

// Global variables used in this example
uint32_t  ECap1IntCount;
uint32_t  ECap1PassCount;
uint32_t  EPwm3TimerDirection;

// To keep track of which way the timer value is moving
#define EPwm_TIMER_UP   1
#define EPwm_TIMER_DOWN 0

CAP_Handle myCap;
CLK_Handle myClk;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;
PWM_Handle myPwm;

void main(void)
{
   
    CPU_Handle myCpu;
    PLL_Handle myPll;
    WDOG_Handle myWDog;
   
    // Initialize all the handles needed for this application   
    myCap = CAP_init((void *)CAPA_BASE_ADDR, sizeof(CAP_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));
    myPwm = PWM_init((void *)PWM_ePWM3_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_4, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A);
   
    GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Enable);
    GPIO_setQualification(myGpio, GPIO_Number_5, GPIO_Qual_Sync);
    GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_ECAP1);

    // 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_4, PIE_SubGroupNumber_1, (intVec_t)&ecap1_isr);

    // Setup peripherals used in this example
    InitEPwmTimer();   
    InitECapture();

    // Initalize counters:
    ECap1IntCount = 0;
    ECap1PassCount = 0;

    // Enable CPU INT4 which is connected to ECAP1-4 INT:
    CPU_enableInt(myCpu, CPU_IntNumber_4);

    // Enable eCAP INTn in the PIE: Group 3 interrupt 1-6
    PIE_enableCaptureInt(myPie);

    // Enable global Interrupts and higher priority real-time debug events:
    CPU_enableGlobalInts(myCpu);
    CPU_enableDebugInt(myCpu);

    for(;;)
    {
        asm("          NOP");
    }

}

使用特权

评论回复
6
gaochy1126| | 2013-9-21 23:32 | 只看该作者

void InitEPwmTimer()
{
   
    CLK_disableTbClockSync(myClk);
    CLK_enablePwmClock(myClk, PWM_Number_3);

    PWM_setCounterMode(myPwm, PWM_CounterMode_Up);
    PWM_setPeriod(myPwm, PWM3_TIMER_MIN);
    PWM_setPhase(myPwm, 0x00000000);
    PWM_setActionQual_Period_PwmA(myPwm, PWM_ActionQual_Toggle);

    // TBCLK = SYSCLKOUT
    PWM_setHighSpeedClkDiv(myPwm, PWM_HspClkDiv_by_2);
    PWM_setClkDiv(myPwm, PWM_ClkDiv_by_1);

    EPwm3TimerDirection = EPwm_TIMER_UP;

    CLK_enableTbClockSync(myClk);

}

使用特权

评论回复
7
gaochy1126| | 2013-9-21 23:32 | 只看该作者


void InitECapture()
{
   
    CLK_enableEcap1Clock(myClk);

    CAP_disableInt(myCap, CAP_Int_Type_All);    // Disable all capture interrupts
    CAP_clearInt(myCap, CAP_Int_Type_All);      // Clear all CAP interrupt flags
    CAP_disableCaptureLoad(myCap);              // Disable CAP1-CAP4 register loads
    CAP_disableTimestampCounter(myCap);         // Make sure the counter is stopped

    // Configure peripheral registers
    CAP_setCapOneShot(myCap);                   // One-shot
    CAP_setStopWrap(myCap, CAP_Stop_Wrap_CEVT4);// Stop at 4 events
    CAP_setCapEvtPolarity(myCap, CAP_Event_1, CAP_Polarity_Falling);    // Falling edge
    CAP_setCapEvtPolarity(myCap, CAP_Event_2, CAP_Polarity_Rising);     // Rising edge
    CAP_setCapEvtPolarity(myCap, CAP_Event_3, CAP_Polarity_Falling);    // Falling edge
    CAP_setCapEvtPolarity(myCap, CAP_Event_4, CAP_Polarity_Rising);     // Rising edge
   
    CAP_setCapEvtReset(myCap, CAP_Event_1, CAP_Reset_Enable);   // Difference operation
    CAP_setCapEvtReset(myCap, CAP_Event_2, CAP_Reset_Enable);   // Difference operation
    CAP_setCapEvtReset(myCap, CAP_Event_3, CAP_Reset_Enable);   // Difference operation
    CAP_setCapEvtReset(myCap, CAP_Event_4, CAP_Reset_Enable);   // Difference operation
   
    CAP_enableSyncIn(myCap);                    // Enable sync in
    CAP_setSyncOut(myCap, CAP_SyncOut_SyncIn);  // Pass through
   
    CAP_enableCaptureLoad(myCap);

    CAP_enableTimestampCounter(myCap);          // Start Counter
    CAP_rearm(myCap);                           // arm one-shot
    CAP_enableCaptureLoad(myCap);               // Enable CAP1-CAP4 register loads
    CAP_enableInt(myCap, CAP_Int_Type_CEVT4);   // 4 events = interrupt

}

interrupt void ecap1_isr(void)
{

    // Cap input is syc'ed to SYSCLKOUT so there may be
    // a +/- 1 cycle variation

    if(CAP_getCap2(myCap) > PWM_getPeriod(myPwm)*2+1 || CAP_getCap2(myCap) < PWM_getPeriod(myPwm)*2-1)
    {
        Fail();
    }

    if(CAP_getCap3(myCap) > PWM_getPeriod(myPwm)*2+1 || CAP_getCap3(myCap) < PWM_getPeriod(myPwm)*2-1)
    {
        Fail();
    }

    if(CAP_getCap4(myCap) > PWM_getPeriod(myPwm)*2+1 || CAP_getCap4(myCap) < PWM_getPeriod(myPwm)*2-1)
    {
        Fail();
    }

    ECap1IntCount++;

    if(EPwm3TimerDirection == EPwm_TIMER_UP) {
        if(PWM_getPeriod(myPwm) < PWM3_TIMER_MAX) {
            PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) + 1);
        }
        else {
            EPwm3TimerDirection = EPwm_TIMER_DOWN;
            PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) - 1);
        }
    }
    else {
        if(PWM_getPeriod(myPwm) > PWM3_TIMER_MIN) {
            PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) - 1);
        }
        else {
            EPwm3TimerDirection = EPwm_TIMER_UP;
            PWM_setPeriod(myPwm, PWM_getPeriod(myPwm) + 1);
        }
    }

    ECap1PassCount++;

    CAP_clearInt(myCap, CAP_Int_Type_CEVT4);
    CAP_clearInt(myCap, CAP_Int_Type_Global);
    CAP_rearm(myCap);

    // Acknowledge this interrupt to receive more interrupts from group 4
    PIE_clearInt(myPie, PIE_GroupNumber_4);
}

void Fail()
{
    asm("   ESTOP0");
}

使用特权

评论回复
8
gaochy1126| | 2013-9-21 23:33 | 只看该作者
这是另外的一个程序的。

使用特权

评论回复
9
gaochy1126| | 2013-9-21 23:33 | 只看该作者

#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/cap.h"
#include "f2802x_common/include/wdog.h"

// Global variables
uint16_t direction = 0;

CLK_Handle myClk;
FLASH_Handle myFlash;
GPIO_Handle myGpio;
PIE_Handle myPie;

void main(void)
{
    CAP_Handle myCap;
    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));
    myCap = CAP_init((void *)CAPA_BASE_ADDR, sizeof(CAP_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_5, GPIO_PullUp_Enable);
    GPIO_setQualification(myGpio, GPIO_Number_5, GPIO_Qual_Sync);
    GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_ECAP1);

    // Setup a debug vector table and enable the PIE
    PIE_setDebugIntVectorTable(myPie);
    PIE_enable(myPie);

    // Setup APWM mode on CAP1, set period and compare registers
    CLK_enableEcap1Clock(myClk);
    CAP_setModeApwm(myCap);                     // Enable APWM mode
    CAP_setApwmPeriod(myCap, 0x01312D00);       // Set Period value
    CAP_setApwmCompare(myCap, 0x00989680);      // Set Compare value
    CAP_clearInt(myCap, CAP_Int_Type_All);      // Clear pending interrupts
    CAP_enableInt(myCap, CAP_Int_Type_CTR_CMP); // enable Compare Equal Int

    // Start counters
    CAP_enableTimestampCounter(myCap);
    for(;;)
    {
        // vary freq
        if(CAP_getCap1(myCap) >= 0x01312D00){
            direction = 0;
        }
        else if(CAP_getCap1(myCap) <= 0x00989680){
            direction = 1;
        }

    }

}

使用特权

评论回复
10
zhangmangui| | 2013-9-21 23:55 | 只看该作者
应该是寄存器配置问题   GPIO19还是高电平什么意思  应该是功能引脚了吧

使用特权

评论回复
11
309579471| | 2014-11-13 16:02 | 只看该作者
zhangmangui 发表于 2013-9-21 23:55
应该是寄存器配置问题   GPIO19还是高电平什么意思  应该是功能引脚了吧

就是这例程。。。看不懂。。也 不会测,。。。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

78

主题

1374

帖子

0

粉丝