Intermediate
30 min

Experience voltage stability with LM317 and ATmega2560

Classic voltage regulator

VREG 2 Click with UNI-DS v8

Published Feb 12, 2024

Click board™

VREG 2 Click

Dev. board

UNI-DS v8

Compiler

NECTO Studio

MCU

ATmega2560

Efficient, reliable, and ready to take your devices to the next level!

A

A

Hardware Overview

How does it work?

VREG 2 Click is based on the outstanding performance of the LM317, a well-established adjustable voltage regulator from Texas Instruments. The circuit on this Click board™ consists of two voltage regulators, one of which is a linear voltage regulator. At the same time the second is a switching step-down converter, also known as the buck converter. Such topology combines the benefits of both worlds: linear regulator offers low voltage ripple and noise, while the switching regulator provides optimal working conditions, avoiding large voltage differences between the input and output voltage of the linear regulator. Unlike the buck converter, a significant difference between the linear regulator's input and output voltage leads to significant dissipation losses. The Click board™ also uses the LM2596, a 3A step-down voltage regulator working at 150 kHz, from Texas Instruments. It belongs to the Simple Switcher™ line of products and supports both continuous and discontinuous modes. This buck DC-DC

converter can handle from 4.5V up to 40V, but the circuit works reliably with voltages between 9V and 35V. This IC has a reasonably simple layout with just a few external pins. The feedback loop regulates the output voltage of the DC-DC converter. Normally, there is a voltage divider with its center pin routed to the FB pin of the LM2596, but on this Click board™, there is a PNP BJT with the 2.7V Zener diode on its emitter, which is used to provide about 3V more voltage on its output, than the desired target voltage. This provides an ideal voltage headroom for the linear regulator, allowing for greater efficiency and less power dissipation. The input voltage is provided from the LM2596, and as already mentioned, this voltage is about 3V greater than the target regulation voltage, allowing optimal headroom for LM317 IC. The ADJ pin is used to set the output voltage on this IC. The output of the first op-amp of the LM358 IC, a dual operational amplifier from Texas Instruments, drives it. The PWM signal from the MCU controls this op-amp's non-inverting

input; therefore, the mikroBUS™ PWM pin is routed to this non-inverting input. By applying an additional RC filter, the PWM signal is converted to a constant linear voltage ranging up to 3.3V, as it is limited by another Zener diode on this input. The inverting pin of this op-amp is connected to an output voltage divider, with its center tap at 3.3V for the maximum output voltage of 15V. This allows the output voltage to be measured by the host MCU. Therefore, this pin is routed to the mikroBUS™ AN pin. The short circuit protection section is designed with the second op-amp of the LM358 IC, working as a comparator. When the current starts flowing through the 0.5Ω resistor, in the event of a short circuit on the output, it will cause the op-amp output voltage to rise. The red LED indicator labeled OCP will be lit, indicating the short circuit condition. This will also cause the rising of the FB voltage of the buck regulator, effectively blocking its operation and cutting the power to the output.

VREG 2 Click hardware overview image

Features overview

Development board

UNI-DS v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports a wide range of microcontrollers, such as different STM32, Kinetis, TIVA, CEC, MSP, PIC, dsPIC, PIC32, and AVR MCUs regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer over WiFi. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, UNI-DS v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the UNI-DS v8 development board contains the components necessary for the most efficient operation of the same board. An advanced integrated CODEGRIP programmer/debugger module offers many valuable programming/debugging options, including support for JTAG, SWD, and SWO Trace (Single Wire Output)), and seamless integration with the Mikroe software environment. Besides, it also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector. Communication options such as USB-UART, USB

HOST/DEVICE, CAN (on the MCU card, if supported), and Ethernet is also included. In addition, it also has the well-established mikroBUS™ standard, a standardized socket for the MCU card (SiBRAIN standard), and two display options for the TFT board line of products and character-based LCD. UNI-DS v8 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.

UNI-DS v8 horizontal image

Microcontroller Overview

MCU Card / MCU

SiBRAIN for ATmega2560 front image

Type

8th Generation

Architecture

AVR

MCU Memory (KB)

256

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

8192

Used MCU Pins

mikroBUS™ mapper

Voltage Sensing
PF3
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
NC
NC
3.3V
Ground
GND
GND
PWM Control
PH3
PWM
NC
NC
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

Click board™ Schematic

VREG 2 Click Schematic schematic

Step by step

Project assembly

Fusion for PIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI-DS v8 as your development board.

Fusion for PIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Board mapper by product7 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 image step 7 hardware assembly
Necto image step 8 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

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for VREG 2 Click driver.

Key functions:

  • vreg2_set_duty_cycle - This function sets the PWM duty cycle in percentages

  • vreg2_pwm_start - This function starts the PWM module output

  • vreg2_pwm_stop - This function stops the PWM module output

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief VREG 2 Click example
 * 
 * # Description
 * This example demonstrates the use of the VREG 2 Click board by changing
 * the voltage output every 5 seconds.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Controls the voltage output by changing the PWM duty cycle every 5 seconds.
 * The duty cycle ranges from 10% to 50%. Each step will be logged on
 * the USB UART where you can track the program flow.
 * 
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "vreg2.h"

static vreg2_t vreg2;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    vreg2_cfg_t vreg2_cfg;  /**< Click config object. */

    /** 
     * 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.
    vreg2_cfg_setup( &vreg2_cfg );
    VREG2_MAP_MIKROBUS( vreg2_cfg, MIKROBUS_1 );
    if ( PWM_ERROR == vreg2_init( &vreg2, &vreg2_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( VREG2_ERROR == vreg2_default_cfg ( &vreg2 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    static int8_t duty_pct = 10;
    static int8_t duty_step = 10;
    if ( VREG2_OK == vreg2_set_duty_cycle ( &vreg2, ( float ) duty_pct / 100 ) )
    {
        log_printf( &logger, "\r\n Duty: %u%%\r\n", ( uint16_t ) duty_pct );
    }
    duty_pct += duty_step;
    if ( ( duty_pct > 50 ) || ( duty_pct < 10 ) ) 
    {
        duty_step = -duty_step;
        duty_pct += ( duty_step * 2 );
    }
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ 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.