Intermediate
30 min

Ensure every word is heard with precision using MCP6022 and PIC32MZ1024EFH064

Mic up and stand out

MIC 2 Click with PIC32MZ clicker

Published Oct 02, 2023

Click board™

MIC 2 Click

Dev Board

PIC32MZ clicker

Compiler

NECTO Studio

MCU

PIC32MZ1024EFH064

Build a top-quality microphone setup that meets your unique needs and specifications.

A

A

Hardware Overview

How does it work?

MIC 2 Click is based on a small omnidirectional electret microphone, accompanied by a digitally controlled pre-amp section. The pre-amp consists of the MCP6022, a dual, rail-to-rail, low noise operational amplifier from Microchip. This op-amp has a wide bandwidth of 10MHz, very low noise, and extremely low total harmonic distortion (THD). These features make it perfectly suitable to be used to build a microphone pre-amplifier (pre-amp). By adding a digital potentiometer IC in the feedback loop, it is possible to set the gain ratio by the host MCU. The AD5171, a digital potentiometer IC with 64 positions from Analog Devices is used in the feedback loop to digitally control the gain ratio. This device contains an OTP memory (a fuse) which can be used to lock the wiper in a permanent position. The wiper data can be changed indefinitely until the internal protection fuse is blown. This can be done by a special command. However, the Click board™ must be operated at 5V in order to successfully blow up the fuse and lock down the wiper position

permanently. Please consult the AD5171 for more details about the OTP memory programming and permanent lock-down of the wiper position. The AD5171 uses the I2C interface to communicate with the host MCU. The slave I2C address of this device can be changed using the SMD jumper, labeled as ADDR SEL. This jumper sets the LSB of the address, allowing it to be selected between 0b0101100x, and 0b0101101x, where (x) represents the R/W bit. The datasheet of the AD5171 offers a comprehensive explanation of its operation. However, it is supported by a mikroSDK compatible set of libraries. These functions greatly simplify the use, ensuring that the accidental lock-down is avoided if not wanted. One half of the MCP6022 is configured as a non-inverting amplifier, with the digital potentiometer connected as a rheostat in its feedback loop. The digital rheostat affects the feedback loop gain, allowing the host MCU to control it over the I2C interface. The input of the op-amp is biased by a voltage divider, so it stays at half the power supply

voltage when there is no signal. This way when the signal appears at the input, it can swing both down to 0V and up to VCC. A minimum gain of the op-amp is 23. It can be increased as the AD5171 is moved away from the 0 position. After power ON, the wiper of the AD5171 is in the middle position (i.e. 25K, if it is not locked down to some other value). The second op-amp of the MCP6022 serves as a unity-gain buffer, allowing the host MCU to sample the output over the AN pin of the mikroBUS™. Depending on the applied gain ratio, the output voltage may peak up to VCC. Therefore, care should be taken when selecting the voltage for the Click board™. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this 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.

MIC 2 Click hardware overview image

Features overview

Development board

PIC32MZ Clicker is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC32MZ microcontroller with FPU from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing access anywhere and under

any circumstances. Each part of the PIC32MZ Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the PIC32MZ Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current, which is more than enough to operate all onboard

and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. PIC32MZ Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

PIC32MZ clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

1024

Silicon Vendor

Microchip

Pin count

64

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

Analog Output
RE4
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
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RD10
SCL
I2C Data
RD9
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

MIC 2 Click Schematic schematic

Step by step

Project assembly

PIC32MZ clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the PIC32MZ clicker as your development board.

PIC32MZ clicker front image hardware assembly
Thermo 26 Click front image hardware assembly
Prog-cut hardware assembly
Micro B Connector clicker - 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
Flip&Click PIC32MZ 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

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 MIC 2 Click driver.

Key functions:

  • mic2_set_potentiometer - This function set the value of digital potentiometer

  • mic2_read_an_pin_value - This function reads results of AD conversion of the AN pin

  • mic2_read_an_pin_voltage - This function reads results of AD conversion of the AN pin and converts them to proportional voltage level.

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 Mic2 Click example
 * 
 * # Description
 * This range is suited for audio and/or speech applications.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver and logger and sets the digital potentiometer.
 * 
 * ## Application Task  
 * Reads the AN pin voltage and displays the results on the USB UART every 100ms.
 * 
 * \author MikroE Team
 *
 */

#include "board.h"
#include "log.h"
#include "mic2.h"

static mic2_t mic2;
static log_t logger;
 
void application_init ( void )
{
    log_cfg_t log_cfg;
    mic2_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.
    mic2_cfg_setup( &cfg );
    MIC2_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    mic2_init( &mic2, &cfg );

    mic2_set_potentiometer( &mic2, 35 );
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    float voltage = 0;
    if ( MIC2_OK == mic2_read_an_pin_voltage ( &mic2, &voltage ) ) 
    {
        log_printf( &logger, " AN Voltage : %.3f[V]\r\n\n", voltage );
        Delay_ms ( 100 );
    }
}

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.