dac16  2.1.0.0
Main Page

DAC 16 Click

DAC 16 Click is a compact add-on board, a digital-to-analog converter (DAC) designed for precise voltage and current output applications. This board features the DAC63204-Q1, an automotive-qualified 12-bit DAC from Texas Instruments. This Click board™ features four output channels with flexible configuration options, including adjustable voltage gains and selectable current ranges from ±25μA to ±250μA. It also supports both internal and external voltage references and offers a Hi-Z power-down mode for enhanced protection. Communication with the host MCU is enabled through either a 4-wire SPI or I2C interface, with configurable I2C addresses and a general-purpose I/O pin for additional functionality.

Click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Apr 2024.
  • Type : I2C/SPI type

Software Support

We provide a library for the DAC 16 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 DAC 16 Click driver.

Standard key functions :

Example key functions :

  • dac16_set_dac_data This function sets the raw DAC data for the selected DAC channel.
    err_t dac16_set_dac_data ( dac16_t *ctx, uint8_t dac, uint16_t dac_data );
  • dac16_start_function_gen This function starts the function generator for the selected DAC channel.
    err_t dac16_start_function_gen ( dac16_t *ctx, uint8_t dac );
  • dac16_stop_function_gen This function stops the function generator for the selected DAC channel.
    err_t dac16_stop_function_gen ( dac16_t *ctx, uint8_t dac );

Example Description

This example demonstrates the use of DAC 16 Click board by changing the voltage level

on the OUT0 as well as the waveform signals from a function generator on the OUT1.

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;
dac16_cfg_t dac16_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
dac16_cfg_setup( &dac16_cfg );
DAC16_MAP_MIKROBUS( dac16_cfg, MIKROBUS_1 );
err_t init_flag = dac16_init( &dac16, &dac16_cfg );
if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( DAC16_ERROR == dac16_default_cfg ( &dac16 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}

Application Task

Changes the voltage level on the OUT0 as well as the waveform signals from a function

generator on the OUT1 every 3 seconds. The state of all outputs will be displayed on the USB UART.

void application_task ( void )
{
static uint16_t dac = 0;
static uint8_t waveform = DAC16_WAVEFORM_TRIANGULAR;
if ( DAC16_OK == dac16_set_dac_data ( &dac16, DAC16_SEL_DAC_0, dac ) )
{
log_printf( &logger, "\r\n OUT0: %u -> %.2f V\r\n",
dac, ( float ) dac * DAC16_VDD_3V3 / DAC16_DAC_DATA_MAX );
dac += 100;
if ( dac > DAC16_DAC_DATA_MAX )
{
}
}
err_t error_flag = dac16_stop_function_gen ( &dac16, DAC16_SEL_DAC_1 );
error_flag |= dac16_config_function_gen ( &dac16, DAC16_SEL_DAC_1, waveform,
error_flag |= dac16_start_function_gen ( &dac16, DAC16_SEL_DAC_1 );
if ( DAC16_OK == error_flag )
{
log_printf( &logger, " OUT1: " );
switch ( waveform )
{
{
log_printf( &logger, "triangular wave at about 1kHz\r\n" );
break;
}
{
log_printf( &logger, "sawtooth wave at about 2kHz\r\n" );
break;
}
{
log_printf( &logger, "inverse sawtooth wave at about 2kHz\r\n" );
waveform = DAC16_WAVEFORM_SINE;
break;
}
{
log_printf( &logger, "sine wave at about 10.5kHz\r\n" );
break;
}
{
log_printf( &logger, "function generator disabled\r\n" );
break;
}
default:
{
log_printf( &logger, "unknown state\r\n" );
break;
}
}
// OUT2 and OUT3 are set in dac16_default_cfg
log_printf( &logger, " OUT2: sine wave at about 10.5kHz\r\n" );
log_printf( &logger, " OUT3: sawtooth wave at about 2kHz\r\n" );
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
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.DAC16

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.


dac16_config_function_gen
err_t dac16_config_function_gen(dac16_t *ctx, uint8_t dac, uint8_t waveform, uint8_t code_step, uint8_t slew_rate)
DAC 16 config function gen function.
DAC16_DAC_DATA_MIN
#define DAC16_DAC_DATA_MIN
Definition: dac16.h:276
dac16_init
err_t dac16_init(dac16_t *ctx, dac16_cfg_t *cfg)
DAC 16 initialization function.
dac16_cfg_t
DAC 16 Click configuration object.
Definition: dac16.h:457
DAC16_WAVEFORM_SINE
#define DAC16_WAVEFORM_SINE
Definition: dac16.h:310
DAC16_VDD_3V3
#define DAC16_VDD_3V3
DAC 16 DAC VDD setting.
Definition: dac16.h:362
DAC16_SEL_DAC_0
#define DAC16_SEL_DAC_0
DAC 16 DAC selection setting.
Definition: dac16.h:289
dac16_set_dac_data
err_t dac16_set_dac_data(dac16_t *ctx, uint8_t dac, uint16_t dac_data)
DAC 16 set dac data function.
DAC16_WAVEFORM_SAWTOOTH
#define DAC16_WAVEFORM_SAWTOOTH
Definition: dac16.h:308
DAC16_WAVEFORM_INV_SAWTOOTH
#define DAC16_WAVEFORM_INV_SAWTOOTH
Definition: dac16.h:309
application_task
void application_task(void)
Definition: main.c:67
DAC16_ERROR
@ DAC16_ERROR
Definition: dac16.h:484
DAC16_SLEW_RATE_4_US
#define DAC16_SLEW_RATE_4_US
Definition: dac16.h:331
DAC16_OK
@ DAC16_OK
Definition: dac16.h:483
DAC16_CODE_STEP_32_LSB
#define DAC16_CODE_STEP_32_LSB
Definition: dac16.h:324
dac16_cfg_setup
void dac16_cfg_setup(dac16_cfg_t *cfg)
DAC 16 configuration object setup function.
DAC16_DAC_DATA_MAX
#define DAC16_DAC_DATA_MAX
DAC 16 DAC setting.
Definition: dac16.h:275
dac16_default_cfg
err_t dac16_default_cfg(dac16_t *ctx)
DAC 16 default configuration function.
DAC16_WAVEFORM_DISABLE
#define DAC16_WAVEFORM_DISABLE
Definition: dac16.h:311
dac16_start_function_gen
err_t dac16_start_function_gen(dac16_t *ctx, uint8_t dac)
DAC 16 start function gen function.
dac16_stop_function_gen
err_t dac16_stop_function_gen(dac16_t *ctx, uint8_t dac)
DAC 16 stop function gen function.
application_init
void application_init(void)
Definition: main.c:30
dac16_s
DAC 16 Click context object.
Definition: dac16.h:437
DAC16_SEL_DAC_1
#define DAC16_SEL_DAC_1
Definition: dac16.h:290
DAC16_MAP_MIKROBUS
#define DAC16_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: dac16.h:402
DAC16_WAVEFORM_TRIANGULAR
#define DAC16_WAVEFORM_TRIANGULAR
DAC 16 DAC waveform setting.
Definition: dac16.h:307