no-OS
Loading...
Searching...
No Matches
afe_calibration.c File Reference
#include "afe_calibration.h"
#include "afe_config.h"
#include "ade9430.h"
#include "status.h"
#include "pqlib_example.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
Include dependency graph for afe_calibration.c:

Functions

void calibration_init (void)
 Initialize calibration context with default values.
 
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.
 
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.
 

Variables

CALIBRATION_CONTEXT calibrationCtx
 

Function Documentation

◆ 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%)
Here is the caller graph for this function:

◆ 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
Here is the caller graph for this function:

◆ 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
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ calibration_get_status_string()

const char * calibration_get_status_string ( void )

Get current calibration status string.

Returns
Status string ("idle", "in_progress", "done", "error")
Here is the caller graph for this function:

◆ calibration_init()

void calibration_init ( void )

Initialize calibration context with default values.

Here is the caller graph for this function:

◆ calibration_is_active()

bool calibration_is_active ( void )

Check if calibration is active.

Returns
true if calibration is in progress
Here is the caller graph for this function:

◆ calibration_is_done()

bool calibration_is_done ( void )

Check if calibration just completed.

Returns
true if calibration was just done (result.done is true)
Here is the caller graph for this function:

◆ calibration_process_cycle()

int calibration_process_cycle ( void )

Process one calibration cycle (called from main loop)

Returns
0 on success, error code otherwise
Here is the caller graph for this function:

◆ calibration_start()

int calibration_start ( CALIBRATION_TYPE type,
CALIBRATION_PHASE phase )

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
Here is the caller graph for this function:

Variable Documentation

◆ calibrationCtx

CALIBRATION_CONTEXT calibrationCtx