Microcontroller measures resistance without an ADC
Sensors automate most of the processes in industry. Most of these sensors, such as those for ammonia gas, temperature, and the like, are resistive devices in which electrical resistance changes—mostly nonlinearly—as the surrounding conditions change. The sensors’ resistances may vary from 1 mΩ to 10 MΩ.
Figure 1 illustrates a circuit for resistance measurement. The circuit uses an eight-pin AVR microcontroller, a Tiny13V from Atmel, for the controller. The Tiny13V works over a supply-voltage range of 1.8 to 5.5V.
This design implements an equivalent oscillator based on the principle of an astable multivibrator in the Tiny13 (Figure 2).
The oscillator has no stable states, and the signal keeps oscillating between two quasistable states. This oscillator produces a frequency that depends on the value of the resistor. As resistance increases, frequency decreases, and you can easily measure this frequency to yield the value of the resistance.
The resistance you want to measure connects between any two general-purpose I/O pins of the microcontroller, and a capacitor, C1, of known value connects across the other general-purpose I/O pin. Note that PB0 and PB1 are always in different states to implement a NOT gate. PB2 measures a high or a low across resistor R1.
Initially, PB0 is high, PB1 is low, and there is a high-impedance state at PB2. As a result, the capacitor starts charging with time-constant RC. Note that the capacitor initially acts as a short, and PB2 senses a high. As the capacitor charges, the voltage across the resistor decreases, and, when PB2 detects a low, PB1 goes high and PB0 goes low.
Next, as the capacitor discharges, the potential across the resistor builds up, and, when PB2 detects a high, PB0 goes high and PB1 goes low. In this fashion, measuring the frequency or half the number of toggles of PB0 in a second gives an inverse relation of resistance, R1 (in Figure 1), with frequency, f: R1=k/f, where k is a proportionality constant. The result travels to a PC through a serial RS-232 interface. Because the Tiny13 has no UART, a software UART program and the program for measuring resistance are available.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本