<examples/I2C/Wire/PAC193X>
PAC193x Energy Monitor
Overview
This application demonstrates the use of the PAC193x Energy Monitor IC used onboard the SOMRT1061 development platform. The PAC193x is a multi-channel power/energy monitor that provides accurate measurements of voltage, current, power, and energy consumption.
Hardware Requirements
- SOMRT1061 development board with onboard PAC193x IC
- I2C interface for communication
- 24.9 milliohm sense resistor (default configuration)
Features
The application provides comprehensive power monitoring capabilities including:
- Voltage Monitoring: Bus voltage measurements in millivolts
- Current Sensing: Current measurements in milliamps through sense resistor
- Power Calculation: Instantaneous and average power in milliwatts
- Energy Tracking: Energy consumption in milliwatt-hours
- Device Identification: Product ID, Manufacturer ID, and Revision ID readout
Application Flow
- Initialization
- Initialize I2C communication
- Configure PAC193x with default settings
- Read and display device identification information
- Continuous Monitoring
- Updates all measurement values every 4 seconds
- Displays comprehensive power statistics
- Shows system tick counter for timing reference
Configuration Details
Default Settings
- I2C Address: 0x10
- Sense Resistor: 24.9 milliohms
- Sample Rate: Configurable (8, 64, 256, or 1024 samples/second)
- Channels: Channel 1 active, channels 2-4 disabled
- Update Interval: 4 seconds
Register Configuration
- NEG_PWR register: 0x00 (no negative power detection)
- CTRL register: 0x02 (control settings)
- CHANNEL_DIS register: 0x70 (disable channels 2-4)
- SLOW register: 0x20 (timing configuration)
Measurement Output
The application displays the following measurements:
Product ID: 0x##
Manufacturer ID: 0x##
Revision ID: 0x##
Read start:
Voltage (mV) = ###.######
Vsense (mV) = #.######
Current (mA) = #.######
Raw Power (HEX) = 0x########
Power (mW) = #.######
Avg Power (mW) = #.######
Raw Power Acc = 0x################
Acc Count = 0x########
Energy (mWh) = #.######
Key Functions
Setup Functions
SetupPwrMon(): Initializes I2C and PAC193x, reads device IDs
pwrMon.begin(): Configures PAC193x registers and performs initial refresh
Measurement Functions
UpdateVoltage(): Reads bus voltage
UpdateVsense(): Reads sense voltage across resistor
UpdateCurrent(): Calculates current from sense voltage
UpdatePower(): Calculates instantaneous power
UpdateAvgPower(): Calculates average power from accumulator
UpdateEnergy(): Calculates energy consumption
Error Handling
The library includes comprehensive error handling with the following error codes:
0: No error
-1: I2C read communication error
-2: I2C write communication error
-3: Invalid sense resistor value (zero or negative)
-4: Invalid sample rate selection
Technical Specifications
Voltage Measurement
- Range: 0-32V
- Resolution: 16-bit
- LSB: 32000mV / 65536 = ~0.488mV
Current Measurement
- Method: Sense voltage across precision resistor
- Sense Voltage Range: +/-100mV
- Resolution: 16-bit
- Calculation: Current = (Vsense / Rsense) * 1,000,000 uA
Power Measurement
- Method: Digital multiplication of voltage and current
- Resolution: 28-bit
- Accumulation: 48-bit accumulator for average calculations
Library Architecture
The PAC193x library provides both raw register access and calculated real-world values:
- Raw Functions: Direct register values for maximum precision
- Calculated Functions: Converted values in standard engineering units
- Flexible Configuration: Multiple constructor options for different setups
- I2C Abstraction: Compatible with standard Wire library interface
Usage Example
#include "PAC193x.h"
PAC193x pwrMon(Wire, 100000);
void setup() {
Wire.begin();
pwrMon.begin();
pwrMon.UpdateProductID();
pwrMon.UpdateManufacturerID();
pwrMon.UpdateRevisionID();
}
void loop() {
pwrMon.UpdateVoltage();
pwrMon.UpdateCurrent();
pwrMon.UpdatePower();
pwrMon.UpdateEnergy();
float voltage = pwrMon.Voltage;
float current = pwrMon.Current;
double power = pwrMon.Power;
float energy = pwrMon.Energy;
delay(1000);
}
File Structure
main.cpp: Main application demonstrating PAC193x usage
PAC193x.h: Library header with class definition and register addresses
PAC193x.cpp: Library implementation with all measurement functions