Intermediate
30 min

Create some serious ADC-DAC combo magic with AD5593R and ATmega324P

The perfect conversion pair

ADAC Click with EasyAVR v7

Published Jul 28, 2023

Click board™

ADAC Click

Dev Board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega324P

Seamlessly converts analog signals to digital, and vice versa, and delivers unparalleled precision and fidelity for a wide range of applications, from audio processing to industrial automation

A

A

Hardware Overview

How does it work?

ADAC Click is based on the AD5593R, an 8-channel 12-bit ADC, DAC, and GPIO from Analog Devices. The click is designed to run on either 3.3V or 5V power supply. ADAC click communicates with the target microcontroller over the I2C interface, with additional functionality provided by the RST pin on the mikroBUS™ line. Every channel can be set individually as ADC, DAC, or GPIO.

The 12-bit conversion values are readable through I2C. The AD5593R has eight input/output (I/O) pins, which can be independently configured as digital-to-analog converter (DAC) outputs, analog-to-digital converter (ADC) inputs, digital outputs, or digital inputs. When an I/O pin is configured as an analog output, it is driven by a 12-bit DAC. The output range of the DAC is 0 V to VREF

or 0 V to 2×V REF. When an I/O pin is configured as an analog input, it is connected to a 12-bit ADC via an analog multiplexer. The input range of the ADC is 0 V to VREF or 0 V to 2 × VREF. The I/O pins can also be configured as general-purpose, digital input, or output (GPIO).

ADAC Click hardware overview image

Features overview

Development board

EasyAVR v7 is the seventh generation of AVR development boards specially designed for the needs of rapid development of embedded applications. It supports a wide range of 16-bit AVR microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyAVR v7 allows you to connect accessory boards, sensors, and custom electronics more

efficiently than ever. Each part of the EasyAVR v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B)

connector. Communication options such as USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets which cover a wide range of 16-bit AVR MCUs. EasyAVR v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyAVR v7 horizontal image

Microcontroller Overview

MCU Card / MCU

ATmega324P

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PA6
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC0
SCL
I2C Data
PC1
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

ADAC Click Schematic schematic

Step by step

Project assembly

EasyAVR v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v7 as your development board.

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyAVR v7 Access DIP MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output via UART Mode

1. Once the code example is loaded, pressing the "FLASH" button initiates the build process, and programs it on the created setup.

2. After the programming is completed, click on the Tools icon in the upper-right panel, and select the UART Terminal.

3. After opening the UART Terminal tab, first check the baud rate setting in the Options menu (default is 115200). If this parameter is correct, activate the terminal by clicking the "CONNECT" button.

4. Now terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART_Application_Output

Software Support

Library Description

This library contains API for ADAC Click driver.

Key functions:

  • adac_write_dac - This function writes DAC using the I2C serial interface

  • adac_read_adc - This function reads ADC data using the I2C serial interface

  • adac_set_configuration - This function sets the configuration for the click module

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief ADAC Click example
 * 
 * # 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.
 * 
 * ## 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.  
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "adac.h"

// ------------------------------------------------------------------ VARIABLES

static adac_t adac;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( )
{
    log_cfg_t log_cfg;
    adac_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    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_ms( 100 );
    adac_hardware_reset( &adac );
    Delay_ms( 100 );
    adac_set_configuration( &adac, ADAC_POWER_REF_CTRL, ADAC_VREF_ON, ADAC_NO_OP );
    Delay_ms( 100 );
    log_printf( &logger, "\r\n Click module initialized \r\n" );
    Delay_ms( 500 );
}

void application_task ( )
{
    uint16_t adc_val;
    uint16_t cnt;
    uint8_t chan;

    log_printf( &logger, "\r\n *** DAC : write ***\r\n" );
    adac_set_configuration( &adac, ADAC_DAC_CONFIG, ADAC_NO_OP, ADAC_IO3 );
    Delay_ms( 100 );

    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" );
    adac_set_configuration( &adac, ADAC_ADC_CONFIG, ADAC_NO_OP, ADAC_IO4 );
    Delay_ms( 100 );
    adac_set_configuration( &adac, ADAC_ADC_SEQUENCE, ADAC_SEQUENCE_ON, ADAC_IO4 );

    for( cnt = 0; cnt < 10; cnt++ )
    {
        adc_val = adac_read_adc( &adac, &chan );
        log_printf( &logger, "   channel : %d\r\n", ( uint16_t ) chan );
        log_printf( &logger, "       val : %d\r\n", adc_val ); 
        Delay_ms( 2000 );
    }

    log_printf( &logger, "-------------------\r\n" );
    Delay_ms( 1000 );
}

void main ( )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.