AnsweredAssumed Answered

MPC5643L eTimer ISR

Question asked by mateuszolsztyn on Apr 18, 2017
Latest reply on Apr 18, 2017 by mateuszolsztyn

Hellow,

i'm using eTimer in my MPC for measuring signal period, i have working code but i want to get same effect using interrupt..

 

///// Working code //////

static void InitETimer(void) {

ETIMER_0 .ENBL.R = 0x0;

ETIMER_0 .CHANNEL[1].CTRL1.R = 0x3801 | PRESC << 8;
ETIMER_0 .CHANNEL[1].CCCTRL.R = 0x0052; // 52- CAPT1, CAPT2 falling edge (for period), 62- CAPT1 rising, CAPT2 falling edge
ETIMER_0 .CHANNEL[1].CTRL3.B.DBGEN = 0b01;

ETIMER_0 .ENBL.R = 0x0002;
}


int main(void) {

 

char wynik[] = " ";

InitGPIO();
InitHW();
InitETimer();
lcd_init();
lcd_cls();


ETIMER_0 .CHANNEL[1].CCCTRL.B.ARM = 1;

 

/* Loop forever */
for (;;) {

ETIMER_0.CHANNEL[1].CCCTRL.B.ARM = 1;
while(!(0x80 & ETIMER_0.CHANNEL[1].STS.R)){}

edge1 = ETIMER_0.CHANNEL[1].CAPT1.R;
edge2 = ETIMER_0.CHANNEL[1].CAPT2.R;

 

if(edge1<edge2)
period = (edge2 - edge1)*ETIMER_PRESC/FSYS;
else
period = (edge2 + 65535 - edge1)*ETIMER_PRESC/FSYS;


ETIMER_0.CHANNEL[1].STS.R = 0x00c0;

 

sprintf(wynik, "%d", period);
lcd_locate(1, 0);
lcd_str(wynik);
}
}

 

 

I think that my code should look something like this, as shown below? But i dont know how should configuration look like.. 

 

static void InitETimer(void) {

?

}

 

static void eTimer_isr(void) {
?
}

 

int main(void) {

char wynik[] = " ";

InitGPIO();
InitHW();
InitETimer();

 

INTC_InstallINTCInterruptHandler(eTimer_isr, 158, 1);
INTC .CPR_PRC0.R = 0;

lcd_init();
lcd_cls();


ETIMER_0 .CHANNEL[1].CCCTRL.B.ARM = 1;

 

/* Loop forever */
for (;;) {

sprintf(wynik, "%d", period);
lcd_locate(1, 0);
lcd_str(wynik);
Delay();
}
}

 

 

Would you please help me ?  Thank you very much.

Outcomes