Intermediate
30 min

Experience powerful sound without compromise with TPA3128D2 and STM32F031K6

Unleash the sonic potential

2x30W Amp Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

2x30W Amp Click

Dev Board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Whether you're a music enthusiast, a DIY audio project lover, or a professional sound designer, the 2x30W Amp Click is perfect for amplifying audio signals compactly and efficiently

A

A

Hardware Overview

How does it work?

2x30W Amp Click is based on the TPA3128, 2x30-W class-D amplifier with low idle power dissipation from Texas Instruments. The most important characteristic of this IC is its output efficiency, which reduces the need for bulky heat sinks, usually associated with audio amplifiers. This is accomplished by switching MOSFET outputs, which have very low RDSON, as low as 90 mΩ. ClassD amplifiers are way more efficient by design than class A or AB amplifiers. Class D amplifier working principles are based on the switching characteristic of the transistors rather than the linear characteristic used for the A/AB class amplifiers. The audio signal is encoded into a PWM signal with a fixed amplitude. An output signal is restored through the LC filter and the speaker itself. Since the basis of this principle is switching the signal, and the transistors are either fully ON or fully OFF, they spend very little time in the linear region and dissipate very little power. Using low RDSON MOSFETs becomes possible and desirable so that the efficiency goes up to 90% and over. 2x30W Amp click is designed to work with two channels of a single-sided audio source, connected via the 3.5mm stereo audio jack provided on board. The Click board™ is equipped with a connector for the external power source.

By default, the 2x30 Amp click is supplied via the mikroBUS™ 5V rail, which limits the output power. An adequate external power supply should be used for the full output power. The TPA3128 IC can handle up to 26V. The onboard SMD jumper should be switched to the desired position (EXT or 5V) to select operation via the external power supply. If the EXT position is selected, the external power supply should be connected via the 1x2 header on the side of the Click board™, labeled as VEXT. The connected speaker impedance should not be less than 4Ω. The speakers can be connected via two edge connectors, with clearly labeled input ports: L+ and L- for connecting the left speaker's positive and negative terminals; R+ and R- for connecting the right speaker's positive and negative terminals. Care should be taken to dimension the speakers according to the maximum output power of the amplifier. The amplifier has a fixed gain of 32dB, determined by two resistors labeled R4 and R5 on the provided schematic. The RST pin of the mikroBUS™ is routed to the SDZ pin of the TPA3128 IC. Setting this pin to a LOW logic level will set the TPA3128 IC in the shutdown mode, with its output stage set to a high impedance (Hi-Z), reducing the idle current to a minimum.

Pulling the SDZ (RST) pin to a LOW logic level before disconnecting the power from the Click board™ to avoid audible power-off clicks is a good practice. The onboard resistor pulls the RST pin up to a HIGH logic level. Another way to mute the speakers is by pulling the MUTE pin to a HIGH logic level. This pin is routed to the CS pin of the mikroBUS™ and labeled as the MT. Pulling this pin to a HIGH logic level will also set the output stage to a Hi-Z, but it will perform a muting function only, thus muting the IC faster than the complete shutdown with the SDZ pin. This function is useful if used in conjunction with the FAULT pin, allowing power-up in a muted state when there is a problem on the output stage. The FAULTZ pin is routed to the INT pin of the mikroBUS™ and labeled as the FLT. It is used to signalize the fault condition (overtemperature, output DC offset detection) to the host MCU. It is active low and can trigger an interrupt request on the host MCU so that the proper action can be taken. The Click board™ uses only GPIO pins, which is extremely simple. However, the Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used, as a reference, for further development.

2x30W Amp 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

NC
NC
AN
Reset
PA11
RST
Mute
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
NC
NC
3.3V
Ground
GND
GND
NC
NC
PWM
Fault Indicator
PA12
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

2x30W Amp 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 via Debug Mode

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

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for 2x30W Amp Click driver.

Key functions:

  • c2x30wamp_enable - Device Enable function

  • c2x30wamp_mute - Device Mute function

  • c2x30wamp_check_diagnostic - Diagnostic Check function

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 c2x30W Amp Click example
 * 
 * # Description
 * This application is audio amplifier.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes GPIO driver and enables the device.
 * 
 * ## Application Task  
 * Mute output for a period of 3 seconds, then keep it unmuted for a period of 10 seconds. 
 * After that, checks if over current fault, over temperature fault or too high DC offset fault occurred.
 * 
 * ## NOTE 
 * When under or over voltage condition occurres the output goes to high impedance state,
 * but the FAULT pin will not be asserted.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "c2x30wamp.h"

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

static c2x30wamp_t c2x30wamp;
static log_t logger;

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

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

    c2x30wamp_cfg_setup( &cfg );
    C2X30WAMP_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    c2x30wamp_init( &c2x30wamp, &cfg );

    c2x30wamp_enable( &c2x30wamp, C2X30WAMP_ENABLE );
    log_printf( &logger, "2x30W AMP is initialized \r\n" );
    Delay_ms( 200 );
}

void application_task ( void )
{
    c2x30wamp_mute( &c2x30wamp, C2X30WAMP_MUTE );
    log_printf( &logger, "---------------------- \r\n" );
    log_printf( &logger, "MUTE \r\n" );
    Delay_ms( 3000 );
    c2x30wamp_mute( &c2x30wamp, C2X30WAMP_UNMUTE );
    log_printf( &logger, "---------------------- \r\n" );
    log_printf( &logger, "UNMUTE \r\n" );
    Delay_ms( 10000 );

    uint8_t fault_check = c2x30wamp_check_diagnostic( &c2x30wamp );

    if ( fault_check == 0 )
    {
        log_printf( &logger, "Fault condition! \r\n" );
    }
}

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.