no-OS
Classes | Macros | Enumerations | Functions | Variables
pqlib_example.h File Reference
#include "ade9430.h"
#include "adi_pqlib.h"
#include "adi_pqlib_memory.h"
#include "adi_pqlib_profile.h"
#include "pqlib_convert.h"
#include "status.h"
#include <stddef.h>
#include "no_os_circular_buffer.h"
Include dependency graph for pqlib_example.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  EXAMPLE_CONFIG
 
struct  PQLIB_EXAMPLE
 

Macros

#define PQLIB_MAX_CHANNELS   7
 
#define ADI_PQLIB_NUM_WAVEFORM_BLOCKS   4
 
#define PQLIB_MAX_HARMONICS   50
 
#define PQLIB_MAX_INTER_HARMONICS   50
 
#define SIZE_OF_INPUT_RTC   19
 

Enumerations

enum  PQLIB_STATE {
  PQLIB_STATE_WAITING_FOR_START_CMD,
  PQLIB_STATE_WAITING_FOR_TRIGGER,
  PQLIB_STATE_RUNNING
}
 PQLIB Example states. More...
 
enum  VCONSEL_CONFIG {
  VCONSEL_4W_WYE,
  VCONSEL_3W_DELTA_VB_VA_NEGVC,
  VCONSEL_4W_WYE_VB_NEGVA_NEGVC,
  VCONSEL_4W_DELTA_VB_NEGVA,
  VCONSEL_4W_DELTA_VA_VB_VC
}
 VCONSEL H/W config selection. More...
 

Functions

int pqm_one_cycle (void)
 One complete cycle for IIO callback function. More...
 
int process_pqlib_error (PQLIB_EXAMPLE *pExample, ADI_PQLIB_RESULT pqlibStatus)
 Prints error message for errors from the library. Serves as an examples on how to handle the errors from the library. More...
 
int open_pqlib (PQLIB_EXAMPLE *pExample)
 Call adi_pqlib_Open with required buffers. Serves as an example how to call adi_pqlib_Open API. More...
 
int SyncLibTime (PQLIB_EXAMPLE *pExample, bool checkRtcTime)
 Sets library internal time using RTC time. Serves as an example how to call the APIs. This also syncs the library time to the user provided time. More...
 
int config_measurement (PQLIB_EXAMPLE *pExample)
 Configures AFE and the library . This serves as an example on how to call APIs adi_pqlib_SetConfig and adi_pqlib_SetCorrectionCoefficients. More...
 
void set_default_config (EXAMPLE_CONFIG *pConfig)
 Sets default configuration of the example as floating points Note that this function doesn't configure the library or AFE. More...
 
void populate_event_config (EXAMPLE_CONFIG *pExampleConfig)
 Populates event configuration using user configuration Serves as an example on how to convert thresholds and hysteresis to the form required by the API. More...
 
int cpy_correction_coeffs (ADI_PQLIB_NOMINAL_FREQUENCY nominalFrequency, ADI_PQLIB_CORR_COEF *pCorrCoef)
 Copies the user provided correction factors to the interface structure. This shows how floating point correction factors can be converted to the format required by adi_pqlib_SetCorrectionCoefficients Requires both current and voltage pointers should be populated. The code assumes numCorrCoef is same for both and if it is less than 40 these are last 'N' coefficients. More...
 
int wait_for_zero_crossing (PQLIB_EXAMPLE *pExample, ADI_PQLIB_RESULT pqlibStatus)
 Looks at the return code from library and checks whether there is a zero crossing timeout. This is only needed for testing. We wanted to know when actual signal comes and start monitoring test output only after a predefined settling time. More...
 
void SyncToDip (PQLIB_EXAMPLE *pExample, ADI_PQLIB_RESULT pqlibStatus)
 Sync the time to a dip or interruption event. Serves as an example how to sync to an external time event. More...
 
int pqm_measurement_init (void)
 Initializes Power Quality Measurement. More...
 
int pqm_start_measurement (bool waitingForSync)
 Starts Power Quality measurement as per configured cycles. More...
 
int process_and_prepare_output ()
 The function gets AFE input and calls main processing APIs of the library. This also gets the measurement parameter output from the library and displays it on the console. More...
 

Variables

PQLIB_EXAMPLE pqlibExample
 

Macro Definition Documentation

◆ ADI_PQLIB_NUM_WAVEFORM_BLOCKS

#define ADI_PQLIB_NUM_WAVEFORM_BLOCKS   4

◆ PQLIB_MAX_CHANNELS

#define PQLIB_MAX_CHANNELS   7

◆ PQLIB_MAX_HARMONICS

#define PQLIB_MAX_HARMONICS   50

◆ PQLIB_MAX_INTER_HARMONICS

#define PQLIB_MAX_INTER_HARMONICS   50

◆ SIZE_OF_INPUT_RTC

#define SIZE_OF_INPUT_RTC   19

Enumeration Type Documentation

◆ PQLIB_STATE

PQLIB Example states.

Enumerator
PQLIB_STATE_WAITING_FOR_START_CMD 
PQLIB_STATE_WAITING_FOR_TRIGGER 
PQLIB_STATE_RUNNING 

◆ VCONSEL_CONFIG

VCONSEL H/W config selection.

Enumerator
VCONSEL_4W_WYE 
VCONSEL_3W_DELTA_VB_VA_NEGVC 
VCONSEL_4W_WYE_VB_NEGVA_NEGVC 
VCONSEL_4W_DELTA_VB_NEGVA 
VCONSEL_4W_DELTA_VA_VB_VC 

