Using the PIC16 A/D Module

The PIC16F88 includes a 10-bit Analog-to-Digital (A/D) conversion module with seven input pins. I wanted to test this with a simple rotary potentiometer between Vdd and Gnd with the wiper connected to AN0. An example of this configuration would be a volume control. The pot varies its resistance as the shaft is rotated to produce a voltage on pin 2 that will be sampled with the A/D. The result of the 10-bit A/D conversion will be output to the serial port connected and configured as described in this tutorial.

Here’s the complete circuit:

The A/D conversion clock, TAD should be a minimum of 1.6 us, so it’s set to 8 * FOSC. The complete code to initialize the A/D follows:

Completion of the A/D will trigger an interrupt with the PIR1bits.ADIF bit set. The result is stored in ADRESH and ADRESL and output to the terminal. The 10-bit A/D is sampled and output every 25ms, but the A/D conversion itself takes 11.5 * TAD, or 23 us.

Here’s the code:

Dan Milliken

Leave a Reply

Your email address will not be published. Required fields are marked *