Page 144 - Robots Androids and Animatrons : 12 Incredible Projects You Can Build
P. 144
6.23 Schematic for read comparator
Reading comparators
The microcontroller can also read logic levels from other micro-
controllers, circuits, or ICs. As an example, look at Fig. 6.23. In this
schematic the microcontroller is set to read the output of an com-
parator. Since the output of an LM339 comparator is equivalent to 123
an open collector of an NPN transistor, it is usually brought high by
using an external pull-up resistor. The comparator is read by the
microcontroller using the same programs that detect a logic low.
Reading resistive sensors
The PIC microcontroller is able to read resistive sensors that vary
in resistance from 5K to 50K ohms directly. The types of resistive
sensors one can connect to the microcontroller are numerous, for
instance, photoresistors [cadmium sulfide (CdS) cells], thermistors
(PTC and NTC types), toxic gas sensors, bend sensors, and humidity
sensors. The microcontroller reads the resistance by timing the
discharge of a capacitor through the resistive device (see Fig. 6.24).
The command to read a resistive sensor is
Pot pin, scale, var
where Pot is the command, and pin is the pin number the resis-
tive sensor is connected to. Variable scale is used to adjust the
RC constant. For a large RC constant, scale should be set low,
and for a small RC constant, scale should be set to its maximum
value of 255. When the value of scale is set correctly, the value
contained in the var variable will be near zero at minimum resis-
tance value and to 255 near maximum resistance value.
Team LRN Intelligence