Page 338 of 346 Start Back Next End ZBasic System Library 326 ZBasic Microcontrollers ACB_AC1CTRL registers may be configured as desired before invoking WaitForInterrupt(). Consult the applicable ATxmega datasheet for more information on these registers. The window mode of the analog comparator utilizes both channels of the comparator, with channel 0 representing the high limit of the window and channel 1 representing the low limit of the window. The mode value to use when setting up an analog comparator interrupt differs depending on whether single channel or window mode is being used, see the tables below. Analog Comparator Interrupt Mode Values – Single Channel Mode Value Built-in Constant Interrupt Trigger &H00 zxAnalogCompChange Comparator output rising edge or falling edge. &H02 zxAnalogCompFalling Comparator output falling edge. &H03 zxAnalogCompRising Comparator output rising edge. Analog Comparator Interrupt Mode Values – Window Mode Value Interrupt Trigger &H00 Input signal above the window. &H01 Input signal inside the window. &H02 Input signal below the window. &H03 Input signal outside the window. Operation For all forms, when the trigger condition occurs an interrupt will be generated and the task awaiting the interrupt will rise to the highest priority. This will cause an immediate task switch meaning that the next instruction that executes will be the one following the WaitForInterrupt() invocation. Note that if another task performs an action that causes interrupts to be disabled, response to the interrupt will be delayed until interrupts are re-enabled. The fact that the current task is locked does not prevent the interrupt task from executing next. If two or more interrupts occur simultaneously, the task awaiting the highest priority interrupt is activated first. For VM mode devices, the priorities of the various interrupts are given in the table below. VM Mode Devices Interrupt Priority (highest to lowest) Interrupt 0 Interrupt 1 Interrupt 2 Analog Comparator Interrupt Interrupt 3 Interrupt 4 Interrupt 5 Interrupt 6 Interrupt 7 Pin Change Interrupt, Port A Pin Change Interrupt, Port B Pin Change Interrupt, Port C Pin Change Interrupt, Port D Pin Change Interrupt, Port E Pin Change Interrupt, Port J Pin Change Interrupt, Port K For native mode devices, the interrupt priority corresponds to the order of the entries in the processor’s interrupt vector table: the lower the vector number the higher the priority. Consult the corresponding ATtiny, ATmega or ATxmega processor datasheet for more information on this topic.