查看: 3803|回复: 4

[MPC] 关于MPC5604P的etimes的捕捉!!COMP1和COMP2

[复制链接]

该用户从未签到

5

主题

14

帖子

0

新手上路

Rank: 1

积分
70
最后登录
1970-1-1
发表于 2013-10-7 10:11:49 | 显示全部楼层 |阅读模式
COMP1和COMP2这两个寄存器
void vETIMER1_Init(void)
{
vuint8_t u8StsFlag;
 SIU.PSMI[11].B.PADSEL=0x02;//etimer1 ETC2=PinD1.
 SIU.PSMI[12].B.PADSEL=0x01;//etimer1 ETC3=PinD2
 SIU.PCR[SIUL_NUM_ETC2].R = 0x0900;
 SIU.PCR[SIUL_NUM_ETC3].R = 0x0900;
 
// ETIMER_1.CHANNEL[2].CNTR.R=0;
// ETIMER_1.CHANNEL[3].CNTR.R=0;
 
 u8StsFlag=u8TimerChannelInit(2);
 u8StsFlag=u8TimerChannelInit(3);
 if(u8StsFlag)
  ETIMER_1.ENBL.R = 0x0c;//channel enable   
}
vuint8_t u8TimerChannelInit(unsigned char channelNum)
{
 if(channelNum>5)
  return 0;
 else
 {
 //counter register
  ETIMER_1.CHANNEL[channelNum].CNTR.R=0;
 //LOAD register
  ETIMER_1.CHANNEL[channelNum].LOAD.R=0;//03-21
 //COMP1 register
  ETIMER_1.CHANNEL[channelNum].COMP1.R=0;//03-21 
 //COMPLD1 register
  ETIMER_1.CHANNEL[channelNum].CMPLD1.R=0;//03-21
 //COMP2 register 
  ETIMER_1.CHANNEL[channelNum].COMP2.R=QUATRATURE_MODULE-1;//03-21 
 //COMPLD2 register
  ETIMER_1.CHANNEL[channelNum].CMPLD2.R=QUATRATURE_MODULE-1;//03-21
  
 //CTRL1 register
  ETIMER_1.CHANNEL[channelNum].CTRL.B.CNTMODE =0x04; //0100b is quadrature mode;
    ETIMER_1.CHANNEL[channelNum].CTRL.B.PRISRC=0x02;//qepa is channel 2 source
    ETIMER_1.CHANNEL[channelNum].CTRL.B.ONCE=0;//0:repeat /1nce
    ETIMER_1.CHANNEL[channelNum].CTRL.B.LENGTH=1;//count length/0:count rollover/1:compare then reinitialize//03-21zjq_formalENGTH=0
    ETIMER_1.CHANNEL[channelNum].CTRL.B.DIR=0;//count direction/0:up/1:down
    ETIMER_1.CHANNEL[channelNum].CTRL.B.SECSRC=0x03;//secondary count source/qepb is channel 3
    
 //CTRL2 Register 
    ETIMER_1.CHANNEL[channelNum].CTRL2.B.OEN = 0;//output enable/0:pin is input/1:pin is output
    ETIMER_1.CHANNEL[channelNum].CTRL2.B.RDNT=0;//redundant channel enable/0:disable/1:enable
    ETIMER_1.CHANNEL[channelNum].CTRL2.B.COFRC=0;//co-channel OFLAG force enable/0ther channel cannot force the oflag of this channel/
    ETIMER_1.CHANNEL[channelNum].CTRL2.B.COINIT=0;//co-channel initialization enable/0:disable
    ETIMER_1.CHANNEL[channelNum].CTRL2.B.SIPS=0;//secondary source input polarity select/0:true polariyt/1:inverted polarity
    ETIMER_1.CHANNEL[channelNum].CTRL2.B.PIPS=0;//primary source input polarity select/0:true polariyt/1:inverted polarity
  
 //CTRL3 register
    ETIMER_1.CHANNEL[channelNum].CTRL3.B.STPEN=1;//stop action enable/0utput enable unaffected by stop mode/1utput disable
    ETIMER_1.CHANNEL[channelNum].CTRL3.B.DBGEN=0;//debug action enable /0:normal operation /1:halt channel /2:force oflag to logic 0/3
    
 //CCCTRL register
 //comp1->comp2
  ETIMER_1.CHANNEL[channelNum].CCCTRL.B.CLC2=0x06;//load CNTR with CMPLD2 upon match CMP1
  ETIMER_1.CHANNEL[channelNum].CCCTRL.B.CLC1=0x07;//load CNTR with CMPLD1 upon match CMP2.
  ETIMER_1.CHANNEL[channelNum].CCCTRL.B.CMPMODE=0x01;//COMP1 is used when down,COM2 is used when up
    
  
 //FILT input filter register/latency is [(CNT+3)*PER]+2
    ETIMER_1.CHANNEL[channelNum].FILT.B.FILTCNT=0;//input filter sample count[2:0]/0:3 sample/
    ETIMER_1.CHANNEL[channelNum].FILT.B.FILTPER=2;//input filter sample period[7:0]/0:filter is bypassed/
    
    return 1;  
 }
}
这是针对正交编码的捕捉!!如果仅仅是简单的PWM  频率或者占空比捕捉COMPLD1 register和COMPLD2 register还需要吗?
我知道答案 目前已有3人回答
回复

