3.4.2 Harmony 3 EMAFE DMA Transfer Mode Example

This topic provides instructions and information about the MPLAB Harmony 3 EMAFE DMA transfer mode demonstration application, which is included in the MPLAB Harmony Smart Energy Metrology Applications distribution.

Description

This demonstration application configures the EMAFE peripheral to enable only channel 2 of the low-pass filter, which implies the activation of the V1 input signal.
Table 3-17. Input Signals Assignment
ChannelInput SignalData Register
Channel 0Temperature sensorEMAFE_DATA0
Channel 1I1EMAFE_DATA1
Channel 2V1EMAFE_DATA2
Channel 3I2EMAFE_DATA3
Channel 4V2EMAFE_DATA4

After enabling V1 decimation filter, V1 is configured to be used in DMA mode.

Once DMA transfer has been completed and data samples have been written in the data memory, the ENDRX flag rises. If the corresponding interrupt is enabled, an interrupt is generated.

This application has been designed to capture 1600 samples, which supports 5 cycles of a periodic 50 Hz signal:

Fs = 16000 ksps. Fin = 50Hz. Fs/Fin = 320 samples/cycle. Total samples = 320 * 5 = 1600 samples in 5 cycles.

Where Fs is sampling frequency and Fin is input signal frequency.

All samples are automatically captured in the data memory by DMA peripheral without any interaction with the user application. Once all samples are captured, interrupt is triggered and, data samples are sent to the terminal console application for analysis with an external tool.
Note: It is strongly recommended to follow the below sequence of the application state diagram to ensure a correct initialization of the analog parts in the EMAFE peripheral.
Figure 3-46. Application State Diagram

Harmony MCC Component Blocks

Figure 3-47. EMAFE DMA Transfer Mode Project Graph for PIC32CXMTSH DB

The virtual COM Port interface is enabled to provide an output console.

Energy Metering Analog Front End component must be enabled.

Figure 3-48. PIC32CXMTSH DB Board Configuration

Clock Configuration

Clocks are configured to match the following distribution:

Figure 3-49. PLL A Clock Configuration
Figure 3-50. PLL B Clock Configuration
Figure 3-51. PLL C Clock Configuration
Figure 3-52. PCK2 Clock Configuration
Figure 3-53. PCK2 Clock Configuration
Figure 3-54. Peripherals Clock Configuration

Harmony EMAFE Code Configuration Options

EMAFE peripheral library is configured to use Direct Transfer mode by default.

Figure 3-55. EMAFE Configuration Options

Building the Application

This section identifies the MPLAB X IDE project name and location and lists and describes the available configurations for the demonstration.

The parent folder for these files is smartenergy_metrology\apps\peripherals\emafe\emafe_dma. To build this project, the user must open the smartenergy_metrology\apps\peripherals\emafe\emafe_dma\emafe_dma_pic32cxmtsh_db.X project file in MPLAB X IDE.

MPLAB X IDE Project Configurations

This table lists and describes the supported configurations of the demonstration, which are located within ./src/config.

Project NameConfigurationDescription
emafe_dma_pic32cxmtsh_dbpic32cxmtsh_dbThis demonstration runs on the PI32CXMTSH Development Board.

Running the Demonstration

To run this application, the PIC32CXMTSH DB has been connected to a WECO Meter test board, and configured accordingly.
Figure 3-56. WECO Equipment Configuration
Figure 3-57. EMAFE Direct Transfer Mode Demo Application
After running the application, data samples have been represented using an external tool.
Figure 3-58. Samples Representation