Interrupt problems

10 Feb 2011

I am trying to measure the time between 2 interrupts (about 8 msec apart). I get stuck forever in my "while (zcrsv_flag==0)" statement. I do get the interrupts and the flag gets set. If I comment out the "while" statements the program runs but of course the measurement is inaccurate.

timer.reset(); zcrsv_flag = 0; LPC_GPIOINT->IO2IntEnF |= 0x00000020; Enable zcrsv int while (zcrsv_flag == 0); LPC_GPIOINT->IO2IntEnF &= 0xFFFFDF; Disable zcrs int timer.start(); zcrsv_flag=0; LPC_GPIOINT->IO2IntEnF |= 0x00000020; Enable zcrsv int while (zcrsv_flag==0); LPC_GPIOINT->IO2IntEnF &= 0xFFFFCF; Disable zcrs int timer.stop();

void zcrsv_handler(void) { LPC_GPIOINT->IO2IntEnF &= 0xFFFFDF; Disable zcrsv int printf("z"); zcrsv_flag=1; return; }end zcrsv_handler

Sorry. I don't know why the listing above is messed up.

I tried putting in single character printfs but they also don't work if the "whiles" are in the code. Even printfs that are at the very beginning of the program will not print???

10 Feb 2011

Place your code between <<code>> and <</code>> tags so we can read it please :)

10 Feb 2011

I removed the comments to make it more readable. The tabs must not work on the postings.

timer.reset(); zcrsv_flag = 0; LPC_GPIOINT->IO2IntEnF |= 0x00000020; while (zcrsv_flag == 0); LPC_GPIOINT->IO2IntEnF &= 0xFFFFDF; timer.start(); zcrsv_flag=0; LPC_GPIOINT->IO2IntEnF |= 0x00000020; while (zcrsv_flag==0); LPC_GPIOINT->IO2IntEnF &= 0xFFFFCF; timer.stop();

Interrupt handler

void zcrsv_handler(void) { LPC_GPIOINT->IO2IntEnF &= 0xFFFFDF; zcrsv_flag=1; return; }

10 Feb 2011

    timer.reset();
    zcrsv_flag = 0;
    LPC_GPIOINT->IO2IntEnF |= 0x00000020;    
    while (zcrsv_flag == 0);
    LPC_GPIOINT->IO2IntEnF &= 0xFFFFDF;    
    timer.start();
    zcrsv_flag=0;
    LPC_GPIOINT->IO2IntEnF |= 0x00000020;   
    while (zcrsv_flag==0);
    LPC_GPIOINT->IO2IntEnF &= 0xFFFFCF;    
    timer.stop();

interrupt handler

void
zcrsv_handler(void)
{
    LPC_GPIOINT->IO2IntEnF &= 0xFFFFDF;    
    zcrsv_flag=1;
    return;
}

Thanks!

10 Feb 2011

Sorry about the typo. Should be 0xFFFFFFCF.

10 Feb 2011

I'm not see a

LPC_GPIOINT->IO2IntClr = (LPC_GPIOINT->IO2IntStatR | LPC_GPIOINT->IO2IntStatF);

or similar in there. If you don't clear teh source of the interrupt it'll re-enter on exit.

10 Feb 2011

I tried adding that in the handler, but it still does the same thing. I put a printf in the while statement and it doesn't hang but the times don't look quite right. The first while prints 1 time but the second prints around 20. I also get the earlier printf when I do that???

10 Feb 2011

Is zcrsv_flag declared volatile? How do you register the handler?

It might be best to post (or publish) the whole program.

10 Feb 2011

Igor,

It wasn't declared volatile. That fixed it. Thanks!

Kevin