LTlib LaurTec Library  4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
module_ADC.h File Reference
#include "LTlib.h"

Go to the source code of this file.

Macros

#define ADC_JUSTIFICATION_LEFT   0
 
#define ADC_JUSTIFICATION_RIGHT   1
 

Functions

void ADC_open (unsigned long int ADC_enable_channel)
 
void ADC_close ()
 
void ADC_select_channel (unsigned long int ADC_channel)
 
void ADC_start_conversion (void)
 
void ADC_abort_conversion (void)
 
unsigned int ADC_read_value (void)
 
unsigned int ADC_read_channel (unsigned long int ADC_channel)
 
unsigned char ADC_is_converting ()
 
void ADC_set_acquisition_time (register_size acq_time)
 
void ADC_set_clock (register_size ADC_clock)
 
void ADC_set_justification (unsigned char ADC_justification)
 
void ADC_set_reference (register_size ADC_reference_V_P, register_size ADC_reference_V_N)
 
unsigned char ADC_channel_converter (unsigned long int channel_mask)
 

Macro Definition Documentation

#define ADC_JUSTIFICATION_LEFT   0

Definition at line 56 of file module_ADC.h.

#define ADC_JUSTIFICATION_RIGHT   1

Definition at line 57 of file module_ADC.h.

Function Documentation

void ADC_abort_conversion ( void  )

This function aborts the ADC conversion that is eventually running.

Parameters
none
Returns
none

Definition at line 187 of file module_ADC.c.

References ADC_START_CONVERSION_BIT.

unsigned char ADC_channel_converter ( unsigned long int  channel_mask)

Private function that converts the channel mask to the ADC channel that will be actually converted. This function should not be used by the user. It is intended for internal use only.

Parameters
channel_maskADC channel mask.
Returns
ADC channel to be loaded within the internal register.

Definition at line 291 of file module_ADC.c.

References ADC_NUMBER_OF_CHANNELS.

void ADC_close ( )

This function disables the ADC. Disabling the ADC sets all the analog channels back to Digital.

Parameters
none
Returns
none

Definition at line 122 of file module_ADC.c.

References ADC_ENABLE_BIT, and ADC_SETTINGS_1.

unsigned char ADC_is_converting ( )

This function returns the ADC running status.

Parameters
none
Returns
results 0: Conversion is over. 1: Conversion is running.

Definition at line 207 of file module_ADC.c.

References ADC_START_CONVERSION_BIT.

void ADC_open ( unsigned long int  ADC_enable_channel)

This function enables the ADC and sets some default values.

Parameters
ADC_enable_channelOr of the channels to enable. You must use the channel numbers declared in the header file (ADC_CH0, ADC_CH1...)
Returns
none
Warning
For the ADC_MODULE_TYPE_4, openening the ADC enable all the Analog channels. This limitation is due to the ADC itself that does not allow single channel settings. To make it simple the library enables all the channels at once.

Definition at line 47 of file module_ADC.c.

References ADC_CH0, ADC_CH1, ADC_CH10, ADC_CH11, ADC_CH12, ADC_CH13, ADC_CH14, ADC_CH15, ADC_CH16, ADC_CH17, ADC_CH18, ADC_CH19, ADC_CH2, ADC_CH20, ADC_CH21, ADC_CH22, ADC_CH23, ADC_CH24, ADC_CH25, ADC_CH26, ADC_CH27, ADC_CH3, ADC_CH4, ADC_CH5, ADC_CH6, ADC_CH7, ADC_CH8, ADC_CH9, ADC_ENABLE_BIT, ADC_JUSTIFICATION_RIGHT, ADC_set_acquisition_time(), ADC_set_clock(), ADC_set_justification(), ADC_set_reference(), and ADC_SETTINGS_1.

unsigned int ADC_read_channel ( unsigned long int  ADC_channel)

This function returns the ADC conversion results merging the High and Low bytes used by the MCU as conversion buffers. The function is a stand alone function that initializes the ADC and returns the ADC conversion of the selected ADC channel. Afterward closes the ADC. Only one Channel can be selected at a time.

Parameters
ADC_channelChannel to convert. You must use the channel numbers declared in the header file (ADC_CH0, ADC_CH1...)
Returns
results Conversion result.
Warning
This function is a blocking one, waiting for the end of conversion.

Definition at line 269 of file module_ADC.c.

References ADC_close(), ADC_is_converting(), ADC_open(), ADC_read_value(), ADC_select_channel(), and ADC_start_conversion().

unsigned int ADC_read_value ( void  )

This function returns the ADC conversion results merging the High and Low bytes used by the MCU as conversion buffers. The function requires that the ADC is properly opened and configured accordingly to the application.

Parameters
none
Returns
results Conversion result.

Definition at line 195 of file module_ADC.c.

References ADC_BUFFER_HIGH, and ADC_BUFFER_LOW.

void ADC_select_channel ( unsigned long int  ADC_channel)

This function selects the ADC channel that will be converted upon the next Start of conversion. You must use the channel numbers declared in the header file (ADC_CH0, ADC_CH1...)

Parameters
ADC_channelChannel that will be converted
Returns
none

Definition at line 153 of file module_ADC.c.

References ADC_channel_converter(), and ADC_CHANNEL_SELECTION_REGISTER.

void ADC_set_acquisition_time ( register_size  acq_time)

This function sets the acquisition time as multiple of TADs. Refer to the datasheet for more information on TAD time base.

Parameters
acq_timeAcquisition time. You must use the constants ADC_ACQUISITION_TIME_xx_TAD to properly set the time. xx can be 0,2,4,6,8,12,16,20.
Returns
none

Definition at line 215 of file module_ADC.c.

References ADC_SETTINGS_2.

void ADC_set_clock ( register_size  ADC_clock)

This function sets the clock frequency used by the ADC.

Parameters
ADC_clockADC Clock. You must use the constants ADC_CLOCK_FOSC_xx to properly set the clock. xx can be 2,4,8,16,32,64,RC. xx represents the Fosc fraction at which the ADC will run.
Returns
none

Definition at line 227 of file module_ADC.c.

References ADC_SETTINGS_0, and ADC_SETTINGS_2.

void ADC_set_justification ( unsigned char  ADC_justification)

This function sets the ADC justification. Since the data is stored into 2 registers. The justification allows storing the data either starting from the left (high side) or the right (low side). Using left justification and read only the high side register is like having 8 bit conversion instead of 10 bits.

Parameters
ADC_justificationADC read buffer justification. You must use either the constant ADC_JUSTIFICATION_LEFT or ADC_JUSTIFICATION_RIGHT.
Returns
none

Definition at line 244 of file module_ADC.c.

References ADC_JUSTIFICATION.

void ADC_set_reference ( register_size  ADC_reference_V_P,
register_size  ADC_reference_V_N 
)

This function sets the ADC references for both the positive and negative one.

Parameters
ADC_reference_V_PADC Positive reference V+. You must use either the constant ADC_VREF_P_AVDD or ADC_VREF_P_EXT or ADC_VREF_P_BUF.
ADC_reference_V_NADC Positive reference V+. You must use either the constant ADC_VREF_N_AVSS or ADC_VREF_N_EXT.
Returns
none
Warning
This function does not support ADC_MODULE_TYPE_4

Definition at line 252 of file module_ADC.c.

References ADC_SETTINGS_1.

void ADC_start_conversion ( void  )

This function starts the ADC conversion.

Parameters
none
Returns
none

Definition at line 179 of file module_ADC.c.

References ADC_START_CONVERSION_BIT.