#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
|
| enum | CALIBRATION_STATE {
CALIBRATION_STATE_IDLE
,
CALIBRATION_STATE_INIT
,
CALIBRATION_STATE_COLLECTING
,
CALIBRATION_STATE_CALCULATING
,
CALIBRATION_STATE_CALCULATE_ERROR_BEFORE
,
CALIBRATION_STATE_WRITING
,
CALIBRATION_STATE_VERIFY_COLLECTING
,
CALIBRATION_STATE_VERIFY_CALCULATING
,
CALIBRATION_STATE_DONE
,
CALIBRATION_STATE_ERROR
} |
| | Calibration state machine states. More...
|
| |
| enum | CALIBRATION_TYPE {
CALIBRATION_TYPE_GAIN
,
CALIBRATION_TYPE_OFFSET
} |
| | Calibration type (gain or offset) More...
|
| |
| enum | CALIBRATION_PHASE {
CALIBRATION_PHASE_A = 0
,
CALIBRATION_PHASE_B = 1
,
CALIBRATION_PHASE_C = 2
} |
| | Phase selection for calibration. More...
|
| |
◆ ADI_PQLIB_MAX_RMS_VALUE_CAL
| #define ADI_PQLIB_MAX_RMS_VALUE_CAL 52702092 |
◆ CALIBRATION_CYCLES_50HZ
| #define CALIBRATION_CYCLES_50HZ 150 |
◆ CALIBRATION_CYCLES_60HZ
| #define CALIBRATION_CYCLES_60HZ 180 |
◆ GAIN_SCALE_FACTOR
| #define GAIN_SCALE_FACTOR (1LL << 27) /* 2^27 */ |
◆ OFFSET_REG_MAX
| #define OFFSET_REG_MAX ((1L << 23) - 1) /* +8388607 */ |
◆ OFFSET_REG_MIN
| #define OFFSET_REG_MIN (-(1L << 23)) /* -8388608 */ |
◆ OFFSET_SCALE_FACTOR
| #define OFFSET_SCALE_FACTOR (1LL << 15) /* 2^15 */ |
◆ SQRT_2
| #define SQRT_2 1.41421356f |
◆ CALIBRATION_PHASE
Phase selection for calibration.
| Enumerator |
|---|
| CALIBRATION_PHASE_A | |
| CALIBRATION_PHASE_B | |
| CALIBRATION_PHASE_C | |
◆ CALIBRATION_STATE
Calibration state machine states.
| Enumerator |
|---|
| CALIBRATION_STATE_IDLE | |
| CALIBRATION_STATE_INIT | |
| CALIBRATION_STATE_COLLECTING | |
| CALIBRATION_STATE_CALCULATING | |
| CALIBRATION_STATE_CALCULATE_ERROR_BEFORE | |
| CALIBRATION_STATE_WRITING | |
| CALIBRATION_STATE_VERIFY_COLLECTING | |
| CALIBRATION_STATE_VERIFY_CALCULATING | |
| CALIBRATION_STATE_DONE | |
| CALIBRATION_STATE_ERROR | |
◆ CALIBRATION_TYPE
Calibration type (gain or offset)
| Enumerator |
|---|
| CALIBRATION_TYPE_GAIN | |
| CALIBRATION_TYPE_OFFSET | |
◆ calculate_error()
| float calculate_error |
( |
int32_t | measured, |
|
|
int32_t | expected ) |
Calculate error percentage.
- Parameters
-
| measured | - Measured value |
| expected | - Expected value |
- Returns
- Error as percentage (e.g., 0.01 = 1%)
◆ calculate_expected_irms()
| uint32_t calculate_expected_irms |
( |
const CALIBRATION_INPUT * | input, |
|
|
float | rms_value ) |
Calculate expected RMS value for current.
- Parameters
-
| input | - Calibration input parameters |
| rms_value | - RMS value in Arms |
- Returns
- Expected register value
◆ calculate_expected_vrms()
| uint32_t calculate_expected_vrms |
( |
const CALIBRATION_INPUT * | input, |
|
|
float | rms_value ) |
Calculate expected RMS value for voltage.
- Parameters
-
| input | - Calibration input parameters |
| rms_value | - RMS value in Vrms |
- Returns
- Expected register value
◆ calculate_gain()
| int32_t calculate_gain |
( |
int32_t | expected, |
|
|
int32_t | measured ) |
Calculate gain coefficient.
- Parameters
-
| expected | - Expected RMS value |
| measured | - Measured RMS value |
- Returns
- Gain coefficient (signed 32-bit)
◆ calculate_rms_without_gain()
| int32_t calculate_rms_without_gain |
( |
int32_t | measured, |
|
|
int32_t | gain ) |
Calculate RMS without gain coefficient.
- Parameters
-
| measured | - Measured RMS value |
| gain | - Gain register value |
- Returns
- rms value without gain (signed 32-bit)
◆ calculate_rms_without_rmsos()
| int32_t calculate_rms_without_rmsos |
( |
int32_t | measured, |
|
|
int32_t | xrmsos ) |
Calculate RMS value without offset coefficient.
- Parameters
-
| measured | - Measured RMS value |
| xrmsos | - RMSOS register value |
- Returns
- rms value without offset (signed 32-bit)
◆ calculate_rmsos()
| int32_t calculate_rmsos |
( |
int32_t | expected, |
|
|
int32_t | measured ) |
Calculate RMS offset coefficient.
- Parameters
-
| expected | - Expected RMS value |
| measured | - Measured RMS value |
- Returns
- Offset coefficient (signed 32-bit)
◆ calibration_clear_done()
| void calibration_clear_done |
( |
void | | ) |
|
Clear calibration done flag.
◆ calibration_get_status_string()
| const char * calibration_get_status_string |
( |
void | | ) |
|
Get current calibration status string.
- Returns
- Status string ("idle", "in_progress", "done", "error")
◆ calibration_init()
| void calibration_init |
( |
void | | ) |
|
Initialize calibration context with default values.
◆ calibration_is_active()
| bool calibration_is_active |
( |
void | | ) |
|
Check if calibration is active.
- Returns
- true if calibration is in progress
◆ calibration_is_done()
| bool calibration_is_done |
( |
void | | ) |
|
Check if calibration just completed.
- Returns
- true if calibration was just done (result.done is true)
◆ calibration_process_cycle()
| int calibration_process_cycle |
( |
void | | ) |
|
Process one calibration cycle (called from main loop)
- Returns
- 0 on success, error code otherwise
◆ calibration_start()
Start calibration process.
- Parameters
-
| type | - Calibration type (gain or offset) |
| phase | - Phase to calibrate (A, B, or C) |
- Returns
- 0 on success, error code otherwise
◆ calibrationCtx