Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVR Analog Comparator + Internal Pullup?

I have what I hope is a simple question pertaining to the Atmel AVR microcontrollers. So I want to use the ATTiny85's Analog Comparator to determine if a signal is above or below a threshold. This signal is normally "floating" and pulled toward ground when "active" (i.e. it's an active low - open collector signal). If I enable the pullup on the input pin (which is also the comparator input) by doing:

DDRB  = 0x00; // DDRB.1  = 0 = input 
PORTB = 0xFF; // PORTB.1 = 1 = internal pullup enabled

If i use the analog comparator and select PORTB.1 as AIN1 will the internal pullup be applied to my input signal? I'm hoping someone has personal experience to verify this behavior. Hope this question isn't too 'hardware-oriented' for stack-overflow. Thanks!

EDIT In response to some of the comments below to the effect of "why not treat it digitially", it's because my "signal" is generated by a sensor (namely an optical IR sensor). I can't be assured that it will pull down "hard enough" to be interpretted as a zero digitally, so I'm going to use the internal 2.56V reference as my switching threshold. I'm just trying to pick up the "IR event," so this seemed the simplest way to me.

Also, by using the analog comparator, I can detect the event "asynchronously" using an ISR. Granted some of the pins can invoke an interrupt on a digital edge, but the one don't want to rely on the response to dip below V_IL.

like image 395
vicatcu Avatar asked Apr 08 '10 03:04

vicatcu


2 Answers

From the datasheet figure 10-5 you can see that the input to the analog stage is affected by the pull-up.

Thus you can use the internal pull-up together with the comparator. As mentioned by the datasheet, you might want to disable the digital input stage of that port to reduce power consumption - of course only if you don't use it for digital input.

Note: Floating pins can cause huge current consumption for the digital input stage. Try to avoid them.

like image 177
ziggystar Avatar answered Sep 28 '22 10:09

ziggystar


I can't say for a fact that it will work (I've never done the case you're describing), but electronically speaking your reasoning is sound. When the switch is open, AIN1 will see VCC through the internal pullup, and when the switch is closed, they will both see 0V.

VCC
|
100k(?)
|
AIN1
|
 /
|
GND

Without actually reading the datasheet for that processor, there's a chance that you won't be able to use an internal pull-up on a pin configured for analog input; in that case, you might be able to use another pin on the chip, configured as a digital input, for the pullup:

VCC
|
100k(?)
|
Other---AIN1
        |
        /
        |
        GND

But if the voltage on AIN1 is constantly in the "neither logic high nor logic low" range, that might throw your current consumption fairly high.

like image 40
Mark Rushakoff Avatar answered Sep 28 '22 10:09

Mark Rushakoff