Projects   /   Meters & Test Instruments   /   PIC16F877A

Connect ADC with PIC16F877

ADC (Analog to Digital Converter) module is available with a number of PIC MCU modules. ADC is an electronic circuit that converts continuous signals to discrete digital numbers. ADC Library provides you a comfortable work with the module.

Published
Updated

At a glance

CategoryMeters & Test Instruments
PIC modelPIC16F877A
IncludesCode · Circuit diagram
Reading time~3 min
Jump to a section
  1. Library Routines
  2. ADC_Init
  3. ADC_Get_Sample
  4. ADC_Read
  5. Quick Solutions to Questions related to PIC MCU ADC Library:
  6. Related projects

Summary of Connect ADC with PIC16F877

The article describes an ADC library for PIC microcontrollers, enabling analog-to-digital conversion using internal RC clocks. It details three core routines: `ADC_Init` to configure the module, and `ADC_Get_Sample` or `ADC_Read` to acquire 10 or 12-bit values from specific channels. The library requires MCUs with built-in ADCs, proper TRISx pin configuration, and relies solely on internal voltage references rather than external ones.

Parts used in PIC MCU ADC Library:

  • PIC Microcontroller Unit (MCU) with built-in ADC module
  • Internal RC Clock
  • Analog Input Channels
  • TRISx Configuration Bits
  • Internal Voltage Reference Source

Library Routines

  • ADC_Init
  • ADC_Get_Sample
  • ADC_ReadConnect ADC with PIC16F877

ADC_Init

Prototype void ADC_Init();
Returns Nothing.
Description This routine initializes PIC’s internal ADC module to work with RC clock. Clock determines the time period necessary for performing AD conversion (min 12TAD).
Requires
  • MCU with built-in ADC module.
Example
Code listing
ADC_Init();  // Initialize ADC module with default settings

ADC_Get_Sample

Prototype unsigned ADC_Get_Sample(unsigned short channel);
Returns 10 or 12-bit unsigned value read from the specified channel (MCU dependent).
Description The function aquires analog value from the specified channel.
Parameter channel represents the channel from which the analog value is to be acquired. Refer to the appropriate datasheet for channel-to-pin mapping.
Connect adc with pic16f877  Note : This function doesn't work with the external voltage reference source, only with the internal voltage reference.
Requires
  • The MCU with built-in ADC module.
  • Prior to using this routine, ADC module needs to be initialized.
  • Before using the function, be sure to configure the appropriate TRISx bits to designate pins as inputs.
Example
C source (2)
unsigned adc_value;
...
adc_value = ADC_Get_Sample(2);    // read analog value from ADC module channel 2

Connect ADC with PIC16F877 schematichADC_Read

Prototype unsigned ADC_Read(unsigned short channel);
Returns 10 or 12-bit unsigned value read from the specified channel (MCU dependent).
Description Initializes PIC’s internal ADC module to work with RC clock. Clock determines the time period necessary for performing AD conversion (min 12TAD).
Parameter channel represents the channel from which the analog value is to be acquired. Refer to the appropriate datasheet for channel-to-pin mapping.
Connect adc with pic16f877  Note : This function doesn't work with the external voltage reference source, only with the internal voltage reference.
Requires
  • The MCU with built-in ADC module.
  • Before using the function, be sure to configure the appropriate TRISx bits to designate pins as inputs.
Example
C source (3)
unsigned tmp;
...
tmp = ADC_Read(2);  // Read analog value from channel 2

 

 

For more detail: Connect ADC with PIC16F877

  • What is the primary function of the ADC library?
    The library provides routines to work comfortably with the ADC module that converts continuous signals to discrete digital numbers.
  • How does the ADC_Init routine configure the module?
    This routine initializes the internal ADC module to work with the RC clock, which determines the time period necessary for AD conversion.
  • What data type does ADC_Get_Sample return?
    It returns a 10 or 12-bit unsigned value read from the specified channel, depending on the MCU.
  • Can ADC_Get_Sample use an external voltage reference source?
    No, this function does not work with the external voltage reference source; it only works with the internal voltage reference.
  • What must be done before using ADC_Get_Sample or ADC_Read?
    You must ensure the ADC module is initialized and configure the appropriate TRISx bits to designate pins as inputs.
  • Does ADC_Read perform initialization internally?
    Yes, the description states that ADC_Read initializes the PIC internal ADC module to work with the RC clock.
  • Where can I find information about channel-to-pin mapping?
    You should refer to the appropriate datasheet for channel-to-pin mapping when specifying a channel parameter.
  • What is the minimum time period required for AD conversion?
    The clock determines the time period necessary for performing AD conversion, with a minimum requirement of 12TAD.
Ibrar Ayyub

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough...