Intermediate
30 min

Efficiently regulate negative voltages with MCP16331 and STM32F031K6

Voltage flexibility unleashed

MCP16331 INV Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

MCP16331 INV Click

Dev. board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Experience efficient conversion of input voltages to desired negative levels while benefiting from the dynamic buck-boost capability that ensures stability and accuracy, enabling reliable operation across various applications

A

A

Hardware Overview

How does it work?

MCP16331 INV Click is based on the MCP16331, a step-down (buck) switching regulator from Microchip. However, with the help of a few external components, MCP16331 INV Click can regulate voltage levels lower and higher than the input voltage, working as an inverted boost-buck voltage regulator. The MCP16331 INV click is designed to output a negative voltage with respect to the GND. A negative voltage is often used in the analog electronics domain to power up devices requiring both positive and negative voltages. A good example would be an operational amplifier (opamp) which amplifies an AC signal. The signal goes in both positive and negative directions with respect to the GND. Processing this kind of signal using a single voltage source is difficult and requires workarounds such as capacitors, charge pumps, and virtual GNDs. Using a symmetrical power supply reduces the required components and simplifies the design. Several additional components, such as the ADM8828 voltage inverter IC and the LM318, a dual operational amplifier, must be added to deliver a negative voltage. The ADM8828 voltage inverter IC provides a negative component of the symmetrical power supply used for the LM318 dual opamp. One integrated opamp from the LM318 IC is used to invert the output from the DAC.

The other opamp from the LM318 IC is used to invert the output from the voltage divider, located on the output rail of the MCP16331, so that it can be used by the MCU, which uses a single voltage power source. To set the output voltage of the MCP16331 INV click, the MCP4921 - a low-power 12-Bit dual voltage output DAC is used in the feedback loop. As already mentioned, it is necessary to invert this signal as the MCP4921 is supplied from a single-voltage power supply, and it cannot bring the signal lower than the GND. Since MCP16331 works in the negative voltage domain, the feedback voltage applied to the FB pin of this IC also needs to be negative with respect to the GND. One of the LM318's integrated opamps, configured as a unity gain inverter, is used to invert the DAC output voltage. Since the DAC drives the FB pin of the MCP16331 IC, it is enough to set the DAC to a specific value to control the output voltage of the click board™. Communication with the MCP4921 DAC is done via the SPI interface. SPI bus pins of the MCP4921 are routed to the mikroBUS™ for an easy and secure connection with the host MCU. The AN pin of the mikroBUS™ is routed to a middle point of a voltage divider at the output. This voltage divider is used to scale down the output voltage so the ADC of the host MCU can successfully convert it.

The voltage on the divider also has to be inverted since it is coming out from the negative voltage domain. This is achieved by the second operational amplifier of the LM318 IC, which also works as a unity gain inverter. This value can be used to monitor and correct the output voltage if needed. The EN pin of the MCP16331 switching regulator is routed to the mikroBUS™ RST pin. By pulling this pin to a HIGH logic level, the internal sections of the regulator are enabled. The EN pin is internally pulled to a HIGH logic level, so the device will be enabled, even if this pin is left floating. Therefore, a correct startup sequence must be used to avoid undesirable effects (in the NOTE below). Although it is designed to work as the negative power supply, the MCP16331INV click can also be used to drive a regular load, connecting its positive input terminal to the GND of the click board™ and using the negative output of the MCP16331INV click as the GND. MCP16331 INV Click with two screw terminals to connect the input and the output voltage rails. This click board™ uses only +5V rail from the mikroBUS™. Provided libraries demonstrate the functionality of the MCP16331 INV click and offer an easy and simple way of setting it up.

MCP16331 INV Click hardware overview image

Features overview

Development board

Nucleo 32 with STM32F031K6 MCU board provides an affordable and flexible platform for experimenting with STM32 microcontrollers in 32-pin packages. Featuring Arduino™ Nano connectivity, it allows easy expansion with specialized shields, while being mbed-enabled for seamless integration with online resources. The

