ADC Library
ADC Library
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
Prototype |
|
---|---|
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 |
|
Example |
|
ADC_Get_Sample
Prototype |
|
---|---|
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 Note : This function doesn't work with the external voltage reference source, only with the internal voltage reference. |
Requires |
|
Example |
|
ADC_Read
Prototype |
|
---|---|
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 Note : This function doesn't work with the external voltage reference source, only with the internal voltage reference. |
Requires |
|
Example |
|
Example Code
unsigned int temp_res;
void main() {
ANSEL = 0x04; // Configure AN2 pin as analog
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISA = 0xFF; // PORTA is input
TRISC = 0; // PORTC is output
TRISB = 0; // PORTB is output
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTB
PORTC = temp_res >> 8; // Send 2 most significant bits to RC1, RC0
} while(1);
}
HW Connection