Jump to main content

# 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-18.Input Signals Assignment
Channel | Input Signal | Data Register
--- | --- | ---
Channel 0 | Temperature sensor | EMAFE_DATA0
Channel 1 | I1 | EMAFE_DATA1
Channel 2 | V1 | EMAFE_DATA2
Channel 3 | I2 | EMAFE_DATA3
Channel 4 | V2 | EMAFE_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-44.Application State Diagram

Harmony MCC Component Blocks

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

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

EMAFE component must be enabled.

Figure 3-46.PIC32CXMTSH-DB Board Configuration

Clock Configuration

Clocks are configured to match the following distribution.

Figure 3-47.PLLA Clock Configuration
Figure 3-48.PLLB Clock Configuration
Figure 3-49.PLLC Clock Configuration
Figure 3-50.PCK2 Clock Configuration
Figure 3-51.Peripherals Clock Configuration

Harmony EMAFE Code Configuration Options

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

Figure 3-52.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 Name | Configuration | Description
--- | --- | ---
emafe_dma_pic32cxmtsh_db | pic32cxmtsh_db | This 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-53.WECO Equipment Configuration
Figure 3-54.EMAFE Direct Transfer Mode Demo Application
After running the application, data samples have been represented using an external tool.
Figure 3-55.Samples Representation

Rev: E