adc20  2.1.0.0
Main Page

ADC 20 click

ADC 20 Click is a compact add-on board with a high-performance data converter. This board features the TLA2518, an SPI-configurable eight-channel 12-bit successive approximation register analog-to-digital converter (SAR ADC) from Texas Instruments. The TLA2518 has an internal oscillator for the ADC conversion and supports averaging multiple data samples with a single conversion start. Also, the built-in programmable averaging filters help reduce noise from the analog inputs and reduce the number of data samples required to be read by the host MCU. All eight channels can be used as analog inputs, with the addition that the four channels can be used as digital inputs or digital outputs.

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Oct 2022.
  • Type : SPI type

Software Support

We provide a library for the ADC 20 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for ADC 20 Click driver.

Standard key functions :

Example key functions :

  • adc20_read_data This function reads two bytes of data by using SPI serial interface.
    err_t adc20_read_data ( adc20_t *ctx, uint16_t *data_out );
  • adc20_set_gpo_value This function sets the gpo value for the selected channels.
    err_t adc20_set_gpo_value ( adc20_t *ctx, uint8_t ch_mask, uint8_t value );
  • adc20_read_gpio_value This function reads the gpio pins value.
    err_t adc20_read_gpio_value ( adc20_t *ctx, uint8_t *gpio_value );

Example Description

This example demonstrates the use of ADC 20 click board by displaying the state of 8 channels

configured as analog inputs (CH2-CH5), digital inputs (CH0-CH1) and digital outputs (CH6-CH7).

The demo application is composed of two sections :

Application Init

Initializes the driver and performs the click default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
adc20_cfg_t adc20_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
adc20_cfg_setup( &adc20_cfg );
ADC20_MAP_MIKROBUS( adc20_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == adc20_init( &adc20, &adc20_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( ADC20_ERROR == adc20_default_cfg ( &adc20 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Starts the auto sequence mode, reads the 12bit ADC value from analog input channels (CH2-CH5) and

displays the values converted to voltage on the USB UART. After that, stops auto sequence mode and toggles the state of digital output pins (CH6-CH7), then reads and displays the state of all GPIO pins.

void application_task ( void )
{
for ( uint8_t ch_id = ADC20_CHANNEL_ID_2; ch_id <= ADC20_CHANNEL_ID_5; ch_id++ )
{
uint16_t adc_data = 0;
if ( ADC20_OK == adc20_read_data ( &adc20, &adc_data ) )
{
float voltage = ( float ) ( adc_data >> ADC20_ADC_OFFSET ) / ADC20_RES_12BIT * ADC20_VREF_3V3;
log_printf ( &logger, " AIN%u: %.2f V\r\n", ( adc_data & ADC20_CHANNEL_ID_MASK ), voltage );
}
}
static uint8_t out_logic_state = ADC20_GPIO_VALUE_LOW;
if ( ADC20_OK == adc20_set_gpo_value ( &adc20, ( ADC20_CHANNEL_6 | ADC20_CHANNEL_7 ), out_logic_state ) )
{
uint8_t gpio_value = 0;
if ( ADC20_OK == adc20_read_gpio_value ( &adc20, &gpio_value ) )
{
log_printf ( &logger, " GPIO state: 0x%.2X\r\n", gpio_value );
}
}
out_logic_state = !out_logic_state;
log_printf ( &logger, "\r\n" );
Delay_ms ( 1000 );
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.ADC20

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


adc20_t
ADC 20 Click context object.
Definition: adc20.h:245
ADC20_CHANNEL_ID_2
#define ADC20_CHANNEL_ID_2
Definition: adc20.h:135
adc20_default_cfg
err_t adc20_default_cfg(adc20_t *ctx)
ADC 20 default configuration function.
adc20_read_data
err_t adc20_read_data(adc20_t *ctx, uint16_t *data_out)
ADC 20 read data function.
ADC20_MAP_MIKROBUS
#define ADC20_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: adc20.h:231
ADC20_CHANNEL_ID_MASK
#define ADC20_CHANNEL_ID_MASK
Definition: adc20.h:141
adc20_stop_auto_sequence
err_t adc20_stop_auto_sequence(adc20_t *ctx)
ADC 20 stop auto sequence function.
ADC20_CHANNEL_7
#define ADC20_CHANNEL_7
Definition: adc20.h:125
application_task
void application_task(void)
Definition: main.c:66
adc20_cfg_t
ADC 20 Click configuration object.
Definition: adc20.h:258
ADC20_ERROR
@ ADC20_ERROR
Definition: adc20.h:279
ADC20_RES_12BIT
#define ADC20_RES_12BIT
Definition: adc20.h:201
adc20_cfg_setup
void adc20_cfg_setup(adc20_cfg_t *cfg)
ADC 20 configuration object setup function.
adc20_read_gpio_value
err_t adc20_read_gpio_value(adc20_t *ctx, uint8_t *gpio_value)
ADC 20 read gpio value function.
ADC20_GPIO_VALUE_LOW
#define ADC20_GPIO_VALUE_LOW
ADC 20 GPIO value settings.
Definition: adc20.h:168
application_init
void application_init(void)
Definition: main.c:30
ADC20_ADC_OFFSET
#define ADC20_ADC_OFFSET
ADC 20 ADC setting.
Definition: adc20.h:200
ADC20_VREF_3V3
#define ADC20_VREF_3V3
Definition: adc20.h:202
ADC20_OK
@ ADC20_OK
Definition: adc20.h:278
ADC20_CHANNEL_ID_5
#define ADC20_CHANNEL_ID_5
Definition: adc20.h:138
adc20_start_auto_sequence
err_t adc20_start_auto_sequence(adc20_t *ctx)
ADC 20 start auto sequence function.
adc20_set_gpo_value
err_t adc20_set_gpo_value(adc20_t *ctx, uint8_t ch_mask, uint8_t value)
ADC 20 set gpo value function.
ADC20_CHANNEL_6
#define ADC20_CHANNEL_6
Definition: adc20.h:124
adc20_init
err_t adc20_init(adc20_t *ctx, adc20_cfg_t *cfg)
ADC 20 initialization function.