308 of 318
ZBasic System Library 298 ZX Microcontroller Family By default, each pin that is enabled for a pin change interrupt will trigger the interrupt on either edge. You may configure the sensitivity for each individual pin to trigger an interrupt on either edge, rising edge only, falling edge only or a low level. The setting for each pin change sensitivity is made in a “pin control” register specific to that pin. For example, the pin control register for bit 3 of port C is named PORTC_PIN3CTRL. Consult the ATxmega A datasheet for more information on these registers. Analog Comparator Interrupt (ATmega-based devices) A task may await an analog comparator interrupt by specifying the value &H10 for intNum. The corresponding built-in constant is waitAnalogComp. In this case, the mode parameter specifies the comparator output transition that will cause the interrupt to occur. Analog Comparator Interrupt Mode Values 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. With all of the mode values in the table above, the analog comparator’s positive input is AIN0 (Port B, bit 2) and the comparator’s negative input is either AIN1 (Port B, bit 3) or, if the ACME bit is set in a CPU register (see below), the analog input specified by the multiplexor select bits in Register.ADMUX. On the ZX-24 models, AIN0 is common with Port A, bit 2 so the latter I/O pin will need to be configured to be an input in high-impedance mode. Also, on the ZX-24 models built using boards earlier than Rev 5 (see the bottom side of the board), AIN1 has no external connection so the negative input must be supplied via the analog multiplexor. The ACME bit is in Register.SFIOR for the mega32 and mega128-based ZX models and in Register.ADCSRB in the mega644, mega644P, mega1284P, mega1280 and mega1281-based ZX models. Another option for the positive comparator input is to select the internal “band gap” voltage. This voltage level (approximately 1.23 volts) is selected by adding &H40 to the mode values in the table above. The built-in constant zxAnalogReference has this value. See the section in the Atmel microcontroller documentation describing the analog comparator for further details. Analog Comparator Interrupt (ATxmega-based devices) A task may await an analog comparator interrupt on one of the analog comparator channels by specifying the corresponding value shown in the table below for intNum. Analog Comparator Interrupt Number Values IntNum Built-in Constant Interrupt Trigger Processor &H10 waitAnalogCompA0 Analog Comp A, Channel 0 xmega128A1, xmega32A4 &H11 WaitAnalogCompA1 Analog Comp A, Channel 1 xmega128A1, xmega32A4 &H12 waitAnalogCompAW Analog Comp A, Window mode xmega128A1, xmega32A4 &H13 waitAnalogCompB0 Analog Comp B, Channel 0 xmega128A1 &H14 WaitAnalogCompB1 Analog Comp B, Channel 1 xmega128A1 &H15 waitAnalogCompBW Analog Comp B, Window mode xmega128A1 In order to use any of the analog comparator interrupts, you must first configure positive and negative inputs to the corresponding comparator(s) using the processor registers ACA_AC0MUXCTRL, ACA_AC1MUXCTRL, ACB_AC0MUXCTRL and/or ACB_AC1MUXCTRL. Also, the high speed/low power control bit and the hysteresis control bits in the ACA_AC0CTRL, ACA_AC1CTRL, ACB_AC0CTRL and ACB_AC1CTRL registers may be configured as desired before invoking WaitForInterrupt(). Consult the ATxmega A datasheet for more information on these registers.