3-phase PV router
|
Implements the processing engine. More...
#include <Arduino.h>
#include "calibration.h"
#include "dualtariff.h"
#include "processing.h"
#include "utils_pins.h"
Go to the source code of this file.
Functions | |
void | confirmPolarity (const uint8_t phase) |
This routine prevents a zero-crossing point from being declared until a certain number of consecutive samples in the 'other' half of the waveform have been encountered. | |
void | initializeOptionalPins () |
Initializes the optional pins. | |
void | initializeProcessing () |
Initializes the ports and load states for processing. | |
constexpr auto | initThreshold (const bool lower) |
set default threshold at compile time so the variable can be read-only | |
uint8_t | nextLogicalLoadToBeAdded () |
Retrieve the next load that could be added (be aware of the order) | |
uint8_t | nextLogicalLoadToBeRemoved () |
Retrieve the next load that could be removed (be aware of the reverse-order) | |
void | printParamsForSelectedOutputMode () |
Print the settings used for the selected output mode. | |
void | proceedHighEnergyLevel () |
Process the case of high energy level, some action may be required. | |
void | proceedLowEnergyLevel () |
Process the case of low energy level, some action may be required. | |
void | processCurrentRawSample (const uint8_t phase, const int16_t rawSample) |
Process the calculation for the actual current raw sample for the specific phase. | |
void | processDataLogging () |
Process with data logging. | |
void | processLatestContribution (const uint8_t phase) |
Process the latest contribution after each phase specific new cycle additional processing is performed after each main cycle based on phase 0. | |
void | processMinusHalfCycle (const uint8_t phase) |
Process the start of a new -ve half cycle, for this phase, just after the zero-crossing point. | |
void | processPlusHalfCycle (const uint8_t phase) |
Process the start of a new +ve half cycle, for this phase, just after the zero-crossing point. | |
void | processPolarity (const uint8_t phase, const int16_t rawSample) |
Process with the polarity for the actual voltage sample for the specific phase. | |
void | processRawSamples (const uint8_t phase) |
This routine is called by the ISR when a pair of V & I sample becomes available. | |
void | processStartNewCycle () |
This code is executed once per 20mS, shortly after the start of each new mains cycle on phase 0. | |
void | processStartUp (const uint8_t phase) |
Process the startup period for the router. | |
void | processVoltage (const uint8_t phase) |
Process the calculation for the current voltage sample for the specific phase. | |
void | processVoltageRawSample (const uint8_t phase, const int16_t rawSample) |
Process the current voltage raw sample for the specific phase. | |
void | updatePhysicalLoadStates () |
This function provides the link between the logical and physical loads. | |
void | updatePortsStates () |
update the control ports for each of the physical loads | |
Implements the processing engine.
Definition in file processing.cpp.
void initializeOptionalPins | ( | ) |
Initializes the optional pins.
Definition at line 143 of file processing.cpp.
void initializeProcessing | ( | ) |
Initializes the ports and load states for processing.
Definition at line 91 of file processing.cpp.
|
constexpr |
set default threshold at compile time so the variable can be read-only
lower | True to set the lower threshold, false for higher |
Definition at line 43 of file processing.cpp.
void printParamsForSelectedOutputMode | ( | ) |
Print the settings used for the selected output mode.
Definition at line 799 of file processing.cpp.
void updatePortsStates | ( | ) |
update the control ports for each of the physical loads
Definition at line 190 of file processing.cpp.
uint8_t activeLoad { NO_OF_DUMPLOADS } |
current active load
Definition at line 62 of file processing.cpp.
bool b_recentTransition { false } |
a load state has been recently toggled
Definition at line 58 of file processing.cpp.
bool beyondStartUpPeriod { false } |
start-up delay, allows things to settle
Definition at line 85 of file processing.cpp.
uint16_t countLoadON[NO_OF_DUMPLOADS] |
Number of cycle the load was ON (over 1 datalog period)
Definition at line 83 of file processing.cpp.
|
constexpr |
for resetting flexible thresholds
Definition at line 29 of file processing.cpp.
float f_energyInBucket_main { 0.0F } |
main energy bucket (over all phases)
Definition at line 53 of file processing.cpp.
float f_lowerEnergyThreshold |
dynamic lower threshold
Definition at line 54 of file processing.cpp.
|
constexpr |
lower default threshold set accordingly to the output mode
Definition at line 50 of file processing.cpp.
|
constexpr |
threshold in anti-flicker mode - must not exceed 0.4
Definition at line 31 of file processing.cpp.
|
constexpr |
Definition at line 33 of file processing.cpp.
float f_upperEnergyThreshold |
dynamic upper threshold
Definition at line 55 of file processing.cpp.
|
constexpr |
upper default threshold set accordingly to the output mode
Definition at line 51 of file processing.cpp.
|
constexpr |
nominal mid-point value of ADC @ x1 scale
Definition at line 24 of file processing.cpp.
uint16_t i_sampleSetsDuringThisDatalogPeriod |
number of sample sets during each datalogging period
Definition at line 71 of file processing.cpp.
int32_t l_cumVdeltasThisCycle[NO_OF_PHASES] |
for the LPF which determines DC offset (voltage)
Definition at line 66 of file processing.cpp.
int32_t l_DCoffset_V[NO_OF_PHASES] |
<— for LPF main energy bucket for 3-phase use, with units of Joules * SUPPLY_FREQUENCY
Definition at line 26 of file processing.cpp.
|
constexpr |
mid-point of ADC plus a working margin
Definition at line 23 of file processing.cpp.
|
constexpr |
mid-point of ADC minus a working margin
Definition at line 22 of file processing.cpp.
int32_t l_sampleVminusDC[NO_OF_PHASES] |
current raw voltage sample filtered
Definition at line 65 of file processing.cpp.
int32_t l_sum_Vsquared[NO_OF_PHASES] |
for summation of V^2 values during datalog period
Definition at line 68 of file processing.cpp.
int32_t l_sumP[NO_OF_PHASES] |
cumulative power per phase
Definition at line 64 of file processing.cpp.
int32_t l_sumP_atSupplyPoint[NO_OF_PHASES] |
for summation of 'real power' values during datalog period
Definition at line 67 of file processing.cpp.
remove_cv<remove_reference<decltype(DATALOG_PERIOD_IN_MAINS_CYCLES)>::type>::type n_cycleCountForDatalogging { 0 } |
for counting how often datalog is updated
Definition at line 73 of file processing.cpp.
uint8_t n_lowestNoOfSampleSetsPerMainsCycle |
For a mechanism to check the integrity of this code structure
Definition at line 75 of file processing.cpp.
uint8_t n_samplesDuringThisMainsCycle[NO_OF_PHASES] |
number of sample sets for each phase during each mains cycle
Definition at line 70 of file processing.cpp.
|
constexpr |
Output mode to be used
Definition at line 35 of file processing.cpp.
LoadStates physicalLoadState[NO_OF_DUMPLOADS] |
Physical state of the loads
Definition at line 82 of file processing.cpp.
Polarities polarityConfirmed[NO_OF_PHASES] |
for zero-crossing detection
Definition at line 79 of file processing.cpp.
Polarities polarityConfirmedOfLastSampleV[NO_OF_PHASES] |
for zero-crossing detection
Definition at line 80 of file processing.cpp.
Polarities polarityOfMostRecentSampleV[NO_OF_PHASES] |
for zero-crossing detection
Definition at line 78 of file processing.cpp.
|
constexpr |
allows each transition to take effect
Definition at line 60 of file processing.cpp.
uint8_t postTransitionCount |
counts the number of cycle since last transition
Definition at line 59 of file processing.cpp.