Function Documentation

◆ config_measurement()

int config_measurement ( PQLIB_EXAMPLE pExample)

Configures AFE and the library . This serves as an example on how to call APIs adi_pqlib_SetConfig and adi_pqlib_SetCorrectionCoefficients.

Parameters
[in]pExample- Pointer to structure for example configurations.
Returns
0 on success 1 on failure
Here is the caller graph for this function:

◆ cpy_correction_coeffs()

int cpy_correction_coeffs ( ADI_PQLIB_NOMINAL_FREQUENCY  nominalFrequency,
ADI_PQLIB_CORR_COEF *  pCorrCoef 
)

Copies the user provided correction factors to the interface structure. This shows how floating point correction factors can be converted to the format required by adi_pqlib_SetCorrectionCoefficients Requires both current and voltage pointers should be populated. The code assumes numCorrCoef is same for both and if it is less than 40 these are last 'N' coefficients.

Parameters
[in]nominalFrequency- structure for nominal frequency
[in]pCorrCoef- pointer to structure for correctionCoefficients
Returns
0 on Success 1 on Copy is not success because both current and voltage correction coefficients are not available.
Here is the caller graph for this function:

◆ open_pqlib()

int open_pqlib ( PQLIB_EXAMPLE pExample)

Call adi_pqlib_Open with required buffers. Serves as an example how to call adi_pqlib_Open API.

Parameters
[in]pExample- Pointer to main example structure.
Here is the caller graph for this function:

◆ populate_event_config()

void populate_event_config ( EXAMPLE_CONFIG pExampleConfig)

Populates event configuration using user configuration Serves as an example on how to convert thresholds and hysteresis to the form required by the API.

Parameters
[in]pExampleConfig- pointer to structure for example configurations.
Here is the caller graph for this function:

◆ pqm_measurement_init()

int pqm_measurement_init ( void  )

Initializes Power Quality Measurement.

Returns
0 on Success 1 on Failure
Here is the caller graph for this function:

◆ pqm_one_cycle()

int pqm_one_cycle ( void  )

One complete cycle for IIO callback function.

Returns
0 - on success, different from 0 otherwise

◆ pqm_start_measurement()

int pqm_start_measurement ( bool  waitingForSync)

Starts Power Quality measurement as per configured cycles.

Parameters
[in]waitingForSync- Flag to indicate whether the code should look for a sync event to synchronize the RTC time.
Returns
0 on Success 1 on Failure
Here is the caller graph for this function:

◆ process_and_prepare_output()

int process_and_prepare_output ( )

The function gets AFE input and calls main processing APIs of the library. This also gets the measurement parameter output from the library and displays it on the console.

This serves as an example for the APIs adi_pqlib_ProcessOneCycle adi_pqlib_ProcessWaveform adi_pqlib_Process1012Cycles adi_pqlib_GetOutputStatus

Returns
0 on Success 1 on Failure
Here is the caller graph for this function:

◆ process_pqlib_error()

int process_pqlib_error ( PQLIB_EXAMPLE pExample,
ADI_PQLIB_RESULT  pqlibStatus 
)

Prints error message for errors from the library. Serves as an examples on how to handle the errors from the library.

Parameters
[in]pExample- Pointer to PQLIB_EXAMPLE structure.
[in]pqlibStatus- return code for the library.
Returns
0 - Error handled successfully. 1 - Fatal error.
Here is the caller graph for this function:

◆ set_default_config()

void set_default_config ( EXAMPLE_CONFIG pConfig)

Sets default configuration of the example as floating points Note that this function doesn't configure the library or AFE.

Parameters
[in]pConfig- Pointer to example configuration structure.
Here is the caller graph for this function:

◆ SyncLibTime()

int SyncLibTime ( PQLIB_EXAMPLE pExample,
bool  checkRtcTime 
)

Sets library internal time using RTC time. Serves as an example how to call the APIs. This also syncs the library time to the user provided time.

Parameters
[in]pExample- Pointer to example structure.
[in]checkRtcTime- Checks RTC time.
Returns
0 on success 1 on failure
Here is the caller graph for this function:

◆ SyncToDip()

void SyncToDip ( PQLIB_EXAMPLE pExample,
ADI_PQLIB_RESULT  pqlibStatus 
)

Sync the time to a dip or interruption event. Serves as an example how to sync to an external time event.

Parameters
[in]pExample- Pointer to example structure.
[in]pqlibStatus- Status from adi_pqlib_ProcessOneCycle.
Here is the caller graph for this function:

◆ wait_for_zero_crossing()

int wait_for_zero_crossing ( PQLIB_EXAMPLE pExample,
ADI_PQLIB_RESULT  pqlibStatus 
)

Looks at the return code from library and checks whether there is a zero crossing timeout. This is only needed for testing. We wanted to know when actual signal comes and start monitoring test output only after a predefined settling time.

Parameters
[in]pExample- Pointer to PQLIB_EXAMPLE structure
[in]pqlibStatus- return code for the library
Returns
SYS_STATUS_NO_SIGNAL - If no signal comes within timeout period SYS_STATUS_PQLIB_RUNNING - We are waiting for zerocrossing SYS_STATUS_SUCCESS -We have received enough zero crossing and good to process 10/12 cycle inputs from the library
Here is the caller graph for this function:

Variable Documentation

◆ pqlibExample

PQLIB_EXAMPLE pqlibExample