
The Cerebellum microcontroller has eight ten-bit analog input ports, ideal for reading in various sensors. As with all Cerebellum I/O, the ports are pinned out with a power and ground bus for each pin. In the case of the analog I/O, the bus uses the Cerebellum's 5V regulated power.
Configuring some analog inputs as digital I/O
The analog input ports are also configurable as digital I/O, however care must be taken to place the correct types of signals in the correct ports - not all combinations of digital/analog I/O are possible. The following table, found in the PIC16F877 datasheet, presents the possible combinations:
Using reference voltages
It is possible to use reference voltages to amplify portions of the 0-5V range by using one or two of of the analog inputs as references. As an example, if you wish to use a sensor which always outputs an analog value between 1 and 3V, you would set A2 to 1V, A3 as 3V, and read in the signal on any of the other analog ports. This will keep you from reading signals less than 1V or greater than 3V, but provides added resolution in the range selected by the references.The voltage into VREF+ (A3) can be any value between 2.5 and 5, and the voltage into VREF- (A2) can be any value from 0 to 2 volts less than VREF+.
Analog input problems
We have experienced a few minor problems using the PIC16F877 analog input ports that it might be helpful to know about:
- ten-bit accuracy with two bits of error - While the PIC16F877 advertises ten bit accuracy, we've found that the analog input ports always have an error of a bit or two. We recommend using the analog input ports as eight-bit ports, and our Cerebellum libraries only return eight-bit values.
- Ghost Signals - If a port is left floating, it will read a value that is close to the nearest driven signal. So if A1 is attached to an IR sensor, expect A2 and A3 to read values that are close to the value of A1.
Analog input port electrical specifications
| Parameter | Min | Max | Units |
| Input Low Voltage | 0 | 0.8 | Volts |
| Input High Voltage | 4.0 | 5 | Volts |
| Output Low Voltage | 0 | 0.6 | Volts |
| Output High Voltage | 4.3 | 5 | Volts |
| Vref+ reference voltage | 2.5 | 5 | Volts |
| Vref- reference voltage | 0 | Vref-2 | Volts |
| Single I/O Pin Source Current | 0 | 25 | Milliamps |
| Single I/O Pin Sink Current | 0 | 25 | Milliamps |
| Total PortA, PortE, and PortB source current (combined) | - | 200 | Milliamps |
|
|

