功率测量
本示例演示了如何使用BL0937功率测量芯片来检测电压、电流、有功功率和能耗等电气参数。使用 FreeRTOS 在ESP32上实现,展示了如何配置BL0937功率测量芯片并与开发芯片连接。该示例初始化功率测量系统、获取各种参数并定期记录。
适配列表
名称 |
功能 |
供应商 |
规格书 |
硬件抽象层 |
---|---|---|---|---|
BL0937 |
检测电量参数,例如电压、电流以及功率和消耗的电量 |
BELLING |
x |
API 参考
The following API implements hardware abstraction for power measure. Users can directly call this layer of code to write sensor applications.
Header File
Functions
-
esp_err_t power_measure_init(power_measure_init_config_t *config)
power measure component int
- 参数
config – configuration for power measure hardware
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_NO_MEM
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_deinit()
power measure component deint
- 返回
ESP_OK
ESP_FAIL
-
esp_err_t power_measure_get_voltage(float *voltage)
get current vltage (V)
- 参数
voltage – current voltage (V)
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_current(float *current)
get current current (A)
- 参数
current – current current (A)
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_active_power(float *active_power)
get current active power (W)
- 参数
active_power – current active power (W)
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_power_factor(float *power_factor)
get current power factor
- 参数
power_factor – power factor
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_energy(float *energy)
get current energy (Kw/h)
- 参数
energy – Power consumed by the load (Kw/h)
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_start_energy_calculation()
start the energy calculation
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_stop_energy_calculation()
stop the energy calculation
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_reset_energy_calculation()
reset the energy accumulated value in flash
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_start_calibration(calibration_parameter_t *para)
start calibration for factory test
- 参数
para – calibration parameters
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_calibration_factor(calibration_factor_t *factor)
get calibration factor from flash
- 参数
factor – calibration factor
- 返回
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_calibration_factor_reset(void)
reset factor in flash
- 返回
ESP_OK
ESP_FAIL POWER_MEASURE
Structures
-
struct overcurrent_event_data_t
Data structure for overcurrent event data.
-
struct overvoltage_event_data_t
Data structure for overvoltage event data.
-
struct undervoltage_event_data_t
Data structure for undervoltage event data.
-
struct calibration_parameter_t
Structure for calibration parameters.
-
struct calibration_factor_t
Structure for calibration factors.
-
struct chip_config_t
Configuration structure for the chip.
Public Members
-
power_measure_chip_t type
Type of the chip used
-
calibration_factor_t factor
Calibration factors for the chip
-
gpio_num_t sel_gpio
GPIO number for selection
-
gpio_num_t cf1_gpio
GPIO number for CF1
-
gpio_num_t cf_gpio
GPIO number for CF
-
uint8_t pin_mode
Pin mode configuration
-
float sampling_resistor
Value of the sampling resistor
-
float divider_resistor
Value of the divider resistor
-
power_measure_chip_t type
-
struct power_measure_init_config_t
Initialization configuration structure for power measurement.
Macros
-
STORGE_FACTOR_KEY
STORGE_FACTOR_KEY.
Enumerations
-
enum power_measure_event_t
POWER_MEASURE event base.
Enumeration of power measurement events.
Values:
-
enumerator POWER_MEASURE_INIT_DONE
Initialisation Done
-
enumerator POWER_MEASURE_OVERCURRENT
Overcurrent detected
-
enumerator POWER_MEASURE_OVERVOLTAGE
Overvoltage detected
-
enumerator POWER_MEASURE_UNDERVOLTAGE
Undervoltage
-
enumerator POWER_MEASURE_ENERGY_REPORT
report energy
-
enumerator POWER_MEASURE_HOME_APPLIANCES_ONLINE
appliances online
-
enumerator POWER_MEASURE_HOME_APPLIANCES_OFFLINE
appliances offline
-
enumerator POWER_MEASURE_INIT_DONE