Intermediate
30 min

Experience powerful sound without compromise with TPA3128D2 and PIC18F57Q43

Unleash the sonic potential

2x30W Amp Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

2x30W Amp Click

Development board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

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

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

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

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX 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
PIC18F57Q43 Curiosity 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 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