Intermediate
30 min

Upgrade your audio equipment with PCM5142 and PIC32MZ2048EFM100

Experience sound at its best

Audio DAC Click with Curiosity PIC32 MZ EF

Published Oct 23, 2023

Click board™

Audio DAC Click

Dev.Board

Curiosity PIC32 MZ EF

Compiler

NECTO Studio

MCU

PIC32MZ2048EFM100

Elevate your audio quality by converting sound into a premium analog signal, ensuring an exceptional audio playback experience

A

A

Hardware Overview

How does it work?

Audio DAC Click is based on a combination of DIR9001 and PCM5142, a digital audio interface receiver and audio stereo DAC from Texas Instruments, suitable for upgrading your audio equipment. The DIR9001 audio receiver can accept signals up to a 108kHz sampling rate at the highest, 24-bit data word, biphase-encoded signal, and complies with the jitter specification IEC60958-3, JEITA CPR1205 (Revised version of EIAJ CP-1201), AES3, and EBUtech3250. These signals are brought to the DIR9001 via an onboard fiber optic S/PDIF connector, better known as Sony/Philips digital interface format, a digital audio interface often used in consumer audio equipment. After receiving the signals, the DIR9001 forwards them for further processing by the stereo audio DAC, the PCM5142, also from Texas Instruments. The PCM5142 has a fully programmable miniDSP core, allowing developers

to integrate filters, dynamic range controls, custom interpolators, and other differentiating features into their applications. It uses the latest generation of TI's advanced segment-DAC architecture to achieve excellent dynamic performance, detailed heights, and an exceptionally good sound stage. Compared with existing DAC technology, the PCM5142 offers up to 20dB lower out-of-band noise, reducing EMI and aliasing in downstream amplifiers/ADCs, and accepts industry-standard audio data formats with 16- to 32-bit data and sample rates up to 384kHz. After stereo DAC processing, the output audio signal is available to users for further use on the 3.5mm-line output audio jack, making it suitable for various multimedia systems, satellite radio, CD and DVD players, and more. The PCM5142 communicates with MCU using the standard I2C 2-Wire data transmission protocol

that supports Standard-Mode (100 kHz) and Fast-Mode (400 kHz) operations. In addition to communication pins, this board has several additional functions, providing users with application flexibility. Besides the I2C signals, the mikroBUS™ also has an auto-mute function routed to the MUT pin on the mikroBUS™ socket to mute the device upon intentional or unintentional power loss, as well as one user-configurable general-purpose pin, the IO4 pin of the mikroBUS™ socket. The onboard button labeled as RST can reset the DIR9001 audio receiver. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Audio DAC Click hardware overview image

Features overview

Development board

Curiosity PIC32 MZ EF development board is a fully integrated 32-bit development platform featuring the high-performance PIC32MZ EF Series (PIC32MZ2048EFM) that has a 2MB Flash, 512KB RAM, integrated FPU, Crypto accelerator, and excellent connectivity options. It includes an integrated programmer and debugger, requiring no additional hardware. Users can expand

functionality through MIKROE mikroBUS™ Click™ adapter boards, add Ethernet connectivity with the Microchip PHY daughter board, add WiFi connectivity capability using the Microchip expansions boards, and add audio input and output capability with Microchip audio daughter boards. These boards are fully integrated into PIC32’s powerful software framework, MPLAB Harmony,

which provides a flexible and modular interface to application development a rich set of inter-operable software stacks (TCP-IP, USB), and easy-to-use features. The Curiosity PIC32 MZ EF development board offers expansion capabilities making it an excellent choice for a rapid prototyping board in Connectivity, IOT, and general-purpose applications.

Curiosity PIC32MZ EF double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

2048

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Soft-Mute
RPE8
PWM
General-Purpose I/O
RF13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RPA14
SCL
I2C Data
RPA15
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Audio DAC Click Schematic schematic

Step by step

Project assembly

Curiosity PIC32MZ EF front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity PIC32 MZ EF as your development board.

Curiosity PIC32MZ EF front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity PIC32 MZ EF MB 1 Access - 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
Curiosity PIC32 MZ EF 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 Audio DAC Click driver.

Key functions:

  • audiodac_get_gpio4_pin - This function returns the GPIO4 pin logic state. The GPIO4 pin is mapped to auto mute flag output for both L and R channels by default

  • audiodac_volume_control - This function sets the volume level for the selected output 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 main.c
 * @brief Audio DAC Click example
 *
 * # Description
 * This example demonstrates the use of Audio DAC click board by controling the volume
 * level of both output channels.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Checks if the auto mute flag is set and then changes the volume level of both output channels
 * every 100ms. All data is being displayed on the USB UART where you can track the program flow.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "audiodac.h"

static audiodac_t audiodac;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    audiodac_cfg_t audiodac_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.
    audiodac_cfg_setup( &audiodac_cfg );
    AUDIODAC_MAP_MIKROBUS( audiodac_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == audiodac_init( &audiodac, &audiodac_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( AUDIODAC_ERROR == audiodac_default_cfg ( &audiodac ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static uint8_t volume = AUDIODAC_VOLUME_MUTE;
    if ( audiodac_get_gpio4_pin ( &audiodac ) )
    {
        log_printf ( &logger, " Auto mute flag (both L and R channels are auto muted)\r\n" );
        // Wait until the channels are auto unmuted, i.e. until a valid digital signal is received
        while ( audiodac_get_gpio4_pin ( &audiodac ) );
    }
    if ( AUDIODAC_OK == audiodac_volume_control ( &audiodac, AUDIODAC_CHANNEL_BOTH, volume ) )
    {
        log_printf ( &logger, "\r\n Volume: " );
        if ( AUDIODAC_VOLUME_MUTE == volume )
        {
            log_printf ( &logger, "MUTE\r\n" );
            Delay_ms ( 3000 );
        }
        else if ( AUDIODAC_VOLUME_MAX == volume )
        {
            log_printf ( &logger, "MAX\r\n" );
            Delay_ms ( 3000 );
        }
        else
        {
            log_printf ( &logger, "%u\r\n", ( uint16_t ) volume );
            Delay_ms ( 100 );
        }
        volume++; 
        if ( volume > AUDIODAC_VOLUME_MAX )
        {
            volume = AUDIODAC_VOLUME_MUTE;
        }
    }
}

void main ( void ) 
{
    application_init( );

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

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

Additional Support

Resources