MPC5643L eTimer ISR

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MPC5643L eTimer ISR

1,160件の閲覧回数
mateuszolsztyn
Contributor II

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.

0 件の賞賛
返信
2 返答(返信)

868件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

If the interrupt is used instead of polling method then you should properly initialize INTC module and enable interrupt within eTimer module.

So your code could work, only within eTimer initialization the INTDMA register must be configured too.

BR, Petr

0 件の賞賛
返信

868件の閲覧回数
mateuszolsztyn
Contributor II

Hi, thank you for the response.

I modified my code and its working but not good enough. Im measuring signal that has a period of 40ms, and im getting values sometimes good sometimes wrong. I see alternately changing values on my lcd, something like this: 40000 (40ms), 64856, 40000, 64856, 40000, 64856.....

Would you tell me, what im missing?

Here is my code:

static void InitETimer(void) {

ETIMER_0 .ENBL.R = 0x0; 
ETIMER_0 .CHANNEL[1].CTRL1.R = 0x3801 | PRESC << 8;

ETIMER_0 .CHANNEL[1].INTDMA.B.ICF1IE = 1;
ETIMER_0 .CHANNEL[1].INTDMA.B.ICF2IE = 1;

ETIMER_0 .CHANNEL[1].CCCTRL.R = 0x0052;
ETIMER_0 .CHANNEL[1].CTRL3.B.DBGEN = 0b01;

ETIMER_0 .ENBL.R = 0x0002; 

}

 

static void eTimer_isr(void) {

if (ETIMER_0 .CHANNEL[1].STS.B.ICF1) {
edge1 = ETIMER_0 .CHANNEL[1].CAPT1.R;

}

if (ETIMER_0 .CHANNEL[1].STS.B.ICF2) {
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;
ETIMER_0 .CHANNEL[1].CCCTRL.B.ARM = 1;

}

 

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();
}
}

0 件の賞賛
返信