Main Menu
Home
AVR News
Atmel AVR
AVR Development Tools
Valuable Tools
WinAVR toolset
Makefile for WinAVR
AVR Virtual Simulators
Hardware for prototyping
GCC and AVR-GCC
Short introduction to C
AVR-GCC Tutorial
Example AVR Projects
AVR-GCC articles
WinAVR Site Map
Scienceprog FORUM
ScienceProg BLOG
Disclaimer
WinARM Tutorial
Latest comments
Measuring motor speed and...
Dear Administrator The code above...
More...

Programming AVR ADC module...
hi please send me example usart with...
More...

Measuring motor speed and...
main.c: In function...
More...

Running TX433 and RX433 RF...
(Hopefully this is not a re-post). I am...
More...

Running TX433 and RX433 RF...
I just bnought a pair of the RX/TX 433...
More...

Friendly sites

Related Items:

Recommended sites


Latest News
AVR analog comparator review PDF Print E-mail
Written by Administrator   
Thursday, 07 June 2007

Analog comparator is pretty simple peripheral, but it can give big benefits. Comparator module is included in all Mega series of AVR microcontrollers. Simply speaking Comparator allows to compare voltage values applied to two pins of microcontrollers. Result of comparison is a logical level which can be read by program(ACO- Analog Comparator Output bit). There is also ability to generate an interrupt which depends on comparator resulting level. And more- timer T1 can capture this level what allows measuring the signal length of analog signals.

In order to use pins as comparator inputs they have to be prepared and configured as input(DDRx=0) and pull-up resistors mus be disconnected (PORTx=0). In some models like Atmega48x/88x/168x, Atmega165x, Atmega325x,3250x,645x/6450x and Atmega640x/128x/1281x/2560x/2561x there is ability to disconnect digital buffers of AIN0 and AIN1pins that allows to use these pins only for analog signal input – this minimises overal power consumption.

Digital buffers can be disconnected by writing “1” where bits AIN0D and AIN1D are in register DIDR1:

Image

Comparator is controlled by one byte ACSR.

Image


Bit No.

Name

Description

7

ACD

0-ON, 1-OFF comparator

6

ACGB

0 – AIN0 to the positive input of comparator; 1- reference voltage to positive comparator input

5

ACO

Result of comparing.

4

ACI

Interrupt flag

3

ACIE

Enable comparator interrupts

2

ACIC

Connect comparator to timer/counter T1 (1- connected, 0-not)

1,0

ACIS1:ACIS0

Interrupt conditions select


In general Comparator module is simple comparator. If voltage in input of AIN0 is bigger than in AIN1, then result of comparing is equal to 1 and 0 otherwise. Result is stored in ACSR register bit ACO.

Image

If comparator is not used ACD bit should be set to 1 because it will reduce power consumption. Also interrupt from comparator should be disabled. As I mentioned comparator can compare voltage to reference voltage if bit ACBG is set. Then positive input of comparator becomes 1.23V. Second comparator pin can be connected to any pin where ADC input is by using multiplexer. If Multiplexer is enabled (bit ACME in SFIOR register) and ADC is off, then MUX2..0 in ADMUX register selects the input pin(refer to datasheet).


Related Items:

   

Users' Comments  
 

Average user rating

 


Add your comment
Only registered users can comment an article. Please login or register.

No comment posted



mXcomment 1.0.6 © 2007-2008 - visualclinic.fr
License Creative Commons - Some rights reserved
Next >

© 2008 WinAVR AVR-GCC Tutorial
Joomla! is Free Software released under the GNU/GPL License.