1.1.1 How the Metrology Driver Library Works
This driver has been designed to be used with PIC32CXMTSH or PIC32CXMTC devices, which are parts of the PIC32CXMTx device families.
Depending on which device is used, there are some requirements to be considered:
- PIC32CXMTSH connection
- This device supports single phase and dual phase (2 voltages and 2 currents).
- AFE is internally provided.
- PIC32CXMTC connection
- This device supports poly-phase.
- It requires an external AFE, ATSense301.
The Energy Metering AFE collects the data from current sensors and voltage inputs and digitalizes voltage and current data. This data is processed by the Metrology library, running on the Core 1 of the PIC32CXMTSH/C part. The Metrology driver and metering application run on Core 0.
Initialization process
After a power up, the metrology driver is responsible of the following points:
- Initialize and configure IPC (Inter-Processor communication) peripheral.
- Initialize the interface with the metrology library through shared memory.
- If the reset cause of the main
processor was not a Watchdog reset:
- Control reset lines of the coprocessor (second processor).
- Control clock lines of the coprocessor (second processor).
- Copy the metrology library application file to the coprocessor execution memory.
- If the reset cause is Watchdog, no actions are performed with coprocessor, as the system is designed to allow coprocessor continue running if a problem arises only on main processor.
The metrology driver provides an assembly file to include the metrology library application file into the application of the main processor:
.section .rodata
.global met_bin_start
.global met_bin_end
.align 8
met_bin_start:
.incbin "./core1_metlib.bin"
.align 8
met_bin_end:
A couple of variables are created in order to set the start and end address where the metrology library file can be found in the main application.
extern uint8_t met_bin_start;
extern uint8_t met_bin_end;
/* Metrology Driver Initialization Data */
DRV_METROLOGY_INIT drvMetrologyInitData = {
/* MET bin destination address */
.regBaseAddress = DRV_METROLOGY_REG_BASE_ADDRESS,
/* MET Binary start address */
.binStartAddress = (uint32_t)&met_bin_start,
/* MET Binary end address */
.binEndAddress = (uint32_t)&met_bin_end,
};
Once the metrology library has been located in the main application, the metrology driver is in charge of copying its content in the execution memory of the coprocessor.
Once the metrology driver has been initialized, it is necessary to call to DRV_METROLOGY_Open routine which is responsible of enabling IPC peripheral and waiting until metrology library application has been started. At this point, metrology control registers are configured and state control data is set to INIT status.
At this point, the application must call the DRV_METROLOGY_GetStatus routine to wait until the status is equal to DRV_METROLOGY_STATUS_READY. Then the metrology driver is ready to be started by the application. For this, the DRV_METROLOGY_Start routine must be called in order to set the metrology library in run mode and receive IPC integration interrupts after each integration period.
Metrology library running in the second core is in charge to trigger a new integration period interrupt when the metrology data is ready. This interrupt is handled by the metrology driver. After processing the received data, a callback function is used to notify this event to the application.
