background image

3. 

Using the Analog Comparator Interrupt

The application note program shows an example on how to enable the comparator interrupt. In the
example, interrupt on comparator toggle is shown. The following procedure is followed:

1.

Clear interrupt flag and ACIS1/ACIS0. The interrupt flag must be cleared first. If not, and the flag for
some reason already is set, the MCU will start executing the interrupt routine immediately when the
interrupts is enabled. Clearing ACIS1/ACIS0 selects interrupt on toggle.

2.

Enable Global Interrupts.

3.

Enable the Analog Comparator Interrupt by setting the ACIE bit in ACSR.

Note that since the ACSR Register is one of the lower 32 I/O, registers, the “SBI” instruction can be used
to set, clear and test bits.

Table 3-1. Analog Comparator Interrupt Enable Performance Figures

Parameter

Value

Code Size (Words)

4

Execution Time (Cycles)

5

Register Usage

Low Registers: None

High Registers: 1

Pointers: None

Interrupts Usage

None

Peripherals Usage

Analog Comparator

Atmel AVR128: Setup and Use of the AVR Analog Comparator [APPLICATION NOTE]

Atmel-0934C-Setup-and-Use-of-the-AVR-Analog-Comparator_AVR128_Application Note-07/2016

6

Содержание AVR128

Страница 1: ...00 asm Detect a positive edge on the comparator output by polling the ACO bit in the Analog Comparator Control and Status Register ACSR Detect a positive edge on the comparator output by polling the Analog Comparator Interrupt Flag ACI in ACSR Initialize interrupt on comparator output toggle An interrupt routine which increments a 16 bit counter each time it is executed is given as an example Atme...

Страница 2: ...CO 3 2 Detecting a Positive Edge by Polling ACI 4 3 Using the Analog Comparator Interrupt 6 4 Revision History 7 Atmel AVR128 Setup and Use of the AVR Analog Comparator APPLICATION NOTE Atmel 0934C Setup and Use of the AVR Analog Comparator_AVR128_Application Note 07 2016 2 ...

Страница 3: ...ng a short pulse will increase Such code might be time out if no edge occurs within a specific period The procedure for detection is as follows 1 If output is high wait for output to go low 2 Wait until output goes high Figure 1 1 ACO Polling Flow Chart START N Y DONE ACO 0 N Y ACO 1 Table 1 1 ACO Polling Performance Figures Parameter Value Code Size Words 4 Response Time Cycles 3 5 Initialization...

Страница 4: ...k for has occurred since the last ACI Reset In this application note positive edge detection by polling ACI is implemented according to the following procedure Setup 1 Set ACIS0 and ACIS1 1 Polling 1 Clear the ACI bit by writing a logical 1 to it 2 Wait until ACI goes high Figure 2 1 ACI Polling Flow Chart SETUP DONE N Y ACO 1 ACIS1 ACIS0 11 CLEAR ACI Table 2 1 ACI Polling Performance Figures Para...

Страница 5: ...nterrupts Usage None Peripherals Usage Analog Comparator Atmel AVR128 Setup and Use of the AVR Analog Comparator APPLICATION NOTE Atmel 0934C Setup and Use of the AVR Analog Comparator_AVR128_Application Note 07 2016 5 ...

Страница 6: ... selects interrupt on toggle 2 Enable Global Interrupts 3 Enable the Analog Comparator Interrupt by setting the ACIE bit in ACSR Note that since the ACSR Register is one of the lower 32 I O registers the SBI instruction can be used to set clear and test bits Table 3 1 Analog Comparator Interrupt Enable Performance Figures Parameter Value Code Size Words 4 Execution Time Cycles 5 Register Usage Low...

Страница 7: ...ents 0934C 07 2016 New template 0934B 05 2002 0934A Initial document release Atmel AVR128 Setup and Use of the AVR Analog Comparator APPLICATION NOTE Atmel 0934C Setup and Use of the AVR Analog Comparator_AVR128_Application Note 07 2016 7 ...

Страница 8: ...R INABILITY TO USE THIS DOCUMENT EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice Atmel does not make any commitment to update the information contain...

Отзывы: