Skip to content

Analog In Driver

Analog In driver provides access to functions used for reading the value of external voltage applied to an analog pin.

To use this library

Header: #include "drv_analog_in.h"

memake: MikroSDK.Driver

Analog In driver initializes and controls the Analog-to-Digital Converter module in the microcontroller in order to read the voltage from any analog input pin.

Initialization

In order to successfully use the Analog In driver, user must call analog_in_open() function before any other.

It is required to specify only the analog pin. Configuring other things like VREF and resolution is optional, as they are configured by the analog_in_configure_default() function.
Example initialization procedure is shown below:

analog_in_t         analog_in;
analog_in_config_t  analog_in_cfg;
uint16_t           *read_value;

analog_in_configure_default( &analog_in_cfg );
analog_in_cfg.input_pin = PA3;                     

analog_in_open( &analog_in, &analog_in_cfg );

Reading ADC value

For reading from ADC, the driver provides a function called analog_in_read().

Basic usage is demonstrated below:

uint16_t *read_value;

analog_in_read( &analog_in, &read_value );

Reference