Sie sind auf Seite 1von 11

Analog Comparator

What is an analog comparator ?

• An analog comparator is a peripheral that compares two analog voltages
and provide the logical output that signals the comparison result.
• The comparator can provide its output to the device pin, acting as a
replacement for an external analog comparator.
• There are 3 analog comparators integrated in TM4C123x devices that can
be used to
- compare two analog signals and replace an external discrete analog
comparator to save board space and system cost.
- Drive an external pin.
-Trigger an ADC .
-Signal an application using
interrupt .
• The analog comparator can be used to
signal the application via interrupts or
trigger the startup of a sample sequence
in the ADC.
• The interrupt generation and ADC
triggering logic is separate and independent.
• This flexibility means, for example, that an interrupt can be generated on
a rising edge and the ADC can be triggered on a falling edge.
• The block diagram of the analog comparator module :

comparator N’s
negative input
comparator N’s

Analog Output to trigger

comparator N’s the ADC
positive input
Functional Description:
If VIN- < VIN+, VOUT = 1
If VIN- > VIN+, VOUT = 0
• the source for VIN- is anexternal
input Cn-
• the sources for VIN+ can be one of
the following :
-An individual external reference voltage .
-A shared signal external reference voltage (C0+).
-A shared internal voltage reference (VIREF).
• Analog comparators can be configured through
(ACCTL) and (ACSTAT) registers
• The internal reference is configured through
(ACREFCTL). Register
• Interrupt status and control are configured through
(ACMIS) , (ACRIS) and (ACINTEN)registers
Analog Comparator Registers :
- Analog Comparator Control Registers (ACCTLx).

- Analog Comparator Status Registers(ACSTATx).

-analog comparator reference voltage control (ACREFCTL).

- Analog Comparator Masked Interrupt Status Register(ACMIS)

- Analog Comparator Raw Interrupt Status Register (ACRIS)

- Analog Comparator Interrupt Enable (ACINTEN)

• Comparator Internal Reference :
• The internal reference can be programmed in one of two modes :
-low range when RNG in ACREFCTL is set
- high range when RNG in ACREFCTL is clear
• In each range, the internal reference, VIREF, has 16 preprogrammed
thresholds or step values, which is selected using the VREF field in the
ACREFCTL register.
• In the high-range mode, the VIREF threshold voltages start at the ideal high-
range starting voltage of VDDA/4.2 and increase in ideal constant voltage
steps of VDDA/29.4.
• In the low-range mode, the VIREF threshold voltages start at 0 V and increase
in ideal constant voltage steps of VDDA/22.12.
• VIREF(VREF) [Min] = Ideal VIREF(VREF) – (Ideal Step size – 2 mV) / 2
• VIREF(VREF) [Max] = Ideal VIREF(VREF) + (Ideal Step size – 2 mV) / 2
Example Utilizing the AVR Analog Comparator
• System Hardware Description
The Software Description :
#include <avr/io.h>
#define F_CPU 1000000UL
int main(void)

DDRD = 0x01; // Set PD0 as output

ACSR = 0x00; // Configured the Analog Comparator


If (ACSR & (1<<ACO)) // Test if ACO is set

PORTD = 0x01; // Turn LED ON - if ACO = 1
PORTD = 0x00; // Turn LED OFF - if ACO = 0

return 0;