blogblog

ADC (Analog-to-Digital Converter) Module in PIC Microcontrollers

Jul 16, 2025 478

Many natural phenomena produce analog electrical signals—signals where one quantity varies continuously in relation to another. Typically, this involves voltage changing in response to factors like force, temperature, light, acceleration, or pressure.

For example, in the LM35 temperature sensor, the output voltage shifts based on the surrounding temperature. By measuring this voltage, we can determine the temperature.

However, most microcontrollers, including PIC microcontrollers, operate digitally. This means they can only detect two states—either high or low—at their input pins, making it necessary to convert analog signals into digital form before processing them.

For instance, if the input voltage is above 2.5V, the microcontroller will interpret it as a high (1); if it's below 2.5V, it will be read as a low (0). Because of this limitation, microcontrollers cannot measure varying voltage levels directly.

To overcome this, most microcontrollers are equipped with an Analog-to-Digital Converter (ADC), which transforms a continuous voltage signal into a corresponding digital value. This digital output can then be processed by the microcontroller.

This functionality enables microcontrollers to interface with a wide range of analog devices. Common examples include temperature sensors, light sensors, touch inputs, accelerometers, and microphones for capturing audio signals.

To learn more, check out this guide on types of analog and digital sensors and their applications.

Analog-to-Digital Converter in PIC Microcontrollers

The role and functionality of the analog-to-digital converter (ADC) in a PIC microcontroller are explained below.

What is a PIC Microcontroller?

PIC stands for Programmable Interface Controller. These microcontrollers can be programmed in advance to perform a wide range of specific functions. For example, a PIC microcontroller can be used to control operations on a production line using built-in timers.

pic microcontroller

PIC microcontrollers are widely used in many electronic applications, including consumer gadgets, computer-based control systems, and security or alarm systems.

Types of PIC Microcontrollers

There are several types of PIC microcontrollers available, but some of the most user-friendly and capable options are found in the GENIE range of programmable microcontrollers. These devices are programmed and simulated using Circuit Wizard software. PIC microcontrollers are relatively affordable and are available either as DIY kits or as pre-assembled circuits that users can further customize and develop.

Analog-to-Digital Conversion

Analog-to-digital conversion is a key function in embedded systems. While microcontrollers process digital data, their environment often involves analog signals—such as those from sensors. These analog inputs must be converted into digital form so the microcontroller can interpret and process them effectively.

Let’s now explore how a PIC microcontroller can be used to read an external analog signal and display the converted digital value on an LCD screen. In this example, the input will be a variable voltage ranging from 0 to 5V.

Analog to Digital Conversion

Analog to Digital Conversion

Key Specifications of an Analog-to-Digital Converter

One of the most important specifications of an ADC is its resolution, which determines how precisely it can measure analog input signals. Common resolutions available in the market include 8-bit, 10-bit, and 12-bit ADCs.

For example, if the ADC operates with a reference voltage of 0 to 5 volts, an 8-bit ADC will divide that voltage range into 256 discrete steps. That means each step represents about 5V / 256 ≈ 19 mV. In contrast, a 10-bit ADC splits the same voltage range into 1024 steps, giving a resolution of approximately 4.88 mV per step.

As a result, an 8-bit ADC wouldn't be able to detect small changes between 1 mV and 18 mV, whereas a 10-bit ADC could. Most PIC microcontrollers feature a 10-bit ADC, providing greater precision for analog measurements.

Another key specification is the sampling rate, which indicates how quickly the ADC can take readings. According to Microchip, the ADC in PIC microcontrollers can achieve speeds of up to 100,000 samples per second (100 ksps)Circuit Diagram of ADC in PIC Microcontroller

Circuit Diagram of ADC in PIC Microcontroller

ADC in PIC Microcontrollers

The ADC module in PIC microcontrollers varies based on the device package. For example:

  • A 28-pin PIC device typically provides 5 analog input channels,
  • A 40-pin device usually supports 8 analog input channels.

When an analog voltage is applied to one of the ADC input pins, the converter processes it into a corresponding 10-bit digital value.

The ADC module allows you to select the reference voltages for conversion through software. These references can be connected to internal sources such as VSS (ground), VDD (supply voltage), or external pins like RA2 and RA3.

In the following example project, we'll demonstrate how to convert an analog input signal into a digital value using a high and low voltage reference, with the output visually indicated by LEDs. You can adjust the reference voltages by configuring the ADCON1 register.

Circuit Diagram of ADC in a PIC Microcontroller

The diagram below shows a circuit for a 10-bit Analog-to-Digital Converter (ADC) using a PIC microcontroller.

In this setup, the input voltage for testing the ADC is provided by a 5k potentiometer, which is connected across the power supply. The adjustable output from the potentiometer is fed into the AN2/RA2 pin of the PIC microcontroller.

The microcontroller uses the power supply voltage as the reference voltage for ADC conversion. This means that the 10-bit ADC will convert any analog voltage within the 0–5V range into a corresponding digital value.

The converted digital output is then displayed on an LCD screen, allowing users to see the result in real time.

Software Requirements for ADC in PIC Microcontroller

To program the Analog-to-Digital (A/D) conversion in a PIC microcontroller, you need to configure several key control registers: ADCON0, ADCON1, and ADCON2.

  • ADCON0: This register is used to select the analog input channel, start the conversion process, monitor whether the conversion is complete, and enable or disable the ADC module.
  • ADCON1: This register allows you to choose the voltage reference source and configure the input pins as analog or digital.
  • ADCON2: This register is used to set the A/D result format (left or right justified), determine the acquisition time, and configure the A/D conversion clock.

In this example, analog input pin AN2/RA2 is used, so the corresponding ANSEL (Analog Select) register must also be configured to enable analog functionality on that pin.

To select AN2 as the input channel in ADCON0, clear bits CHS2 and CHS0, and set CHS1. This connects channel AN2 to the internal Sample-and-Hold (S&H) circuit.

In the ADCON1 register, clearing the VCFG bit sets the device’s power supply (VDD and VSS) as the reference voltage for ADC.

This register can also be used to select the clock source for ADC conversion. However, if you're using MikroC Pro for PIC, the built-in ADC_Read() library function automatically uses the internal RC oscillator as the clock source for ADC operations. Therefore, you generally don't need to manually configure the ADCON1 register when using this function.

Conclusion

In summary, we’ve covered the key concepts of the Analog-to-Digital Converter (ADC) in a PIC microcontroller, including an introduction to PIC microcontrollers, the role of ADCs, how ADC functionality is implemented in PIC devices, and the necessary software and register configurations.

We hope this explanation has helped you gain a clearer understanding of how analog signals are converted into digital form using a PIC microcontroller.

If you have any questions about this topic, or if you're working on PIC microcontroller projects or other electrical and electronics applications, feel free to share your thoughts or ask in the comments section below—we’d love to hear from you.

Question for You:
What are some practical applications of an analog-to-digital converter?

Amanda Miller

Amanda Miller is a senior electronics engineer with 6 years of experience. She focuses on studying resistors, transistors, and package design in detail. Her deep knowledge helps her bring innovation and high standards to the electronics industry.

Subscribe to JMBom Electronics !

Email
Email

Leave Us A Message!

We`re not around but we still want to hear from you! Leave us a note:

SEND
EmailWhatsApp
*You can contact us directly on WhatsApp!