Intermediate
30 min

Enhance your system performance with AD74412R and ATmega328

Compact yet powerful

AD-SWIO Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

AD-SWIO Click

Dev.Board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328

The game-changer for applications demanding simultaneous ADC and DAC functionality

A

A

Hardware Overview

How does it work?

AD-SWIO Click is based on AD74412R, a 16-bit analog-to-digital converter (ADC), and a 13-bit digital-to-analog converter (DAC) from Analog Devices. There are several modes related to the AD74412R. These modes are voltage output, current output, voltage input, externally powered current input, loop-powered current input, external RTD measurement, digital input logic, and loop-powered digital input. The ADC can measure the voltage across the 100Ω RSENSE or at each channel's I/OP_x screw terminal. In high impedance mode, the ADC, by default, measures the voltage across the screw terminals (I/OP_x to I/ON_x) in a 0V to 10V range. The ADC also provides diagnostic information on user-selectable inputs such as supplies, internal die temperature, reference, and regulators. The AD-SWIO Click has four GPO-x pins, one per channel (GPO-A, GPO-B, GPO-C, GPO-D). 

Each channel GPO-x pin can be configured to the logic outputs of the digital input functions or a logic high or low output. The GPO-x pins can be set via the GPO_SELECT bits within the GPO_CONFIGx registers. The Click board™ also contains an LVIN ( Low Voltage Input) pin, the measurement voltage range on this pin is 0V to 2.5V. The AD74412R has four 13-bit DACs, one per channel. Each DAC core is a 13-bit string DAC. The architecture structure consists of a string of resistors, each with a value of R. The digital input code loaded to the DAC_CODEx registers determines which string node the voltage is tapped off from and fed into the output amplifier. This architecture is inherently monotonic and linear. The AD74412R has short-circuited limit in voltage output mode that is programmable per channel. The circuit minimizes glitching on the I/OP_x screw terminal when the AVDD

supply is ramping, or the use case configuration is changed. This short-circuit limit you can regulate with a positive analog supply on the AVDD pin, Output voltage on AD-SWIO 2 Click is limited to +20V. The AD-SWIO 2 Click is equipped with the ADP1613 step-up dc-to-dc switching converter from Analog Devices with an integrated power switch capable of providing an output voltage as high as 20V. This Click board™ can only be operated with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board™ comes equipped with a library containing functions and an example code that can be used as a reference for further development.

ad-swio-click-hardware-overview

Features overview

Development board

Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an

ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the

first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

32

RAM (Bytes)

2048

You complete me!

Accessories

Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino UNO accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PD2
RST
SPI Chip Select
PB2
CS
SPI Clock
PB5
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Alert Status
PD6
PWM
Data Ready
PC3
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

AD-SWIO Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Arduino UNO Rev3 Access 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 image step 5 hardware assembly
Necto image step 6 hardware assembly
Arduino UNO MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for AD-SWIO Click driver.

Key functions:

  • adswio_status_pin_ready - This function checks the status of the ready pin.

  • adswio_get_conv_results - This function allows user to get the converted results of the selected channel.

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 AdSwio Click example
 * 
 * # Description
 * This click provides a fully integrated single chip solution for input and output operation. 
 * The AD-SWIO Click contains four 13-bit DACs, one per chanal, and 16-bit Σ-∆ ADC. 
 * These options give a lot of flexibility in choosing functionality for analog output, 
 * analog input, digital input, resistance temperature detector (RTD), and thermocouple 
 * measurements integrated into a single chip solution with a serial peripheral interface (SPI).
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Performs a hardware reset of the click board and
 * executes a default configuration that enables channel A and sets it to measure voltage
 * input in the range from 0V to 10V, with 4800 SPS.
 * 
 * ## Application Task  
 * Waits for the data ready and then reads the results of ADC conversion from channel A
 * and if response is ok, then prints the results on the uart console.
 * 
 * ## Additional Functions
 *
 * - void application_default_handler ( uint8_t *err_msg ) - Sends an error report messages from click
 * driver to initialized console module. It must be set using adswio2_set_handler function.
 *
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "adswio.h"

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

static adswio_t adswio;
static log_t logger;

static uint8_t adswio_rdy;
static adswio_err_t adswio_err;
static uint16_t adswio_ch_a;
static float adswio_res;

const uint16_t ADSWIO_RANGE_VOLT_MV = 10000;
const uint32_t ADSWIO_RANGE_RESOLUTION = 65536;

// ------------------------------------------------------ ADDITIONAL FUNCTIONS

void application_default_handler ( uint8_t *err_msg )
{
    char *err_ptr = err_msg;

    log_printf( &logger, "\r\n" );
    log_printf( &logger, "[ERROR] : %s", err_ptr );
    log_printf( &logger, "\r\n" );
}

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

void application_init ( void )
{
    log_cfg_t log_cfg;
    adswio_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.

    adswio_cfg_setup( &cfg );
    ADSWIO_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    adswio_init( &adswio, &cfg );
    Delay_ms( 100 );

    adswio_default_cfg( &adswio );
    Delay_ms( 1000 );

    adswio_rdy  = DUMMY;
    adswio_ch_a = DUMMY;
    adswio_res  = DUMMY;
    adswio_err  = ADSWIO_ERR_STATUS_OK;

    log_printf( &logger, " AD-SWIO click initialization done \r\n");
    log_printf( &logger, "************************************\r\n");
}

void application_task ( void )
{
    uint16_t timeout = 0;
    do
    {
        Delay_1ms( );
        timeout++;
        adswio_rdy = adswio_status_pin_ready( &adswio );
        if ( timeout > 3000 ) 
        {
            timeout = 0;
            log_printf( &logger, " Reinitializing...");
            adswio_default_cfg( &adswio );
            log_printf( &logger, "Done\r\n");
        }
    }
    while ( adswio_rdy != 0 );

    adswio_err = adswio_get_conv_results( &adswio, ADSWIO_SETUP_CONV_EN_CHA, &adswio_ch_a );

    if ( adswio_err == ADSWIO_ERR_STATUS_OK )
    {
        adswio_res = adswio_ch_a;
        adswio_res /= ADSWIO_RANGE_RESOLUTION;
        adswio_res *= ADSWIO_RANGE_VOLT_MV;
        adswio_ch_a = adswio_res;

        log_printf( &logger, " Voltage from channel A: %d mV\r\n", adswio_ch_a );
        
        log_printf( &logger, "-----------------------------------\r\n\r\n" );
        Delay_ms( 200 );
    }
}

void main ( void )
{
    application_init( );

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


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

Additional Support

Resources