105 DCoffset_V = 512L * 256L;
110 bOverrideLoad =
false;
183#if !defined(__DOXYGEN__)
305 int32_t sampleIminusDC = (
static_cast< int32_t
>(rawSample -
i_DCoffset_I_nom)) << 8;
308 const int32_t last_lpf_long{ lpf_long[phase] };
309 lpf_long[phase] +=
alpha * (sampleIminusDC - last_lpf_long);
310 sampleIminusDC += (
lpf_gain * lpf_long[phase]);
314 const int32_t filtI_div4 = sampleIminusDC >> 2;
315 int32_t instP = filtV_div4 * filtI_div4;
358 int32_t inst_Vsquared{ filtV_div4 * filtV_div4 };
362 inst_Vsquared >>= 16;
366 inst_Vsquared >>= 12;
410 bool bOK_toAddLoad{
true };
451 bool bOK_toRemoveLoad{
true };
476 if (bOK_toRemoveLoad)
574#if !defined(__DOXYGEN__)
597#if !defined(__DOXYGEN__)
646#if !defined(__DOXYGEN__)
802 DBUG(F(
"Output mode: "));
809 DBUGLN(F(
"anti-flicker"));
810 DBUG(F(
"\toffsetOfEnergyThresholds = "));
813 DBUG(F(
"\tf_capacityOfEnergyBucket_main = "));
815 DBUG(F(
"\tf_lowerEnergyThreshold = "));
817 DBUG(F(
"\tf_upperEnergyThreshold = "));
Calibration values definition.
constexpr float f_powerCal[NO_OF_PHASES]
void initializePins() const
Initialize the pins used by the relays.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
constexpr bool RELAY_DIVERSION
constexpr bool OVERRIDE_PIN_PRESENT
constexpr uint8_t dualTariffPin
constexpr uint8_t forcePin
constexpr RelayEngine relays
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
constexpr bool DUAL_TARIFF
constexpr uint8_t diversionPin
constexpr uint8_t NO_OF_DUMPLOADS
constexpr bool WATCHDOG_PIN_PRESENT
constexpr bool DIVERSION_PIN_PRESENT
constexpr uint8_t rotationPin
constexpr uint8_t watchDogPin
constexpr int16_t REQUIRED_EXPORT_IN_WATTS
constexpr uint32_t WORKING_ZONE_IN_JOULES
constexpr uint8_t ::type DATALOG_PERIOD_IN_MAINS_CYCLES
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
constexpr uint8_t NO_OF_PHASES
constexpr uint8_t SUPPLY_FREQUENCY
Classes/types needed for dual-tariff support.
void updatePhysicalLoadStates()
This function provides the link between the logical and physical loads.
void processLatestContribution(const uint8_t phase)
Process the latest contribution after each phase specific new cycle additional processing is performe...
void processStartUp(const uint8_t phase)
Process the startup period for the router.
void processStartNewCycle()
This code is executed once per 20mS, shortly after the start of each new mains cycle 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 processVoltageRawSample(const uint8_t phase, const int16_t rawSample)
Process the current voltage raw sample for the specific phase.
void proceedLowEnergyLevel()
Process the case of low energy level, some action may be required.
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.
uint8_t nextLogicalLoadToBeAdded()
Retrieve the next load that could be added (be aware of the order)
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 processDataLogging()
Process with data logging.
uint8_t nextLogicalLoadToBeRemoved()
Retrieve the next load that could be removed (be aware of the reverse-order)
void confirmPolarity(const uint8_t phase)
This routine prevents a zero-crossing point from being declared until a certain number of consecutive...
void processVoltage(const uint8_t phase)
Process the calculation for the current voltage sample for the specific phase.
void proceedHighEnergyLevel()
Process the case of high 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.
Polarities polarityConfirmedOfLastSampleV[NO_OF_PHASES]
uint8_t n_lowestNoOfSampleSetsPerMainsCycle
float f_energyInBucket_main
constexpr OutputModes outputMode
constexpr int16_t i_DCoffset_I_nom
constexpr int32_t l_DCoffset_V_min
constexpr int32_t l_DCoffset_V_max
float f_upperEnergyThreshold
uint16_t countLoadON[NO_OF_DUMPLOADS]
constexpr float f_offsetOfEnergyThresholdsInAFmode
void updatePortsStates()
update the control ports for each of the physical loads
remove_cv< remove_reference< decltype(DATALOG_PERIOD_IN_MAINS_CYCLES)>::type >::type n_cycleCountForDatalogging
constexpr uint8_t POST_TRANSITION_MAX_COUNT
constexpr auto initThreshold(const bool lower)
set default threshold at compile time so the variable can be read-only
constexpr float f_capacityOfEnergyBucket_main
LoadStates physicalLoadState[NO_OF_DUMPLOADS]
void initializeOptionalPins()
Initializes the optional pins.
int32_t l_sum_Vsquared[NO_OF_PHASES]
int32_t l_sumP[NO_OF_PHASES]
Polarities polarityConfirmed[NO_OF_PHASES]
uint8_t n_samplesDuringThisMainsCycle[NO_OF_PHASES]
constexpr float f_lowerThreshold_default
void printParamsForSelectedOutputMode()
Print the settings used for the selected output mode.
constexpr float f_midPointOfEnergyBucket_main
int32_t l_cumVdeltasThisCycle[NO_OF_PHASES]
int32_t l_sampleVminusDC[NO_OF_PHASES]
Polarities polarityOfMostRecentSampleV[NO_OF_PHASES]
uint16_t i_sampleSetsDuringThisDatalogPeriod
constexpr float f_upperThreshold_default
float f_lowerEnergyThreshold
int32_t l_DCoffset_V[NO_OF_PHASES]
int32_t l_sumP_atSupplyPoint[NO_OF_PHASES]
void initializeProcessing()
Initializes the ports and load states for processing.
uint8_t postTransitionCount
Public functions/variables of processing engine.
volatile uint8_t copyOf_lowestNoOfSampleSetsPerMainsCycle
constexpr uint16_t startUpPeriod
constexpr uint8_t PERSISTENCE_FOR_POLARITY_CHANGE
uint8_t loadPrioritiesAndState[NO_OF_DUMPLOADS]
volatile bool b_reOrderLoads
volatile float copyOf_energyInBucket_main
volatile int32_t copyOf_sumP_atSupplyPoint[NO_OF_PHASES]
volatile int32_t copyOf_sum_Vsquared[NO_OF_PHASES]
volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod
volatile bool b_overrideLoadOn[NO_OF_DUMPLOADS]
volatile bool b_newMainsCycle
volatile bool b_datalogEventPending
volatile uint32_t absenceOfDivertedEnergyCount
volatile bool b_diversionOff
constexpr uint16_t initialDelay
volatile uint16_t copyOf_countLoadON[NO_OF_DUMPLOADS]
constexpr uint8_t loadStateMask
constexpr uint8_t loadStateOnBit
Some utility functions for pins manipulation.
constexpr void bit_set(T &_dest, const uint8_t bit)
Set the specified bit to 1.
void setPinsOFF(const uint16_t pins)
Set the Pins state to OFF.
constexpr void setPinOFF(const uint8_t pin)
Set the Pin state to OFF for the specified pin.
void setPinsON(const uint16_t pins)
Set the Pins state to ON.
constexpr uint8_t bit_clear(T &_dest, const uint8_t bit)
Clear the specified bit.