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.

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
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.
  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
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.
  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
unsigned tmp;
...
tmp = ADC_Read(2);  // Read analog value from channel 2

 

 

For more detail: Connect ADC with PIC16F877

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter