User manual

272
mikoC PRO for dsPIC
MikroElektronika
ADCx_Get_Sample
Prototype
unsigned ADCx_Get_Sample(unsigned channel);
Description The function enables ADC module and reads the specied analog channel input.
Parameters - channel represents the channel from which the analog value is to be acquired.
Returns 10-bit or 12-bit (depending on selected mode by ADCx_Init_Advanced or MCU) unsigned value
from the specied 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.
- ADC library routines require you to specify the module you want to use. To select the desired ADC
module, simply change the letter x in the routine prototype for a number from 1 to 2.
- Before using the function, be sure to congure the appropriate TRISx bits to designate pins as
inputs.
Example
unsigned adc_value;
...
adc_value = ADC1_Get_Sample(10); // read analog value from ADC1 module
channel 10
Notes - Number of ADC modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.
- 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.
ADCx_Read
Prototype
unsigned ADCx_Read(unsigned channel);
Description The function initializes, enables ADC module and reads the specied analog channel input.
Parameters - channel represents the channel from which the analog value is to be acquired.
Returns 10-bit or 12-bit (depending on the MCU) unsigned value from the specied channel.
Requires - The MCU with built-in ADC module.
- ADC library routines require you to specify the module you want to use. To select the desired ADC
module, simply change the letter x in the routine prototype for a number from 1 to 2.
- Number of ADC modules per MCU differs from chip to chip. Please, read the appropriate datasheet
before utilizing this library.
- Before using the function, be sure to congure 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.