AVR 模拟比较器 +内部上拉?

发布于 2024-08-27 17:26:38 字数 638 浏览 9 评论 0原文

我希望有一个与 Atmel AVR 微控制器有关的简单问题。因此,我想使用 ATTiny85 的模拟比较器来确定信号是否高于或低于阈值。该信号通常是“浮动”的,并且在“有效”时拉向地(即,它是一个低电平有效 - 集电极开路信号)。如果我通过执行以下操作在输入引脚(也是比较器输入)上启用上拉:

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

如果我使用模拟比较器并选择 PORTB.1 作为 AIN1,内部上拉会应用于我的输入信号吗?我希望有人有亲身经历来验证这种行为。希望这个问题对于堆栈溢出来说不太“面向硬件”。谢谢!

编辑 为了回应下面一些关于“为什么不以数字方式处理它”的评论,这是因为我的“信号”是由传感器(即光学红外传感器)生成的。我不能保证它会“足够硬”地下拉以数字方式解释为零,因此我将使用内部 2.56V 基准作为我的开关阈值。我只是想了解“IR 事件”,所以这对我来说似乎是最简单的方法。

此外,通过使用模拟比较器,我可以使用 ISR“异步”检测事件。虽然某些引脚可以在数字边缘调用中断,但这些引脚不希望依赖于低于 V_IL 的响应。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软糯酥胸 2024-09-03 17:26:38

数据表图10-5中您可以看到输入模拟级受上拉影响。

因此,您可以将内部上拉电阻与比较器一起使用。正如数据表中提到的,您可能希望禁用该端口的数字输入级以降低功耗 - 当然前提是您不将其用于数字输入。

笔记:
浮动引脚可能会导致数字输入级消耗大量电流。尽量避开他们。

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.

晨曦÷微暖 2024-09-03 17:26:38

我不能说它会起作用(我从来没有做过你所描述的情况),但从电子角度来说,你的推理是合理的。当开关打开时,AIN1 将通过内部上拉电阻看到 VCC,而当开关闭合时,它们都将看到 0V。

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

如果没有实际阅读该处理器的数据表,您可能无法在配置为模拟输入的引脚上使用内部上拉;在这种情况下,您可以使用芯片上的另一个引脚(配置为数字输入)进行上拉:

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

但是,如果 AIN1 上的电压始终处于“既不是逻辑高也不是逻辑低”范围内,则可能会导致您的目前的消费相当高。

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.

素染倾城色 2024-09-03 17:26:38

通常您会使用带有上拉的数字输入,因为您似乎有一个数字输入信号。

有理由使用模拟输入吗?

Normally you would use the digital input with the pull-up, since you seem to have a digital input signal.

Is there a reason to use the analog input?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文