Hi,I need to do two time critical operations simultaneously. Each of them would probably require an interrupt:1) phase controlling a triac - this requires to catch the time when AC crosses zero level2) measure pulse frequency from my power meter (converts measured watts to frequency - pulses)My question is, if there is a way to do this using one Arduino without missing any of the two events, or if I will have to use two Arduinos.
Thanks Lefty. I have no idea how long may it take to process one simple ISR (~6 lines of code, substracting integers and storing variables only). But probably you are right, it will not make any significant delay to harm the process.... 16MHz is much more than 700Hz
You should be able to handle them both using the two user interrupts pins on the standard Uno type board (pins 2 and 3 the mega board has more avalible). The individual interrupts are stored and buffered internally such that even if one interrupt ISR is active when the other interrupt arrives, when the first completes the second 'stored' interrupt on the other pin will be serviced. The events you are processing are relatively slow by the AVR 16Mhz speed, so I wouldn't expect any problems for you.Lefty
When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The user soft-ware can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the currentinterrupt routine. The I-bit is automatically set when a Return from Interrupt instruction - RETI - is executed.There are basically two types of interrupts. The first type is triggered by an event that sets the Interrupt Flag. Forthese interrupts, the Program Counter is vectored to the actual Interrupt Vector in order to execute the interrupthandling routine, and hardware clears the corresponding Interrupt Flag. Interrupt Flags can also be cleared by writ-ing a logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the correspondinginterrupt enable bit is cleared, the Interrupt Flag will be set and remembered until the interrupt is enabled, or theflag is cleared by software. Similarly, if one or more interrupt conditions occur while the Global Interrupt Enable bitis cleared, the corresponding Interrupt Flag(s) will be set and remembered until the Global Interrupt Enable bit isset, and will then be executed by order of priority.The second type of interrupts will trigger as long as the interrupt condition is present. These interrupts do not nec-essarily have Interrupt Flags. If the interrupt condition disappears before the interrupt is enabled, the interrupt willnot be triggered.When the AVR exits from an interrupt, it will always return to the main program and execute one more instructionbefore any pending interrupt is served.
OK and what happens, if I simply put "Interrupts();" as the first line of the ISR? Will it allow to nest the other one correctly? I mean the attachInterrupt (0....) and attachInterrupt (1....) for example.