adac  2.0.0.0
Main Page

ADAC click

The click is designed to run on either 3.3V or 5V power supply. ADAC click communicates with the target microcontroller over I2C interface, with additional functionality provided by the RST pin on the mikroBUS™ line.

click Product page


Click library

  • Author : MikroE Team
  • Date : Jun 2020.
  • Type : I2C type

Software Support

We provide a library for the ADAC 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 form compilers IDE(recommended way), or downloaded from our LibStock, or found on mikroE github account.

Library Description

This library contains API for ADAC Click driver.

Standard key functions :

  • Config Object Initialization function.

    void adac_cfg_setup ( adac_cfg_t *cfg );

  • Initialization function.

    ADAC_RETVAL adac_init ( adac_t *ctx, adac_cfg_t *cfg );

  • Click Default Configuration function.

    void adac_default_cfg ( adac_t *ctx );

Example key functions :

  • This function writes DAC using the I2C serial interface.

    void adac_write_dac ( adac_t *ctx, uint8_t chan, uint8_t msb, uint8_t lsb );

  • This function reads ADC data using the I2C serial interface.

    uint16_t adac_read_adc( adac_t *ctx, uint8_t *chan );

  • This function sets the configuration for the click module.

    void adac_set_configuration ( adac_t *ctx, uint8_t ptr, uint8_t msb, uint8_t lsb );

Examples Description

This example showcases how to initialize, configure and use the ADAC click module. The click

has an ADC and a DAC. An external power supply sets the maximum voltage of the input analog signal, which is bound to 2.5 V by default. For the input any external analog signal will suffice and a multimeter is needed to read the output on one of the channels.

The demo application is composed of two sections :

Application Init

This function initializes and configures the click and logger modules. It does a hardware

reset first and after that configures the click module using default settings.

void application_init ( void )
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, "---- Application Init ----" );
// Click initialization.
adac_cfg_setup( &cfg );
ADAC_MAP_MIKROBUS( cfg, MIKROBUS_1 );
adac_init( &adac, &cfg );
Delay_100ms( );
Delay_100ms( );
Delay_100ms( );
log_printf( &logger, "\r\n Click module initialized \r\n" );
Delay_ms( 500 );
}

Application Task

This function first writes digital values ranging from 0 to 256 to output channel 3 with a

10 millisecond delay between iterations and after that reads analog values from channel 4 10 times and displays results in the UART console.

void application_task ( void )
{
uint16_t adc_val;
uint16_t cnt;
uint8_t chan;
log_printf( &logger, "\r\n *** DAC : write ***\r\n" );
Delay_100ms( );
for ( cnt = 0; cnt < 0xFF; cnt +=4 )
{
adac_write_dac( &adac, ADAC_PB_PIN3, cnt / 0x100, cnt % 0x100 );
Delay_ms( 10 );
log_printf( &logger, " > write... \r\n" );
}
log_printf( &logger, "-------------------\r\n" );
Delay_ms( 1000 );
log_printf( &logger, "\r\n *** ADC : read ***\r\n" );
Delay_100ms( );
for( cnt = 0; cnt < 10; cnt++ )
{
adc_val = adac_read_adc( &adac, &chan );
log_printf( &logger, " channel : %d\r\n", chan );
log_printf( &logger, " val : %d\r\n", adc_val );
Delay_ms( 2000 );
}
log_printf( &logger, "-------------------\r\n" );
Delay_ms( 1000 );
}

The full application code, and ready to use projects can be installed directly form compilers IDE(recommneded) or found on LibStock page or mikroE GitHub accaunt.

Other mikroE Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.ADAC

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. The terminal available in all Mikroelektronika compilers, or any other terminal application of your choice, can be used to read the message.


application_init
void application_init()
Definition: main.c:38
ADAC_IO4
#define ADAC_IO4
Definition: adac.h:117
adac_hardware_reset
void adac_hardware_reset(adac_t *ctx)
Hardware reset function.
adac_write_dac
void adac_write_dac(adac_t *ctx, uint8_t chan, uint8_t msb, uint8_t lsb)
Write DAC function.
ADAC_PB_PIN3
#define ADAC_PB_PIN3
Definition: adac.h:130
ADAC_POWER_REF_CTRL
#define ADAC_POWER_REF_CTRL
Definition: adac.h:83
adac_set_configuration
void adac_set_configuration(adac_t *ctx, uint8_t ptr, uint8_t msb, uint8_t lsb)
Set configuration function.
adac_init
ADAC_RETVAL adac_init(adac_t *ctx, adac_cfg_t *cfg)
Initialization function.
ADAC_ADC_SEQUENCE
#define ADAC_ADC_SEQUENCE
Definition: adac.h:74
adac_cfg_setup
void adac_cfg_setup(adac_cfg_t *cfg)
Config Object Initialization function.
application_task
void application_task()
Definition: main.c:70
adac_cfg_t
Click configuration structure definition.
Definition: adac.h:209
adac_read_adc
uint16_t adac_read_adc(adac_t *ctx, uint8_t *chan)
Read ADC function.
ADAC_MAP_MIKROBUS
#define ADAC_MAP_MIKROBUS(cfg, mikrobus)
Definition: adac.h:51
ADAC_IO3
#define ADAC_IO3
Definition: adac.h:116
ADAC_NO_OP
#define ADAC_NO_OP
Definition: adac.h:73
ADAC_ADC_CONFIG
#define ADAC_ADC_CONFIG
Definition: adac.h:76
ADAC_VREF_ON
#define ADAC_VREF_ON
Definition: adac.h:105
ADAC_SEQUENCE_ON
#define ADAC_SEQUENCE_ON
Definition: adac.h:106
ADAC_DAC_CONFIG
#define ADAC_DAC_CONFIG
Definition: adac.h:77