![]() |
no-OS
|
#include <stdint.h>#include <stdbool.h>Classes | |
| struct | CALIBRATION_INPUT |
| Calibration input parameters (user-provided values) More... | |
| struct | CALIBRATION_RESULT |
| Calibration results (computed values) More... | |
| struct | CALIBRATION_CONTEXT |
| Calibration state structure (runtime state) More... | |
Macros | |
| #define | ADI_PQLIB_MAX_RMS_VALUE_CAL 52702092 |
| #define | CALIBRATION_CYCLES_50HZ 150 |
| #define | CALIBRATION_CYCLES_60HZ 180 |
| #define | SQRT_2 1.41421356f |
| #define | GAIN_SCALE_FACTOR (1LL << 27) /* 2^27 */ |
| #define | OFFSET_SCALE_FACTOR (1LL << 15) /* 2^15 */ |
| #define | OFFSET_REG_MAX ((1L << 23) - 1) /* +8388607 */ |
| #define | OFFSET_REG_MIN (-(1L << 23)) /* -8388608 */ |
Enumerations | |
| 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... | |
Functions | |
| void | calibration_init (void) |
| Initialize calibration context with default values. | |
| int | calibration_start (CALIBRATION_TYPE type, CALIBRATION_PHASE phase) |
| Start calibration process. | |
| int | calibration_process_cycle (void) |
| Process one calibration cycle (called from main loop) | |
| bool | calibration_is_active (void) |
| Check if calibration is active. | |
| bool | calibration_is_done (void) |
| Check if calibration just completed. | |
| void | calibration_clear_done (void) |
| Clear calibration done flag. | |
| const char * | calibration_get_status_string (void) |
| Get current calibration status string. | |
| uint32_t | calculate_expected_irms (const CALIBRATION_INPUT *input, float rms_value) |
| Calculate expected RMS value for current. | |
| uint32_t | calculate_expected_vrms (const CALIBRATION_INPUT *input, float rms_value) |
| Calculate expected RMS value for voltage. | |
| int32_t | calculate_gain (int32_t expected, int32_t measured) |
| Calculate gain coefficient. | |
| int32_t | calculate_rms_without_gain (int32_t measured, int32_t gain) |
| Calculate RMS without gain coefficient. | |
| int32_t | calculate_rmsos (int32_t expected, int32_t measured) |
| Calculate RMS offset coefficient. | |
| int32_t | calculate_rms_without_rmsos (int32_t measured, int32_t xrmsos) |
| Calculate RMS value without offset coefficient. | |
| float | calculate_error (int32_t measured, int32_t expected) |
| Calculate error percentage. | |
Variables | |
| CALIBRATION_CONTEXT | calibrationCtx |
| #define ADI_PQLIB_MAX_RMS_VALUE_CAL 52702092 |
| #define CALIBRATION_CYCLES_50HZ 150 |
| #define CALIBRATION_CYCLES_60HZ 180 |
| #define GAIN_SCALE_FACTOR (1LL << 27) /* 2^27 */ |
| #define OFFSET_REG_MAX ((1L << 23) - 1) /* +8388607 */ |
| #define OFFSET_REG_MIN (-(1L << 23)) /* -8388608 */ |
| #define OFFSET_SCALE_FACTOR (1LL << 15) /* 2^15 */ |
| #define SQRT_2 1.41421356f |
| enum CALIBRATION_PHASE |
| enum CALIBRATION_STATE |
Calibration state machine states.
| enum CALIBRATION_TYPE |
| float calculate_error | ( | int32_t | measured, |
| int32_t | expected ) |
Calculate error percentage.
| measured | - Measured value |
| expected | - Expected value |
| uint32_t calculate_expected_irms | ( | const CALIBRATION_INPUT * | input, |
| float | rms_value ) |
Calculate expected RMS value for current.
| input | - Calibration input parameters |
| rms_value | - RMS value in Arms |
| uint32_t calculate_expected_vrms | ( | const CALIBRATION_INPUT * | input, |
| float | rms_value ) |
Calculate expected RMS value for voltage.
| input | - Calibration input parameters |
| rms_value | - RMS value in Vrms |
| int32_t calculate_gain | ( | int32_t | expected, |
| int32_t | measured ) |
Calculate gain coefficient.
| expected | - Expected RMS value |
| measured | - Measured RMS value |
| int32_t calculate_rms_without_gain | ( | int32_t | measured, |
| int32_t | gain ) |
Calculate RMS without gain coefficient.
| measured | - Measured RMS value |
| gain | - Gain register value |
| int32_t calculate_rms_without_rmsos | ( | int32_t | measured, |
| int32_t | xrmsos ) |
Calculate RMS value without offset coefficient.
| measured | - Measured RMS value |
| xrmsos | - RMSOS register value |
| int32_t calculate_rmsos | ( | int32_t | expected, |
| int32_t | measured ) |
Calculate RMS offset coefficient.
| expected | - Expected RMS value |
| measured | - Measured RMS value |
| void calibration_clear_done | ( | void | ) |
Clear calibration done flag.
| const char * calibration_get_status_string | ( | void | ) |
Get current calibration status string.
| void calibration_init | ( | void | ) |
Initialize calibration context with default values.
| bool calibration_is_active | ( | void | ) |
Check if calibration is active.
| bool calibration_is_done | ( | void | ) |
Check if calibration just completed.
| int calibration_process_cycle | ( | void | ) |
Process one calibration cycle (called from main loop)
| int calibration_start | ( | CALIBRATION_TYPE | type, |
| CALIBRATION_PHASE | phase ) |
Start calibration process.
| type | - Calibration type (gain or offset) |
| phase | - Phase to calibrate (A, B, or C) |
|
extern |