3.4.1 Harmony 3 EMAFE Direct Transfer Mode Example

This topic provides instructions and information about the MPLAB Harmony 3 EMAFE direct 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-16. Input Signals Assignment
ChannelInput SignalData Register
Channel 0Temperature sensorEMAFE_DATA0
Channel 1I1EMAFE_DATA1
Channel 2V1EMAFE_DATA2
Channel 3I2EMAFE_DATA3
Channel 4V2EMAFE_DATA4

When enabling V1 filter, V1 filter uploads their 24-bit data in EMAFE_DATA2 register.

When a new set of data in V1 is uploaded, the flag DRDY is set in the Interrupt Status register (EMAFE_ISR). An interrupt can be triggered if the bit DRDY is written to 1 in the Interrupt Enable register (EMAFE_IER).

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 captured in the EMAFE interrupt callback by reading the corresponding EMAFE_DATA register. Once all samples are captured, they 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-33. Application State Diagram

Harmony MCC Component Blocks

Figure 3-34. EMAFE Direct 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-35. PIC32CXMTSH DB Board Configuration

Clock Configuration

Clocks are configured to match the following distribution.

Figure 3-36. PLL A Clock Configuration
Figure 3-37. PLL B Clock Configuration
Figure 3-38. PLL C Clock Configuration
Figure 3-39. PCK2 Clock Configuration
Figure 3-40. Peripherals Clock Configuration

Harmony EMAFE Code Configuration Options

EMAFE peripheral library is configured to use Direct Transfer mode by disabling the Enable DMA option.

Figure 3-41. 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_polled. To build this project, the user must open the smartenergy_metrology\apps\peripherals\emafe\emafe_polled\emafe_polled_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_polled_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-42. WECO Equipment Configuration
Figure 3-43. EMAFE Direct Transfer Mode Demo Application
After running the application, data samples have been represented using an external tool.
Figure 3-44. Samples Representation