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.