mikroSDK Reference Manual

ADC Hardware Abstraction Layer API Reference. More...

Functions list

void hal_adc_configure_default (hal_adc_config_t *config)
 Configure ADC HAL configuration structure.. More...
 
err_t hal_adc_open (handle_t *handle, bool hal_obj_open_state)
 Open the ADC HAL layer object on selected pin. More...
 
err_t hal_adc_set_resolution (handle_t *handle, hal_adc_config_t *config)
 Set ADC HAL sample resolution. More...
 
err_t hal_adc_set_vref_input (handle_t *handle, hal_adc_config_t *config)
 Set ADC HAL reference voltage source to desired value. More...
 
void hal_adc_set_vref_value (handle_t *handle, hal_adc_config_t *config)
 Set ADC HAL reference voltage value to desired value. More...
 
err_t hal_adc_read (handle_t *handle, uint16_t *readDatabuf)
 Read analog value on pin. More...
 
err_t hal_adc_read_voltage (handle_t *handle, float *readDatabuf)
 Read analog voltage value on pin. More...
 
err_t hal_adc_close (handle_t *handle)
 Close ADC HAL layer object. More...
 

Detailed Description

API for configuring and manipulating ADC HAL module.

Function Documentation

◆ hal_adc_configure_default()

void hal_adc_configure_default ( hal_adc_config_t config)

Configures ADC configuration structure to default initialization values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.

Parameters
[in,out]configADC HAL layer configuration settings. See hal_adc_config_t structure definition for detailed explanation.

Default values:

Function Default value
Input pin HAL_PIN_NC (invalid pin)
Resolution 12 bit
Vref input External voltage reference source
Vref value -1 (invalid reference voltage value)
Returns
Nothing.

Example

// ADC HAL configuration structure
static hal_adc_config_t hal_adc_cfg;
// Fill structure with default values
hal_adc_configure_default( &hal_adc_cfg );

◆ hal_adc_open()

err_t hal_adc_open ( handle_t *  handle,
bool  hal_obj_open_state 
)

Function allocates memory needed for ADC HAL and pin for specified object.

Parameters
[in,out]handleADC handle.
[in]hal_obj_open_stateADC state, is it open or not.
Returns
The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.

Example

// ADC HAL context structure
static hal_adc_t hal_adc;
// ADC HAL configuration structure
static hal_adc_config_t hal_adc_cfg;
// Fill structure with default values.
adc_configure_default(&hal_adc_cfg);
// Specify desired ADC pin.
hal_adc_cfg.pin. = MIKROBUS_1_AN;
// Allocate resources for ADC HAL.
hal_adc_open( &hal_adc->handle, true );

◆ hal_adc_set_resolution()

err_t hal_adc_set_resolution ( handle_t *  handle,
hal_adc_config_t config 
)

Initializes ADC HAL on the hardware level and sets sample resolution to specified config->resolution value.

Parameters
[in]handleADC handle.
[in]configADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation.
Returns
The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
Precondition
Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
Warning
If desired resolution can not be achieved, error will be returned. Make sure to poll the return value in your code.

Example

// Set resolution
hal_adc_set_resolution( &hal_adc->handle, &hal_adc->config );

◆ hal_adc_set_vref_input()

err_t hal_adc_set_vref_input ( handle_t *  handle,
hal_adc_config_t config 
)

Initializes ADC HAL on the hardware level and sets sample reference voltage source to specified config->vref_input value.

Parameters
[in]handleADC handle.
[in]configADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation.
Returns
The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
Precondition
Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
Warning
If desired reference voltage source can not be achieved, error will be returned. Make sure to poll the return value in your code.

Example

// Set voltage reference source
hal_adc_set_vref_input( &hal_adc->handle, &hal_adc->config );

◆ hal_adc_set_vref_value()

void hal_adc_set_vref_value ( handle_t *  handle,
hal_adc_config_t config 
)

Sets sample reference voltage value to specified config->vref_value value used later for calculating voltage.

Parameters
[in]handleADC handle.
[in]configADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation.
Returns
Nothing.
Precondition
Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
Warning
If desired reference voltage value is not set, calculated voltage value on AN pin will be wrong.

Example

// Set voltage reference value
hal_adc_set_vref_value( &hal_adc->handle, &hal_adc->config );

◆ hal_adc_read()

err_t hal_adc_read ( handle_t *  handle,
uint16_t *  readDatabuf 
)
Parameters
[in]handleADC handle.
[out]readDatabufData buffer to place read data in.
Returns
The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
Precondition
Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.

Example

hal_adc_read( &hal_adc->handle, readDatabuf );

◆ hal_adc_read_voltage()

err_t hal_adc_read_voltage ( handle_t *  handle,
float *  readDatabuf 
)
Parameters
[in]handleADC handle.
[out]readDatabufData buffer to place read data in.
Returns
The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
Precondition
Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.

Example

hal_adc_read_voltage( &hal_adc->handle, readDatabuf );

◆ hal_adc_close()

err_t hal_adc_close ( handle_t *  handle)

Closes ADC HAL layer object, clears all buffers used by object and clears config.

Parameters
[in,out]handleADC handle.
Returns
Nothing.

Example

// Close the ADC HAL object handler.
hal_adc_close( &hal_adc->handle );
hal_adc_open
err_t hal_adc_open(handle_t *handle, bool hal_obj_open_state)
Open the ADC HAL layer object on selected pin.
hal_adc_read_voltage
err_t hal_adc_read_voltage(handle_t *handle, float *readDatabuf)
Read analog voltage value on pin.
hal_adc_set_vref_value
void hal_adc_set_vref_value(handle_t *handle, hal_adc_config_t *config)
Set ADC HAL reference voltage value to desired value.
hal_adc_read
err_t hal_adc_read(handle_t *handle, uint16_t *readDatabuf)
Read analog value on pin.
hal_adc_config_t
ADC HAL initialization configuration structure, consisted of the following fields :
Definition: hal_adc.h:131
hal_adc_t::handle
handle_t handle
Definition: hal_adc.h:151
hal_adc_configure_default
void hal_adc_configure_default(hal_adc_config_t *config)
Configure ADC HAL configuration structure..
hal_adc_config_t::pin
hal_pin_name_t pin
Definition: hal_adc.h:133
hal_adc_close
err_t hal_adc_close(handle_t *handle)
Close ADC HAL layer object.
hal_adc_set_vref_input
err_t hal_adc_set_vref_input(handle_t *handle, hal_adc_config_t *config)
Set ADC HAL reference voltage source to desired value.
hal_adc_set_resolution
err_t hal_adc_set_resolution(handle_t *handle, hal_adc_config_t *config)
Set ADC HAL sample resolution.
hal_adc_t
ADC HAL context structure, consisted of the following fields :
Definition: hal_adc.h:149
hal_adc_t::config
hal_adc_config_t config
Definition: hal_adc.h:152