1-phase PV router
|
#include <Arduino.h>
#include "calibration.h"
#include "dualtariff.h"
#include "processing.h"
#include "utils_pins.h"
#include "utils_display.h"
Go to the source code of this file.
Functions | |
void | confirmPolarity () |
Confirms the polarity of the current voltage sample. | |
constexpr uint16_t | getInputPins () |
Retrieves the input pins configuration. | |
constexpr uint16_t | getOutputPins () |
Retrieves the output pins configuration. | |
void | initializeOldPCBPins () |
Initializes optional pins for the old PCB configuration. | |
void | initializeProcessing () |
Initializes the processing engine, including ports, load states, and ADC setup. | |
ISR (ADC_vect) | |
Interrupt Service Routine - Interrupt-Driven Analog Conversion. | |
void | logLoadPriorities () |
Prints the load priorities to the Serial output. | |
uint8_t | nextLogicalLoadToBeAdded () |
Retrieve the next load that could be removed (be aware of the reverse-order). | |
uint8_t | nextLogicalLoadToBeRemoved () |
Process with data logging. | |
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 | processDataLogging () |
Process with data logging. | |
void | processDivertedCurrentRawSample (const int16_t rawSample) |
Processes the raw current sample for the diverted connection point. | |
void | processGridCurrentRawSample (const int16_t rawSample) |
Processes the raw current sample for the grid connection point. | |
void | processLatestContribution () |
Process the latest contribution after each new cycle. | |
void | processMinusHalfCycle () |
Process the start of a new -ve half cycle, just after the zero-crossing point. | |
void | processPlusHalfCycle () |
Process the start of a new +ve half cycle, just after the zero-crossing point. | |
void | processPolarity (const int16_t rawSample) |
Processes the polarity of the current voltage sample. | |
void | processRawSamples () |
This routine is called by the ISR when a pair of V & I samples 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 () |
Process the startup period for the router. | |
void | processVoltage () |
Process the calculation for the current voltage sample. | |
void | processVoltageRawSample (const int16_t rawSample) |
Process the current voltage raw sample. | |
void | updatePhysicalLoadStates () |
This function provides the link between the logical and physical loads. | |
void | updatePortsStates () |
Updates the control ports for each of the physical loads. | |
void printParamsForSelectedOutputMode | ( | ) |
Print the settings used for the selected output mode.
This function outputs the configuration parameters related to the selected output mode. It is primarily used for debugging and verifying the system's configuration.
Definition at line 1176 of file processing.cpp.
References capacityOfEnergyBucket_long, DBUG, DBUGLN, and PERSISTENCE_FOR_POLARITY_CHANGE.
Referenced by printConfiguration().
uint32_t absenceOfDivertedEnergyCountInMC { 0 } |
number of main cycles without diverted energy
Definition at line 104 of file processing.cpp.
Referenced by processLatestContribution(), and processRawSamples().
uint8_t activeLoad { NO_OF_DUMPLOADS } |
current active load
Definition at line 75 of file processing.cpp.
Referenced by proceedHighEnergyLevel(), and proceedLowEnergyLevel().
|
constexpr |
threshold value in Integer Energy Units (IEU) that prevents small measurement noise from being incorrectly registered as diverted energy
Definition at line 40 of file processing.cpp.
Referenced by processLatestContribution().
bool beyondStartUpPeriod { false } |
start-up delay, allows things to settle
Definition at line 110 of file processing.cpp.
Referenced by processDataLogging(), processRawSamples(), and processStartUp().
|
constexpr |
main energy bucket for single-phase use, with units of Joules * SUPPLY_FREQUENCY
Definition at line 33 of file processing.cpp.
Referenced by printParamsForSelectedOutputMode(), proceedHighEnergyLevel(), processRawSamples(), and processStartNewCycle().
uint16_t countLoadON[NO_OF_DUMPLOADS] {} |
Number of cycle the load was ON (over 1 datalog period)
Definition at line 102 of file processing.cpp.
Referenced by processDataLogging(), and updatePortsStates().
int32_t cumVdeltasThisCycle_long { 0 } |
for the LPF which determines DC offset (voltage)
Definition at line 81 of file processing.cpp.
Referenced by processMinusHalfCycle(), and processVoltage().
|
inlineconstexpr |
A3 is for CT2 which measures diverted current (A4 for the old PCB)
Definition at line 14 of file processing.cpp.
Referenced by ISR().
|
inlineconstexpr |
A1 is for CT1 which measures grid current (A5 for the old PCB)
Definition at line 13 of file processing.cpp.
Referenced by ISR().
|
constexpr |
nominal mid-point value of ADC @ x1 scale
Definition at line 31 of file processing.cpp.
Referenced by processDivertedCurrentRawSample(), and processGridCurrentRawSample().
int32_t DCoffset_V_long { 512L * 256 } |
<— for LPF
Definition at line 27 of file processing.cpp.
Referenced by processMinusHalfCycle(), and processPolarity().
|
constexpr |
mid-point of ADC plus a working margin
Definition at line 29 of file processing.cpp.
Referenced by processMinusHalfCycle().
|
constexpr |
mid-point of ADC minus a working margin
Definition at line 28 of file processing.cpp.
Referenced by processMinusHalfCycle().
int32_t divertedEnergyRecent_IEU { 0 } |
Hi-res accumulator of limited range
Definition at line 60 of file processing.cpp.
Referenced by processLatestContribution().
uint16_t divertedEnergyTotal_Wh { 0 } |
WattHour register of 63K range
Definition at line 61 of file processing.cpp.
Referenced by processDataLogging(), and processLatestContribution().
int32_t energyInBucket_long { 0 } |
in Integer Energy Units
Definition at line 56 of file processing.cpp.
Referenced by processDataLogging(), processLatestContribution(), processMinusHalfCycle(), processRawSamples(), and processStartNewCycle().
int32_t energyInBucket_prediction { 0 } |
predicted energy level at the end of the current mains cycle
Definition at line 86 of file processing.cpp.
Referenced by proceedHighEnergyLevel(), proceedLowEnergyLevel(), processMinusHalfCycle(), and processRawSamples().
|
constexpr |
Definition at line 70 of file processing.cpp.
Referenced by processLatestContribution().
int32_t l_sum_Vsquared { 0 } |
for summation of V^2 values during datalog period
Definition at line 82 of file processing.cpp.
Referenced by processDataLogging(), and processVoltage().
uint8_t loadPrioritiesAndState[NO_OF_DUMPLOADS] |
load priorities
Definition at line 17 of file processing.cpp.
Referenced by initializeOldPCBPins(), initializeProcessing(), logLoadPriorities(), nextLogicalLoadToBeAdded(), nextLogicalLoadToBeRemoved(), proceedHighEnergyLevel(), proceedLowEnergyLevel(), processRawSamples(), and updatePhysicalLoadStates().
int32_t lowerEnergyThreshold { 0 } |
dynamic lower threshold
Definition at line 57 of file processing.cpp.
Referenced by proceedLowEnergyLevel(), and processRawSamples().
|
constexpr |
default lower threshold for the energy bucket (50% of capacity)
Definition at line 37 of file processing.cpp.
Referenced by processRawSamples().
uint8_t lowestNoOfSampleSetsPerMainsCycle { 0 } |
For a mechanism to check the integrity of this code structure
Definition at line 97 of file processing.cpp.
Referenced by processDataLogging(), processPlusHalfCycle(), and processStartUp().
|
constexpr |
for resetting flexible thresholds
Definition at line 35 of file processing.cpp.
Referenced by processRawSamples().
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 106 of file processing.cpp.
Referenced by processDataLogging().
uint8_t perSecondCounter { 0 } |
for counting every second inside the ISR
Definition at line 108 of file processing.cpp.
Referenced by processLatestContribution().
|
inlineconstexpr |
allows polarity changes to be confirmed
Definition at line 20 of file processing.cpp.
Referenced by confirmPolarity(), and printParamsForSelectedOutputMode().
LoadStates physicalLoadState[NO_OF_DUMPLOADS] |
Physical state of the loads
Definition at line 101 of file processing.cpp.
Referenced by updatePhysicalLoadStates(), and updatePortsStates().
Polarities polarityConfirmed |
for zero-crossing detection
Definition at line 90 of file processing.cpp.
Referenced by confirmPolarity(), processRawSamples(), and processVoltage().
Polarities polarityConfirmedOfLastSampleV |
for zero-crossing detection
Definition at line 91 of file processing.cpp.
Referenced by confirmPolarity(), processRawSamples(), and processVoltage().
Polarities polarityOfMostRecentVsample |
for zero-crossing detection
Definition at line 89 of file processing.cpp.
Referenced by confirmPolarity(), and processPolarity().
|
constexpr |
allows each transition to take effect
Definition at line 74 of file processing.cpp.
Referenced by processRawSamples().
|
inlineconstexpr |
allows trigger device to be reliably armed
Definition at line 22 of file processing.cpp.
Referenced by processRawSamples().
uint8_t postTransitionCount { 0 } |
counts the number of cycle since last transition
Definition at line 73 of file processing.cpp.
Referenced by proceedHighEnergyLevel(), proceedLowEnergyLevel(), and processRawSamples().
int32_t realEnergy_diverted { 0 } |
stores the calculated real energy diverted to controlled loads (CT2) for the current mains cycle
Definition at line 85 of file processing.cpp.
Referenced by processLatestContribution().
int32_t realEnergy_grid { 0 } |
stores the calculated real energy from the grid connection point (CT1) for the current mains cycle
Definition at line 84 of file processing.cpp.
Referenced by processLatestContribution().
bool recentTransition { false } |
a load state has been recently toggled
Definition at line 72 of file processing.cpp.
Referenced by proceedHighEnergyLevel(), proceedLowEnergyLevel(), and processRawSamples().
|
constexpr |
target amount of energy to be exported to the grid during each mains cycle, expressed in Integer Energy Units (IEU)
Definition at line 41 of file processing.cpp.
Referenced by processLatestContribution().
uint16_t sampleSetsDuringNegativeHalfOfMainsCycle { 0 } |
for arming the triac/trigger
Definition at line 99 of file processing.cpp.
Referenced by processRawSamples(), and processStartNewCycle().
uint16_t sampleSetsDuringThisDatalogPeriod { 0 } |
number of sample sets during each datalogging period
Definition at line 95 of file processing.cpp.
Referenced by processDataLogging(), and processVoltageRawSample().
uint8_t sampleSetsDuringThisMainsCycle { 0 } |
number of sample sets during each mains cycle
Definition at line 94 of file processing.cpp.
Referenced by processLatestContribution(), processMinusHalfCycle(), processPlusHalfCycle(), processStartNewCycle(), processStartUp(), and processVoltageRawSample().
int32_t sampleVminusDC_long { 0 } |
voltage sample with DC offset removed
Definition at line 87 of file processing.cpp.
Referenced by processDivertedCurrentRawSample(), processGridCurrentRawSample(), processPolarity(), and processVoltage().
int32_t sumP_diverted { 0 } |
for per-cycle summation of 'real power'
Definition at line 79 of file processing.cpp.
Referenced by processDivertedCurrentRawSample(), processLatestContribution(), processStartNewCycle(), and processStartUp().
int32_t sumP_diverted_overDL_Period { 0 } |
for per-cycle summation of 'real power' during datalog period
Definition at line 80 of file processing.cpp.
Referenced by processDataLogging(), processDivertedCurrentRawSample(), and processStartUp().
int32_t sumP_grid { 0 } |
for per-cycle summation of 'real power'
Definition at line 77 of file processing.cpp.
Referenced by processGridCurrentRawSample(), processLatestContribution(), processMinusHalfCycle(), processStartNewCycle(), and processStartUp().
int32_t sumP_grid_overDL_Period { 0 } |
for per-cycle summation of 'real power' during datalog period
Definition at line 78 of file processing.cpp.
Referenced by processDataLogging(), processGridCurrentRawSample(), and processStartUp().
int32_t upperEnergyThreshold { 0 } |
dynamic upper threshold
Definition at line 58 of file processing.cpp.
Referenced by proceedHighEnergyLevel(), and processRawSamples().
|
constexpr |
default upper threshold for the energy bucket (50% of capacity)
Definition at line 38 of file processing.cpp.
Referenced by processRawSamples().
|
inlineconstexpr |
A0 is for the voltage sensor (A3 for the old PCB)
Definition at line 12 of file processing.cpp.
Referenced by ISR().