社区导航

 
查看: 1644|回复: 2

[经验] DSP28335 ecap使用

[复制链接]

16

TA的帖子

0

TA的资源

一粒金砂(初级)

Rank: 1

发表于 2016-6-28 15:32:07 | 显示全部楼层 |阅读模式

输入捕获有4级捕获,最多可以得到4个捕获时间,捕获记性可以任意配置

可用于测速,测脉冲周期,频率,占空比等

cap.c

#include "cap.h"

void InitCap(void)
{
   InitECap5Gpio();
   InitECap6Gpio();
   SetCap5();
   SetCap6();
}

void SetCap5(void)
{
  ECap5Regs.ECCTL1.bit.CAP1POL = EC_RISING;  
  ECap5Regs.ECCTL1.bit.CAP2POL = EC_FALLING; //EC_RISING;
  ECap5Regs.ECCTL1.bit.CAP3POL = EC_RISING;
  ECap5Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
  ECap5Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
  ECap5Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE;
  ECap5Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
  ECap5Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE;
  ECap5Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
  ECap5Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
  ECap5Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
  ECap5Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;  //连续捕获
  ECap5Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
  ECap5Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
  ECap5Regs.ECEINT.all=0x0000;//stop all interrupt
  ECap5Regs.ECCLR.all=0xFFFF;//clare all flag
  ECap5Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
  ECap5Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt  //第4个捕获事件发生时,产生中断
}

void SetCap6(void)
{
  ECap6Regs.ECCTL1.bit.CAP1POL = EC_FALLING;
  ECap6Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
  ECap6Regs.ECCTL1.bit.CAP3POL = EC_FALLING;
  ECap6Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
  ECap6Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
  ECap6Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE;
  ECap6Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
  ECap6Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE;
  ECap6Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
  ECap6Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
  ECap6Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
  ECap6Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
  ECap6Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
  ECap6Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
  ECap6Regs.ECEINT.all=0x0000;//stop all interrupt
  ECap6Regs.ECCLR.all=0xFFFF;//clare all flag
  ECap6Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
  ECap6Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
}

Uint32 t1,t2,t3,t4,T1,T2;
interrupt void ISRCap5(void)
{
   // Acknowledge this interrupt to receive more interrupts from group 1
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
    ECap5Regs.ECCLR.all=0xFFFF;//clare all flag
t1= ECap5Regs.CAP1;
t2= ECap5Regs.CAP2;
t3= ECap5Regs.CAP3;
    t4= ECap5Regs.CAP4;
    T1=t2-t1;T2=t3-t1;
}


Uint32 t5,t6,t7,t8,T3,T4;
interrupt void ISRCap6(void)
{
   // Acknowledge this interrupt to receive more interrupts from group 1
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
    ECap6Regs.ECCLR.all=0xFFFF;//clare all flag
t5= ECap6Regs.CAP1;
t6= ECap6Regs.CAP2;
t7= ECap6Regs.CAP3;
    t8= ECap6Regs.CAP4;
    T3=t6-t5;T4=t8-t7;

}



cap.h

#ifndef CAP_H_
#define CAP_H_

#include "main.h"

extern Uint32 t1,t2,t3,t4,T1,T2;
extern Uint32 t5,t6,t7,t8,T3,T4;

void InitCap(void);
void SetCap5(void);
void SetCap6(void);

interrupt void ISRCap5(void);
interrupt void ISRCap6(void);

#endif /* CAP_H_ */


main函数中要调用的

InitCap(); //输入捕获初始化

PieVectTable. ECAP5_INT = &ISRCap5;  //输入捕获5

IER |= M_INT4;    //输入捕获
PieVectTable. ECAP6_INT = &ISRCap6;  //输入捕获6


PieCtrlRegs.PIEIER4.bit.INTx5 = 1;   //输入捕获5中断
  PieCtrlRegs.PIEIER4.bit.INTx6 = 1;   //输入捕获6中断




回复

使用道具 举报

14

TA的帖子

0

TA的资源

一粒金砂(中级)

Rank: 2

发表于 2018-6-22 22:12:33 | 显示全部楼层
想咨询一下,用eCAP模块求方波的频率和占空比怎么求,四个cap寄存器是怎么计算周期和时间的?


回复

使用道具 举报

1

TA的帖子

0

TA的资源

一粒金砂(初级)

Rank: 1

发表于 2018-10-8 17:27:16 | 显示全部楼层
annqisn 发表于 2018-6-22 22:12
想咨询一下,用eCAP模块求方波的频率和占空比怎么求,四个cap寄存器是怎么计算周期和时间的?

问题解决了吗?如何计算捕获的周期频率呢?  上面那段程序是求得占空比吗


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

  • 论坛活动 E手掌握

    扫码关注
    EEWORLD 官方微信

  • EE福利  唾手可得

    扫码关注
    EE福利 唾手可得

Archiver|手机版|小黑屋|电子工程世界 ( 京ICP证 060456 )

GMT+8, 2018-12-19 11:57 , Processed in 0.145468 second(s), 16 queries , Gzip On, MemCache On.

快速回复 返回顶部 返回列表