board includes an on-board ST-LINK/V2-1 debugger/programmer, supporting USB reenumeration with three interfaces: Virtual Com port, mass storage, and debug port. It offers a flexible power supply through either USB VBUS or an external source. Additionally, it includes three LEDs (LD1 for USB communication, LD2 for power,

and LD3 as a user LED) and a reset push button. The STM32 Nucleo-32 board is supported by various Integrated Development Environments (IDEs) such as IAR™, Keil®, and GCC-based IDEs like AC6 SW4STM32, making it a versatile tool for developers.

Nucleo 32 with STM32F031K6 MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

32

RAM (Bytes)

4096

You complete me!

Accessories

Click Shield for Nucleo-32 is the perfect way to expand your development board's functionalities with STM32 Nucleo-32 pinout. The Click Shield for Nucleo-32 provides two mikroBUS™ sockets to add any functionality from our ever-growing range of Click boards™. We are fully stocked with everything, from sensors and WiFi transceivers to motor control and audio amplifiers. The Click Shield for Nucleo-32 is compatible with the STM32 Nucleo-32 board, providing an affordable and flexible way for users to try out new ideas and quickly create prototypes with any STM32 microcontrollers, choosing from the various combinations of performance, power consumption, and features. The STM32 Nucleo-32 boards do not require any separate probe as they integrate the ST-LINK/V2-1 debugger/programmer and come with the STM32 comprehensive software HAL library and various packaged software examples. This development platform provides users with an effortless and common way to combine the STM32 Nucleo-32 footprint compatible board with their favorite Click boards™ in their upcoming projects.

Click Shield for Nucleo-32 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Voltage Sense
PA0
AN
Output Enable
PA11
RST
SPI Chip Select
PA4
CS
SPI Clock
PB3
SCK
NC
NC
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
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

MCP16331 INV Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 32 with STM32F031K6 MCU as your development board.

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Stepper 22 Click complete accessories setup image hardware assembly
Nucleo-32 with STM32 MCU 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
STM32 M4 Clicker HA MCU/Select 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

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 MCP16331 INV Click driver.

Key functions:

  • mcp16331inv_enable_vin - This function enables or disables internal VIN pull up

  • mcp16331inv_set_dac_vout - This function determines DAC output voltage value

  • mcp16331inv_generic_transfer - Generic SPI transfer, for sending and receiving packages

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 
 * \brief Mcp16331Inv Click example
 * 
 * # Description
 * This application enables usage of this click as a buck-boost voltage regulator.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes click driver and enables VIN Pull Up.
 * 
 * ## Application Task  
 * Sets DAC output voltage on 3500mV, when gain is set up on 1x VREF,
 * on 4s delay time, and then sets DAC output voltage on 5000mV, when gain is now set up on 2x VREF,
 * on also 4s delay time. VIN Pull Up voltage must be greater than 4V.
 * 
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "mcp16331inv.h"

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

static mcp16331inv_t mcp16331inv;
static log_t logger;

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

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

    mcp16331inv_cfg_setup( &cfg );
    MCP16331INV_MAP_MIKROBUS( cfg, MIKROBUS_1 );

    Delay_ms( 100 );

    mcp16331inv_init( &mcp16331inv, &cfg );

    Delay_ms( 100 );

    mcp16331inv_enable_vin( &mcp16331inv, MCP16331INV_ENABLE_VIN_PULL_UP );
}

void application_task ( void )
{
    //  Task implementation.

    mcp16331inv_set_dac_vout( &mcp16331inv, MCP16331INV_3500_MV_1X_GAIN, MCP16331INV_GAIN_1X_VREF, MCP16331INV_ACTIVE_MODE );
    Delay_ms( 4000 );
    mcp16331inv_set_dac_vout( &mcp16331inv, MCP16331INV_5000_MV_2X_GAIN, MCP16331INV_GAIN_2X_VREF, MCP16331INV_ACTIVE_MODE );
    Delay_ms( 4000 );
}

void main ( void )
{
    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.