4250|0

1

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

关于28335芯片的CAP功能实现 [复制链接]

大家好,关于CAP功能实现有关问题向你们请教,我想用CAP功能实现无刷直流电机的换相,用CAP1,CAP2,CAP3,分别捕获电机霍尔信号,CAP1,2,3单独测试,功能一切正常,当CAP1,2,3三路同时工作,捕获的数据是错误。也不知道是什么原因,以下是相关代码以及寄存器信息。搞了一个星期了。也没有搞定,特请教专家解答。非常感谢
CAP初始化
void SetCap1Mode(void)
{
ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap1Regs.ECEINT.all=0x0000;//stop all interrupt
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
// ECap1Regs.ECEINT.bit.CEVT1=1;// Enable cevt1 interrupt
// ECap1Regs.ECEINT.bit.CEVT2=1;// Enable cevt2 interrupt
// ECap1Regs.ECEINT.bit.CEVT3=1;// Enable cevt3 interrupt
// ECap1Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
}
void SetCap2Mode(void)
{
ECap2Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap2Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
ECap2Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap2Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
ECap2Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap2Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap2Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap2Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
ECap2Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap2Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap2Regs.ECEINT.all=0x0000;//stop all interrupt
ECap2Regs.ECCLR.all=0xFFFF;//clare all flag
ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启
ECap2Regs.ECEINT.bit.CEVT1=1;// Enable cevt1 interrupt
ECap2Regs.ECEINT.bit.CEVT2=1;// Enable cevt2 interrupt
ECap2Regs.ECEINT.bit.CEVT3=1;// Enable cevt3 interrupt
ECap2Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
}
void SetCap3Mode(void)
{
ECap3Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap3Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
ECap3Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap3Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
ECap3Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap3Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap3Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap3Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
ECap3Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap3Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap3Regs.ECEINT.all = 0x0000;//stop all interrupt
ECap3Regs.ECCLR.all = 0xffff;//clare all flag
ECap3Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
// ECap3Regs.ECEINT.bit.CEVT1=1;// Enable cevt1 interrupt
// ECap3Regs.ECEINT.bit.CEVT2=1;// Enable cevt2 interrupt
// ECap3Regs.ECEINT.bit.CEVT3=1;// Enable cevt3 interrupt
// ECap3Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
}
以下为中断代码
interrupt void ISRCap1(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=0;//设定cap1~3为gpio
GpioCtrlRegs.GPAMUX2.bit.GPIO25=0;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=0;
capstastus=(GpioDataRegs.GPADAT.all&0x07000000)>>24;
speed1[capdata1]=capstastus;
capdata1++;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=1;//设定cap1~3为cap
GpioCtrlRegs.GPAMUX2.bit.GPIO25=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=1;
// Acknowledge this interrupt to receive more interrupts from group 1
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
EDIS;
}
interrupt void ISRCap2(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=0;//设定cap1~3为gpio
GpioCtrlRegs.GPAMUX2.bit.GPIO25=0;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=0;
capstastus=(GpioDataRegs.GPADAT.all&0x07000000)>>24;
speed2[capdata2]=capstastus;
capdata2++;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=1;//设定cap1~3为cap
GpioCtrlRegs.GPAMUX2.bit.GPIO25=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=1;

/*************************/
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
ECap2Regs.ECCLR.all=0xFFFF;
EDIS;
}
单路测试 工作正常 以下是寄存器信息
CAP1 2两路同时工作  出现错误。以下出错寄存器信息

 
点赞 关注

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

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表