使用道具 举报

该用户从未签到

5

主题

14

帖子

0

新手上路

Rank: 1

积分
70
最后登录
1970-1-1
 楼主| 发表于 2013-10-7 10:13:29 | 显示全部楼层

回复:关于MPC5604P的etimes的捕捉!!COMP1和COMP2

谁还用过MPC5604P或者MPC5643L的etimer!!有的一起讨论下!
回复 支持 反对

使用道具 举报

该用户从未签到

6

主题

36

帖子

0

新手上路

Rank: 1

积分
90
最后登录
1970-1-1
发表于 2013-10-8 16:17:09 | 显示全部楼层

RE:关于MPC5604P的etimes的捕捉!!COMP1和COMP2

我要通过channel5 capture 输入的波形,请问这样配置正确吗?
生成的代码如下:
void eTimer_0_init_fnc(void)
{
/*------------------------------------------------------------*/
/*            eTimer Counter/Timer  Initialization            */
/*------------------------------------------------------------*/
    ETIMER_0.ENBL.R = 0x0000 ;
        /*Disabled all eTimer channels */
/*-----------------------------------------------------------*/
/*    eTimer Initialization code for the eTimer_0 Device.    */
/*-----------------------------------------------------------*/

    ETIMER_0.DREQ[0].R= 0x000C;
        /*DMA Request0 Select :Ch 3 CAPT1 DMA read req    */
    ETIMER_0.DREQ[1].R= 0x000C;
        /*DMA Request1 Select :Ch 3 CAPT1 DMA read req    */
/*------------------------------------------------------------*/
/*        eTimer_0 Initialization code for the channel 5 .    */
/*------------------------------------------------------------*/

    ETIMER_0.CHANNEL[5].LOAD.R= 0x0000;
        /* Load register value  : 0x0    */
    ETIMER_0.CHANNEL[5].CNTR.R= 0x0000;
        /* Counter value  : 0x0    */
        /* Counter is initialize with same value as LOAD    */
    ETIMER_0.CHANNEL[5].CTRL3.R= 0x2F00;
        /* Stop Actions Enable : Disable    */
        /* Reload on Capture : Reload the counter on a capture 1 event    */
        /* Debug Actions Enable : Continue with normal operation during debug mode    */
    ETIMER_0.CHANNEL[5].FILT.R= 0x0000;
        /* Input Filter Sample Count : 3    */
        /* Input Filter Sample Period : 0    */
    ETIMER_0.CHANNEL[5].CTRL2.R= 0x0000;
        /* Output Enable : Disable    */
        /* Redundant Channel : Disable    */
        /* Force the OFLAG output: Disable    */
        /* Co-channel OFLAG Force : Disable    */
        /* Co-channel Initialization : Other channels cannot force Re-Init of this ch.    */
        /* Secondary Source Input Polarity Select : True    */
        /* Primary Source Input Polarity Select : True    */
        /* Output Polarity Select. :  True    */
        /* Master Mode : Disable    */
        /* Output Mode : Software controlled    */
    ETIMER_0.CHANNEL[5].CMPLD1.R= 0x0000;
        /* Comparator Load Register 1: 0x0    */
    ETIMER_0.CHANNEL[5].COMP1.R= 0x0000;
        /* Comparator 1 value: 0x0    */
    ETIMER_0.CHANNEL[5].CMPLD2.R= 0x0000;
        /* Comparator Load Register 2: 0x0    */
    ETIMER_0.CHANNEL[5].COMP2.R= 0x0000;
        /* Comparator 2 value: 0x0    */
    ETIMER_0.CHANNEL[5].CCCTRL.R= 0x006D;
        /* Compare Load Control 2 : Never preload    */
        /* Compare Load Control 1 : Never preload    */
        /* Compare Mode : Both CMP1 & CMP2 used when Counting Up    */
        /* Capture 2 Mode Control : Capture falling edges    */
        /* Capture 1 Mode Control : Capture rising edges.    */
        /* One Shot Capture Mode : Disable    */
        /* Arm Capture : Enable    */
        /* Capture FIFO Water Mark : 3    */
    ETIMER_0.CHANNEL[5].INTDMA.R= 0x00C0;
        /* Input Capture 2 Flag DMA : Disable    */
        /* Input Capture 1 Flag DMA : Disable    */
        /* Comparater Load Register 2 DMA : Disable    */
        /* Comparater Load Register 1 DMA : Disable    */
        /* Watchdog Flag Interrupt : Disable    */
        /* Redundant Channel Flag Interrupt : Disable    */
        /* Input Capture 2 Flag Interrupt : Enable    */
        /* Input Capture 1 Flag Interrupt : Enable    */
        /* Input Edge High Flag Interrupt : Disable    */
        /* Input Edge Low Flag Interrupt : Disable    */
        /* Timer Overflow Flag Interrupt : Disable    */
        /* Timer Compare 2 Flag Interrupt : Disable    */
        /* Timer Compare 1 Flag Interrupt : Disable    */
        /* Timer Compare Flag Interrupt : Disable    */
    ETIMER_0.CHANNEL[5].CTRL.R= 0x3C05;
        /* Count Mode :  Count rising edges of primary source    */
        /* Primary Count Source : IP Bus clock / 16 prescaler    */
        /* Count Once : Continues    */
        /* Count Till Compare : Disable    */
        /* Count Direction : Count Up    */
        /* Secondary Count Source :  Counter 5 I/P    */

    ETIMER_0.ENBL.R = 0x003F ;
        /* Timer Channel3 : Enable    */
        /* Timer Channel4 : Enable    */
        /* Timer Channel5 : Enable    */
     
    SIU.PCR[44].R = 0x0503;                /* Configure port c[12] as etimer input*/
}
现在我外部给一个方波信号,产生不了中断,读ETIMER_0.CHANNEL[5].STS.B.ICF1和ETIMER_0.CHANNEL[5].STS.B.ICF2他们也一直是0.
回复 支持 反对

使用道具 举报

该用户从未签到

6

主题

36

帖子

0

新手上路

Rank: 1

积分
90
最后登录
1970-1-1
发表于 2013-10-8 16:20:26 | 显示全部楼层

回复:关于MPC5604P的etimes的捕捉!!COMP1和COMP2

 附上rappid配置。

rappid.zip

90.72 KB, 下载次数: 12

回复 支持 反对

使用道具 举报

该用户从未签到

6

主题

36

帖子

0

新手上路

Rank: 1

积分
90
最后登录
1970-1-1
发表于 2013-10-8 16:50:23 | 显示全部楼层

RE:关于MPC5604P的etimes的捕捉!!COMP1和COMP2

我的理解是不用要了,我的程序还是有问题。楼主,帮忙看看。
回复 支持 反对

使用道具 举报

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

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-9-9 20:40 , Processed in 0.087020 second(s), 28 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

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