AnsweredAssumed Answered

MPC5744 etimer capture fail in one channal

Question asked by ping li on Sep 26, 2017
Latest reply on Sep 27, 2017 by ping li

Hi,NXP

 

look the file ,6 Measure signal parameters:

 

void eTimer_Init(uint8_t EtimerN,uint8_t DspiNumber)
{
volatile struct ETIMER_tag *pETIMERn;

switch(EtimerN)
{ //choose base eTimer address
case 0 : pETIMERn = &ETIMER_0; break;
case 1 : pETIMERn = &ETIMER_1; break;
case 2 : pETIMERn = &ETIMER_2; break;
default: pETIMERn = &ETIMER_0; break;
}


pETIMERn->ENBL.R = 0x0; // disable Timer0 channels

/* Configure the channel */
// pETIMERn->CH[DspiNumber].CTRL1.R = 0x38C1;//0x2001;//0x3801; // Counts only rising edge of the MC_CLK (100MHz in RUN0), divide by 1, count up, count repeatedly, rollover
pETIMERn->CH[DspiNumber].CTRL1.B.PRISRC = 0x18;
pETIMERn->CH[DspiNumber].CCCTRL.B.CPT1MODE = 2;
pETIMERn->CH[DspiNumber].CCCTRL.B.CPT2MODE = 1;
pETIMERn->CH[DspiNumber].CTRL1.B.LENGTH = 0;
pETIMERn->CH[DspiNumber].CTRL1.B.ONCE = 0;
pETIMERn->CH[DspiNumber].CTRL1.B.SECSRC = DspiNumber;
pETIMERn->CH[DspiNumber].CTRL1.B.CNTMODE = 1;

 

pETIMERn->CH[DspiNumber].COMP1.R = 0xFFFF;
pETIMERn->CH[DspiNumber].CCCTRL.R = 0x0264; // compare on COMP1 when counting up, COMP2 when counting down
// CAPT2 on falling edge, CAPT1 on rising edge, 2 entries
// free-running mode
/*
pETIMERn->CH[DspiNumber].CCCTRL.B.ONESHOT = 1;
pETIMERn->CH[DspiNumber].CCCTRL.B.CFWM = 2;


pETIMERn->CH[DspiNumber].CTRL3.R = 1;
pETIMERn->CH[DspiNumber].CTRL3.B.ROC = 3;

pETIMERn->ENBL.B.ENBL |= (1<<DspiNumber); // Enable Timer0 channel 1
pETIMERn->CH[DspiNumber].CCCTRL.B.ARM = 1; // starts the input capture process
//pETIMERn->CH[DspiNumber].CCCTRL.B.ONESHOT = 1;
*/
}

void eTimer_EnableChannal(uint8_t eTimerN,uint8_t DspiNumber)
{
volatile struct ETIMER_tag *pETIMERn;

switch(eTimerN)
{ //choose base eTimer address
case 0 : pETIMERn = &ETIMER_0; break;
case 1 : pETIMERn = &ETIMER_1; break;
case 2 : pETIMERn = &ETIMER_2; break;
default: pETIMERn = &ETIMER_0; break;
}

pETIMERn->ENBL.B.ENBL |= (1<<DspiNumber); // Enable Timer0 channel 1
}

 

void eTimer_Value(uint8_t EtimerN,uint8_t DspiNumber)
{
uint32_t counts;
uint32_t capture_ch[4];
uint8_t eTimerSTS = 0;

float freq,period,duty,pulseH,pulseL;

volatile struct ETIMER_tag *pETIMERn;
eTimer_Channal.duty = 0;
eTimer_Channal.Freq = 0;
eTimer_Channal.Period = 0;

switch(EtimerN)
{ //choose base eTimer address
case 0 : pETIMERn = &ETIMER_0; break;
case 1 : pETIMERn = &ETIMER_1; break;
case 2 : pETIMERn = &ETIMER_2; break;
default: pETIMERn = &ETIMER_0; break;
}

pETIMERn->CH[DspiNumber].CCCTRL.B.ARM = 1;
while((pETIMERn->CH[DspiNumber].STS.B.ICF1 == 0x0)||(pETIMERn->CH[DspiNumber].STS.B.ICF2 == 0x0))
{ //(pETIMERn->CH[DspiNumber].STS.B.ICF1 == 0x0)||(pETIMERn->CH[DspiNumber].STS.B.ICF2 == 0x0)
// Delayms(100);
// if(!(0x0080 & pETIMERn->CH[DspiNumber].STS.R)) eTimerSTS = 1;
}
pETIMERn->CH[DspiNumber].CCCTRL.B.ARM = 0; // stop the input capture process
pETIMERn->CH[DspiNumber].STS.B.ICF1 = 0x1;
pETIMERn->CH[DspiNumber].STS.B.ICF2 = 0x1;


capture_ch[0] = pETIMERn->CH[DspiNumber].CAPT1.R; //First rising edge
capture_ch[1] = pETIMERn->CH[DspiNumber].CAPT2.R; //First falling edge
capture_ch[2] = pETIMERn->CH[DspiNumber].CAPT1.R; //Second rising edge
capture_ch[3] = pETIMERn->CH[DspiNumber].CAPT2.R; //Second falling edge


counts = capture_ch[2] - capture_ch[0];


eTimer_Channal.Freq = (float)(100000000.0/counts);
eTimer_Channal.Period = (counts / (float)100000.0)*1000000;

counts = capture_ch[1] - capture_ch[0];

pulseH = (counts /100000.0)*1000000;
// eTimer_Channal.duty = pulseH/period*100;
eTimer_Channal.duty = ((uint16_t)((capture_ch[1] - capture_ch[0])*1000)/(uint16_t)(capture_ch[2] - capture_ch[0]));

 

PWM:25Hz

 

why I get the  duty fail 

 

clipping

Attachments

Outcomes