ADC Library
ADC (Analog to Digital Converter) module is available with a number of PIC32 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
ADCx_Init
| Prototype |
void ADCx_Init();
|
| Description |
This routines configures ADC module to work with default settings.
The internal ADC module is set to:
- single channel conversion
- 10-bit conversion resolution
- unsigned integer data format
- auto-convert
- VRef+ : AVdd, VRef- : AVss
- instruction cycle clock
- conversion clock : 32*Tcy
- auto-sample time : 31TAD
|
| Parameters |
None.
|
| Returns |
Nothing.
|
| Requires |
- MCU with built-in ADC module.
|
| Example |
ADC1_Init(); // Initialize ADC module with default settings
|
| Notes |
None.
|
ADCx_Init_Advanced
| Prototype |
void ADC1_Init_Advanced(unsigned Reference);
|
| Description |
This routine configures the internal ADC module to work with user defined settings.
|
| Parameters |
Reference: voltage reference used in ADC process.
| Description |
Predefined library const |
| Voltage reference: |
Internal voltage reference |
_ADC_INTERNAL_REF |
External voltage reference |
_ADC_EXTERNAL_REF |
Internal positive voltage reference, external negative voltage reference |
_ADC_VREFH_INTERNAL_VREFL_EXTERNAL |
External positive voltage reference, internal negative voltage reference |
_ADC_VREFH_EXTERNAL_VREFL_INTERNAL |
|
| Returns |
Nothing.
|
| Requires |
- The MCU with built-in ADC module.
|
| Example |
ADC1_Init_Advanced(_ADC_INTERNAL_REF); // set internal reference used
|
| Notes |
- Not all MCUs support advanced configuration. Please, read the appropriate datasheet before utilizing this library.
|
ADCx_Get_Sample
| Prototype |
unsigned ADCx_Get_Sample(unsigned channel);
|
| Description |
The function enables ADC module and reads the specified analog channel input.
|
| Parameters |
channel represents the channel from which the analog value is to be acquired.
|
| Returns |
10-bit unsigned value from the specified channel.
|
| Requires |
- The MCU with built-in ADC module.
- Prior to using this routine, ADC module needs to be initialized. See ADCx_Init and ADCx_Init_Advanced.
- Before using the function, be sure to configure the appropriate TRISx bits to designate pins as inputs.
|
| Example |
unsigned adc_value;
...
adc_value = ADC1_Get_Sample(10); // read analog value from ADC module channel 10
|
| Notes |
- The function sets the appropriate bit in the AD1PCFG registers to enable analog function of the chosen pin.
- Refer to the appropriate Datasheet for channel-to-pin mapping.
|
ADCx_Read
| Prototype |
unsigned ADCx_Read(unsigned channel);
|
| Description |
The function initializes, enables ADC module and reads the specified analog channel input.
|
| Parameters |
channel represents the channel from which the analog value is to be acquired.
|
| Returns |
10-bit unsigned value from the specified channel.
|
| 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 adc_value;
...
adc_value = ADC1_Read(10); // read analog value from ADC1 module channel 10
|
| Notes |
- This is a standalone routine, so there is no need for a previous initialization of ADC module.
- The function sets the appropriate bit in the ADPCFG registers to enable analog function of the chosen pin.
- Refer to the appropriate Datasheet for channel-to-pin mapping.
|
Copyright (c) 2002-2017 mikroElektronika. All rights reserved.
What do you think about this topic ?
Send us feedback!
Want more examples and libraries?
Find them on