AnsweredAssumed Answered

How to use the Capture Register of TMR in MC56F8006?

Question asked by 金峰 吴 on Dec 20, 2016
Latest reply on Dec 22, 2016 by Sutter Zhou

Hello, Thank you for answering my question.

I am using the Capture Register in MC56F8006,and I want to capture a pulse.

But, I have some question.

The data in Capture Register(TMRn_CAPT) don't change.

This is my program as follow:

 

void main(void)
{
/* Write your local variable definition here */

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/

/* Write your code here */

GPIO_Init();
PWM_Init();
clrReg16Bits(TMR_ENBL, 0x03U);
/* ### TimerInt "TI1" init code ... */
TI1_Init();
/* Common peripheral initialization - ENABLE */
/* TMR_ENBL: ENBL|=3 */
setReg16Bits(TMR_ENBL, 0x03U);

CVT=CVD1+CVD2+CVD3+CVD4;
CVT=CVT/4;

 

for(;;){ }
}

 

 

void TI1_Init(void)
{
/* TMR0_CTRL: CM=0,PCS=0,SCS=0,ONCE=0,LENGTH=1,DIR=0,Co_INIT=0,OM=0 */
setReg(TMR0_CTRL,0x60a0);
/* Stop all functions of the timer */
/* TMR1_CTRL: CM=7,PCS=4,SCS=0,ONCE=0,LENGTH=1,DIR=0,Co_INIT=0,OM=0 */
setReg(TMR1_CTRL,0xE820);
/* Set up cascade counter mode */
/*TMR1_SCTRL:TCF=0,TCFIE=0,TOF=0,TOFIE=0,IEF=0,IEFIE=0,IPS=0,INPUT=0,CAPTURE_MODE=0,MSTR=0,EEOF=0,VAL=0,FORCE=0,OPS=0,OEN=0 */
setReg(TMR1_SCTRL,0x00);
/* TMR0_SCTRL:

TCF=0,TCFIE=0,TOF=0,TOFIE=0,IEF=0,IEFIE=0,IPS=0,INPUT=0,CAPTURE_MODE=0,MSTR=0,EEOF=0,VAL=0,FORCE=0,OPS=0,OEN=0 */
setReg(TMR0_SCTRL,0x0040);
setReg(TMR1_CNTR,0x00);
/* Reset counter register */
setReg(TMR0_CNTR,0x00);
setReg(TMR1_LOAD,0x00);
/* Reset load register */
setReg(TMR0_LOAD,0x00);
setReg(TMR1_COMP1,0x00);
/* Set up compare 1 register */
setReg(TMR0_COMP1,0xF9FF);
/* TMR1_CSCTRL: DBG_EN=0,FAULT=0,ALT_LOAD=0,??=0,??=0,??=0,??=0,TCF2EN=0,TCF1EN=1,TCF2=0,TCF1=0,CL2=0,CL1=1 */
setReg(TMR1_CSCTRL,0x41);
/* Enable compare 1 interrupt */
/* TMR0_CSCTRL: DBG_EN=0,FAULT=0,ALT_LOAD=0,??=0,??=0,??=0,??=0,TCF2EN=0,TCF1EN=0,TCF2=0,TCF1=0,CL2=0,CL1=1 */
setReg(TMR0_CSCTRL,0x01);
SetCV((word)0xF9FF,(word)0x00);
/* Store appropriate value to the compare register according to the selected high speed CPU mode */
SetPV((byte)0x08);
/* Set prescaler register according to the selected high speed CPU mode */
setRegBitGroup(TMR0_CTRL,CM,0x01);
/* Run counter */
}

 

int duty;
int d=0;
int CVT,ActualSpeed,CVD1,CVD2,CVD3,CVD4,CV1,CV2,CV3,CV4,CV5;

 

void TI1_OnInterrupt(void)
{
d=d+1;
if(d==1)
{
CV1=TMR0_CAPT;
}
if(d==2)
{
CV2=TMR0_CAPT;
CVD1=CV2-CV1;

}
if(d==3)
{
CV3=TMR0_CAPT;
CVD2=CV3-CV2;
}
if(d==4)
{
CV4=TMR0_CAPT;
CVD3=CV4-CV3;
}
if(d==5)
{;
CV5=TMR0_CAPT;
d=0;
CVD4=CV5-CV4;
}
setReg(TMR1_CSCTRL,0x0041);
}

 

 

The debug result is:

 

You can see the data in TMR0_CAPT don't change.

 

I want to count a speed. So I have to capture a pulse of speed.

Please help me.

Thank you very very much.

Outcomes