Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Using timestamp in an interrupt

Hi, i wanted to use the timestamp driver to get an approximation of the time spend in an ISR. Has anyone tried/achieved this? Should it be possible?

I have tried it, but even if i do sequential timestamps, then i consistently get a difference of more than 260,000 counts.

It can't possibly be taking this long to run that code. Debugger is connected for purposes of download to RAM, but debug is off. Timers and Nios II are connected to a 50MHz clk.

The timestamp driver seems to be working fine elsewhere in the code and has an overhead < 100 counts .

Could this be anything to do with it being in the interrupt?

I do have other interrupts running, but even if nesting was somehow enabled, then surely the code i have used would prevent them interrupting this code?

alt_irq_context context1 = alt_irq_disable_all();

TIMESTAMP(start_of_tick);

TIMESTAMP(end_of_tick);

alt_irq_enable_all(context1);

void

timestamp(unsignedint index){//use the altera timestamp driver to get the time

m_timestamps[index] = alt_timestamp();

}

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Problem seems to be solved. The code wasn't properly protecting m_timestamps from race conditions when I was reading them out. Now i am doing this, the counts value seems a lot more reasonable. Thanks Altera for your help.

    Mel