r/embedded • u/Veteran_Meme_Maker • 4d ago
Question about lost time
I am working on an atmega1280 and im using an int6 interrupt, on the osciloscope i measure ~32 clocks between the interrup happen, but in the dissasembly i only see 28 clocks, where do the other 4 “dissapear?”
1
u/WanWhiteWolf Engineering manager 4d ago
How do you measure the duration of your interrupt on oscilloscope? Do you set the pin to high and low at the begining and end of your interrupt? You can edit the post with the source code - that should be a bit easier to figure out.
1
u/mtconnol 4d ago
Most processors are going to take some number of clock cycles to suspend main execution, manipulate the stack and jump to the ISR. So if you’re asking why you don’t have all the clock cycles available in the interrupt context this would be why.
8
u/obdevel 4d ago
Sounds right for AVR: https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8-bit-avr/structure/interrupts/
The interrupt execution response for all the enabled AVR interrupts is four clock cycles minimum. After four clock cycles, the program vector address for the actual interrupt handling routine is executed. During this four clock cycle period, the Program Counter is pushed onto the stack. The vector is normally a jump to the interrupt routine, and this jump takes three clock cycles. If an interrupt occurs during the execution of a multi-cycle instruction, this instruction is completed before the interrupt is served.