no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pqlib_example.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file pqlib_example.h
3 * @brief Header file for pqlib display example functions
4 * @author Robert Budai (robert.budai@analog.com)
5 ********************************************************************************
6 * Copyright (c) 2024 Analog Devices, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33
34#ifndef __PQLIB_EXAMPLE_H__
35#define __PQLIB_EXAMPLE_H__
36
37#include "ade9430.h"
38#include "adi_pqlib.h"
39#include "adi_pqlib_memory.h"
40#include "adi_pqlib_profile.h"
41#include "pqlib_convert.h"
42#include "status.h"
43#include <stddef.h>
45
46#define PQLIB_MAX_CHANNELS 7
47#define ADI_PQLIB_NUM_WAVEFORM_BLOCKS 4
48#define PQLIB_MAX_HARMONICS 50
49#define PQLIB_MAX_INTER_HARMONICS 50
50#define SIZE_OF_INPUT_RTC 19
51
61
73
77typedef struct {
83 uint8_t maxHarmonics;
92 uint32_t cyclesToRun;
94 uint32_t correction;
96 uint64_t syncTime;
116 ADI_PQLIB_REF_CHANNEL refChannel;
117 ADI_PQLIB_CORR_COEF correctionData;
118 ADI_PQLIB_FLICKER_MODEL flickerModel;
119 ADI_PQLIB_PHASE_MAP phaseMap;
121
122} EXAMPLE_CONFIG; // pqlib example config
123
124typedef struct {
125
129 uint16_t syncCycles;
132 uint32_t timeOutCount;
133 uint32_t pqlibStateMemory[ADI_PQLIB_STATE_MEM_NUM_BYTES / 4];
134 uint32_t pqlibTempMemory[ADI_PQLIB_TEMP_MEM_NUM_BYTES / 4];
136 char *pChannel;
137 ADI_PQLIB_HANDLE hDevice;
138 ADI_PQLIB_CONFIG config;
139 ADI_PQLIB_CYCLE_INPUT inputCycle;
140 ADI_PQLIB_1012_CYCLE_INPUT input1012Cycles;
141 ADI_PQLIB_WAVEFORM inputWaveform;
143 ADI_PQLIB_OUTPUT *output;
144 ADI_PQLIB_PHASE_MAP channelMap;
147
148} PQLIB_EXAMPLE; // pqlib example struct
149
155int pqm_one_cycle(void);
156
166 ADI_PQLIB_RESULT pqlibStatus);
167
173int open_pqlib(PQLIB_EXAMPLE *pExample);
174
185int SyncLibTime(PQLIB_EXAMPLE *pExample, bool checkRtcTime);
186
197int config_measurement(PQLIB_EXAMPLE *pExample);
198
206
215void populate_event_config(EXAMPLE_CONFIG *pExampleConfig);
216
231int cpy_correction_coeffs(ADI_PQLIB_NOMINAL_FREQUENCY nominalFrequency,
232 ADI_PQLIB_CORR_COEF *pCorrCoef);
233
248 ADI_PQLIB_RESULT pqlibStatus);
249
256void SyncToDip(PQLIB_EXAMPLE *pExample, ADI_PQLIB_RESULT pqlibStatus);
257
259
265int pqm_measurement_init(void);
266
275int pqm_start_measurement(bool waitingForSync);
276
292
293#endif /* __PQLIB_EXAMPLE_H__ */
Header file of ADE9430 Driver.
Circular buffer library header.
PQLIB_EXAMPLE pqlibExample
Definition pqlib_example.c:37
VCONSEL_CONFIG
VCONSEL H/W config selection.
Definition pqlib_example.h:66
@ VCONSEL_4W_WYE
Definition pqlib_example.h:67
@ VCONSEL_4W_WYE_VB_NEGVA_NEGVC
Definition pqlib_example.h:69
@ VCONSEL_4W_DELTA_VA_VB_VC
Definition pqlib_example.h:71
@ VCONSEL_4W_DELTA_VB_NEGVA
Definition pqlib_example.h:70
@ VCONSEL_3W_DELTA_VB_VA_NEGVC
Definition pqlib_example.h:68
int process_and_prepare_output()
The function gets AFE input and calls main processing APIs of the library. This also gets the measure...
Definition pqlib_example.c:201
PQLIB_STATE
PQLIB Example states.
Definition pqlib_example.h:56
@ PQLIB_STATE_WAITING_FOR_START_CMD
Definition pqlib_example.h:57
@ PQLIB_STATE_RUNNING
Definition pqlib_example.h:59
@ PQLIB_STATE_WAITING_FOR_TRIGGER
Definition pqlib_example.h:58
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 ev...
Definition pqlib_example.c:548
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...
Definition pqlib_example.c:285
void populate_event_config(EXAMPLE_CONFIG *pExampleConfig)
Populates event configuration using user configuration Serves as an example on how to convert thresho...
Definition pqlib_example.c:364
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....
Definition pqlib_example.c:400
#define PQLIB_MAX_CHANNELS
Definition pqlib_example.h:46
int pqm_start_measurement(bool waitingForSync)
Starts Power Quality measurement as per configured cycles.
Definition pqlib_example.c:56
#define PQLIB_MAX_INTER_HARMONICS
Definition pqlib_example.h:49
int pqm_measurement_init(void)
Initializes Power Quality Measurement.
Definition pqlib_example.c:41
int open_pqlib(PQLIB_EXAMPLE *pExample)
Call adi_pqlib_Open with required buffers. Serves as an example how to call adi_pqlib_Open API.
Definition pqlib_example.c:117
void set_default_config(EXAMPLE_CONFIG *pConfig)
Sets default configuration of the example as floating points Note that this function doesn't configur...
Definition pqlib_example.c:466
int SyncLibTime(PQLIB_EXAMPLE *pExample, bool checkRtcTime)
Sets library internal time using RTC time. Serves as an example how to call the APIs....
Definition pqlib_example.c:520
int config_measurement(PQLIB_EXAMPLE *pExample)
Configures AFE and the library . This serves as an example on how to call APIs adi_pqlib_SetConfig an...
Definition pqlib_example.c:134
#define SIZE_OF_INPUT_RTC
Definition pqlib_example.h:50
#define PQLIB_MAX_HARMONICS
Definition pqlib_example.h:48
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 f...
Definition pqlib_example.c:449
int pqm_one_cycle(void)
One complete cycle for IIO callback function.
Definition pqlib_example.c:105
Definition pqlib_example.h:77
float dipHysteresis
Definition pqlib_example.h:98
float msvRecordingLength
Definition pqlib_example.h:107
uint32_t cyclesToRun
Definition pqlib_example.h:92
uint32_t correction
Definition pqlib_example.h:94
uint8_t harmonics[PQLIB_MAX_HARMONICS]
Definition pqlib_example.h:81
uint16_t currentCorrCoef[PQLIB_MAX_HARMONICS]
Definition pqlib_example.h:86
float inputCurrentCorrCoef60Hz[PQLIB_MAX_HARMONICS]
Definition pqlib_example.h:113
ADI_PQLIB_REF_CHANNEL refChannel
Definition pqlib_example.h:116
char * pEnabledChannels[PQLIB_MAX_CHANNELS]
Definition pqlib_example.h:115
uint16_t numCorrCoefVoltage50Hz
Definition pqlib_example.h:89
uint32_t zeroCrossingCheck
Definition pqlib_example.h:95
uint8_t maxInterHarmonics
Definition pqlib_example.h:84
float intrpThreshold
Definition pqlib_example.h:101
ADI_PQLIB_PHASE_MAP phaseMap
Definition pqlib_example.h:119
float rvcThreshold
Definition pqlib_example.h:103
uint32_t nominalFrequency
Definition pqlib_example.h:93
float rvcHysteresis
Definition pqlib_example.h:104
float intrpHysteresis
Definition pqlib_example.h:102
uint64_t syncTime
Definition pqlib_example.h:96
float dipThreshold
Definition pqlib_example.h:97
ADI_PQLIB_CORR_COEF correctionData
Definition pqlib_example.h:117
VCONSEL_CONFIG vconsel
Definition pqlib_example.h:120
float currentScale
Definition pqlib_example.h:109
uint16_t numCorrCoefCurrent50Hz
Definition pqlib_example.h:88
float swellThreshold
Definition pqlib_example.h:99
float inputVoltageCorrCoef60Hz[PQLIB_MAX_HARMONICS]
Definition pqlib_example.h:114
float swellHysteresis
Definition pqlib_example.h:100
float inputVoltageCorrCoef50Hz[PQLIB_MAX_HARMONICS]
Definition pqlib_example.h:112
float msvThreshold
Definition pqlib_example.h:105
float nominalVoltage
Definition pqlib_example.h:110
float msvCarrierFrequency
Definition pqlib_example.h:106
uint16_t numCorrCoefVoltage60Hz
Definition pqlib_example.h:91
bool enableIconsel
Definition pqlib_example.h:79
uint8_t maxHarmonics
Definition pqlib_example.h:83
uint16_t numCorrCoefCurrent60Hz
Definition pqlib_example.h:90
uint16_t voltageCorrCoef[PQLIB_MAX_HARMONICS]
Definition pqlib_example.h:87
uint8_t interHarmonics[PQLIB_MAX_INTER_HARMONICS]
Definition pqlib_example.h:82
float inputCurrentCorrCoef50Hz[PQLIB_MAX_HARMONICS]
Definition pqlib_example.h:111
bool enableRTCSync
Definition pqlib_example.h:78
bool useExternalTimestamp
Definition pqlib_example.h:80
float voltageScale
Definition pqlib_example.h:108
ADI_PQLIB_FLICKER_MODEL flickerModel
Definition pqlib_example.h:118
uint8_t rtcBuff[SIZE_OF_INPUT_RTC]
Definition pqlib_example.h:85
Definition pqlib_example.h:124
ADI_PQLIB_OUTPUT * output
Definition pqlib_example.h:143
ADI_PQLIB_HANDLE hDevice
Definition pqlib_example.h:137
uint32_t pqlibStateMemory[ADI_PQLIB_STATE_MEM_NUM_BYTES/4]
Definition pqlib_example.h:133
bool waitingForSync
Definition pqlib_example.h:127
uint32_t processedCycles
Definition pqlib_example.h:130
uint16_t syncCycles
Definition pqlib_example.h:129
uint32_t timeOutCount
Definition pqlib_example.h:132
float calExpectedRms
Definition pqlib_example.h:135
ADI_PQLIB_1012_CYCLE_INPUT input1012Cycles
Definition pqlib_example.h:140
uint32_t pqlibTempMemory[ADI_PQLIB_TEMP_MEM_NUM_BYTES/4]
Definition pqlib_example.h:134
char * pChannel
Definition pqlib_example.h:136
bool readyToDisplay
Definition pqlib_example.h:126
ADI_PQLIB_WAVEFORM inputWaveform
Definition pqlib_example.h:141
struct no_os_circular_buffer * no_os_cb_desc
Definition pqlib_example.h:146
PQLIB_STATE state
Definition pqlib_example.h:145
EXAMPLE_CONFIG exampleConfig
Definition pqlib_example.h:142
ADI_PQLIB_CYCLE_INPUT inputCycle
Definition pqlib_example.h:139
uint32_t zeroCrossingCount
Definition pqlib_example.h:131
bool calibration
Definition pqlib_example.h:128
ADI_PQLIB_PHASE_MAP channelMap
Definition pqlib_example.h:144
ADI_PQLIB_CONFIG config
Definition pqlib_example.h:138
Circular buffer descriptor.
Definition no_os_circular_buffer.h:59