ADC Library
ADC (Analog to Digital Converter) module is available with a number of 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 |
void ADC_Init(); |
---|---|
Description |
This routines configures ADC module. The internal ADC module is set to:
|
Parameters |
None. |
Returns |
Nothing. |
Requires |
|
Example |
ADC_Init(); // Initialize ADC module with default settings |
Notes |
None. |
ADC_Init_Advanced
Prototype |
void ADC_Init_Advanced(unsigned short mode); |
||||||
---|---|---|---|---|---|---|---|
Description |
This routine configures the internal ADC module to work with user defined settings. |
||||||
Parameters |
|
||||||
Returns |
Nothing. |
||||||
Requires |
|
||||||
Example |
ADC_Init_Advanced(_ADC_MODE_CONTINUOUS); // set continuous conversion mode |
||||||
Notes |
None. |
ADC_Set_Input_Channel
Prototype |
void ADC_Set_Input_Channel(unsigned input_mask); |
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
The function sets appropriate ADC channel as an analog input. |
||||||||||||||||||
Parameters |
|
||||||||||||||||||
Returns |
Nothing. |
||||||||||||||||||
Requires |
|
||||||||||||||||||
Example |
// sets ADC channels 0 and 1 as analog inputs ADC_Set_Input_Channel(_ADC_CHANNEL_0 | _ADC_CHANNEL_1); |
||||||||||||||||||
Notes |
|
ADC_Get_Sample
Prototype |
unsigned int ADC_Get_Sample(unsigned channel); |
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
The function enables ADC module and reads the specified analog channel input. |
||||||||||||||||||
Parameters |
|
||||||||||||||||||
Returns |
ADC value from the specified |
||||||||||||||||||
Requires |
|
||||||||||||||||||
Example |
unsigned adc_value; ... ADC_Set_Input_Channel(_ADC_CHANNEL_1); // Set ADC channel 1 as an analog input ADC_Init(); // Initialize ADC module adc_value = ADC_Get_Sample(_ADC_CHANNEL_1); // read analog value from ADC module channel 1 |
||||||||||||||||||
Notes |
|
ADC_Read
Prototype |
unsigned int ADC_Read(unsigned char channel); |
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
The function sets appropriate ADC channel as an analog input, enables ADC module, initializes ADC module and reads from the specified analog channel input. |
||||||||||||||||||
Parameters |
|
||||||||||||||||||
Returns |
ADC value from the specified |
||||||||||||||||||
Requires |
|
||||||||||||||||||
Example |
unsigned adc_value; ... adc_value = ADC_Read(_ADC_CHANNEL_1); // read analog value from ADC module channel 1 |
||||||||||||||||||
Notes |
|
What do you think about this topic ? Send us feedback!