This example demonstrates how to interface with the MCP6022 microphone integrated on the Curiosity Nano Explorer development board by utilizing the Analog-to-Digital Converter (ADC) found on the PIC18F56Q24 microcontroller. The analog audio signals captured by the microphone are converted into a digital data representation the ADC on the PIC18F56Q24. This digital data is then transmitted from the PIC18F56Q24 to a host computer via the Universal Asynchronous Receiver and Transmitter (UART) interface. On the host computer, the Data Visualizer tool is used to display and analyze the incoming data in real time, allowing users to observe the microphone’s output and evaluate its performance.
- MPLAB® X IDE 6.20.0 or newer
- MPLAB® XC8 3.00.0 or newer compiler
- MPLAB® Code Configurator (MCC) 5.5.1 or newer
- Microchip PIC18F-Q Series DFP (1.24.430) or newer
- PIC18F56Q24 Curiosity Nano Evaluation Kit
- Curiosity Nano Explorer
- USB type C cable
All instructions required to recreate this example are provided below:
- Create a new project and open the MPLAB Code Configurator (MCC) by selecting Tools > Embedded > MPLAB Code Configurator.
- In the Resource Management tab, navigate to Device Resources > Libraries > Data Visualizer > Data Streamer. Click the '+' icon to add the Data Streamer to the project graph.
- The UART peripheral will be automatically added under Project Resources > Drivers. Select the UART peripheral to open its configuration panel.
- Specify UART2 as the PLIB selector. Configure the settings in the configuration window to match the provided reference image.
-
Navigate to Device Resources > Drivers > ADC and select the '+' icon to add the ADC peripheral to your project
-
Select ADC from Project Resources > Drivers > ADC to open the configuration window
-
See images below for changes that must be made. Note that:
- In image 1, continuous operation is enabled. This means that sampling will start automatically once a conversion is complete.
- In image 2, the sampling frequency is approximately 48 kHz, the standard rate for microphones. You can adjust the sampling frequency by adjusting the clock divider.
- In image 3, the conversion interrupt is enabled. The main program will contain an interrupt service routine (ISR) that writes the conversion result to the Data Visualizer.
-
Navigate to Device Resources > Drivers > ADC and click the '+' icon to add the ADC peripheral to the project.
-
Select ADC from Project Resources > Drivers > ADC to open the configuration window.
-
Refer to the images below for the required configuration changes. Note the following:
- In image 1, continuous operation is enabled, allowing sampling to start automatically after each conversion is complete.
- In image 2, the sampling frequency is set to approximately 48 kHz, which is the standard rate for microphones. The sampling frequency can be adjusted by modifying the clock divider.
- In image 3, the conversion interrupt is enabled. The main program will include an interrupt service routine (ISR) that writes the conversion result to the Data Visualizer.
- The userguide for the Curiosity Explorer Nano board provides detailed information about the pin mapping between the Curiosity Explorer board and the PIC18F56Q24 Curiosity Nano board being used in this example. This example uses the ADC and UART peripherals found on the PIC18F56Q24. According to the image below, RB5 and RB4 are assigned as UART2 TX and RX, respectively. On the physical Curiosity Nano Explorer board, the "Microphone out" signal is connected to ADC6, which corresponds to pin RA3.
- To select and configure these pins in MPLAB Code Configurator (MCC), open the "Pin Grid View" located in the lower half of the interface. Adjust the pin assignments to match the configuration shown in the image below.
- Click on "Generate" to complete the configuration in MCC.
After programming the device, open the Data Visualizer by selecting the "DV" icon from the toolbar.
- In the Data Visualizer, select "Variable Streamer" from the sidebar, then click "Import."
- Navigate to mcc_generated_files > data_streamer and select the
data_streamer.ds
file. - Specify the Curiosity Nano as the data source, then select the plot data icon to begin visualizing the data.
- To adjust the graph axes, hover over the desired axis and use the scroll wheel to zoom in or out. Click and drag the axis to reposition it as needed.
For more information on using the Data Streamer, navigate to the official online documentation. or support resources provided by the development environment or tool vendor.
This demonstration shows how to configure the ADC on the PIC18F56Q24 microcontroller. To simulate a practical application, an analog signal is captured from a microphone, and the resulting data is displayed using the Data Visualizer tool.