3-phase PV router
Loading...
Searching...
No Matches
processing.cpp
Go to the documentation of this file.
1
12#include <Arduino.h>
13
14#include "calibration.h"
15#include "dualtariff.h"
16#include "processing.h"
17#include "utils_pins.h"
18
19// Define operating limits for the LP filters which identify DC offset in the voltage
20// sample streams. By limiting the output range, these filters always should start up
21// correctly.
22constexpr int32_t l_DCoffset_V_min{ (512L - 100L) * 256L };
23constexpr int32_t l_DCoffset_V_max{ (512L + 100L) * 256L };
24constexpr int16_t i_DCoffset_I_nom{ 512L };
33constexpr float f_offsetOfEnergyThresholdsInAFmode{ 0.1F };
34
43constexpr auto initThreshold(const bool lower)
44{
45 return lower
48}
49
50constexpr float f_lowerThreshold_default{ initThreshold(true) };
51constexpr float f_upperThreshold_default{ initThreshold(false) };
53float f_energyInBucket_main{ 0.0F };
57// for improved control of multiple loads
58bool b_recentTransition{ false };
60constexpr uint8_t POST_TRANSITION_MAX_COUNT{ 3 };
61// constexpr uint8_t POST_TRANSITION_MAX_COUNT{50}; /**< for testing only */
77// For an enhanced polarity detection mechanism, which includes a persistence check
85bool beyondStartUpPeriod{ false };
92{
93 for (uint8_t i = 0; i < NO_OF_DUMPLOADS; ++i)
94 {
96 pinMode(physicalLoadPin[i], OUTPUT); // driver pin for Load #n
98 }
99 updatePhysicalLoadStates(); // allows the logical-to-physical mapping to be changed
100
101 updatePortsStates(); // updates output pin states
102
103 for (auto &DCoffset_V : l_DCoffset_V)
104 {
105 DCoffset_V = 512L * 256L; // nominal mid-point value of ADC @ x256 scale
106 }
107
108 for (auto &bOverrideLoad : b_overrideLoadOn)
109 {
110 bOverrideLoad = false;
111 }
112
113 // First stop the ADC
114 bit_clear(ADCSRA, ADEN);
115
116 // Activate free-running mode
117 ADCSRB = 0x00;
118
119 // Set up the ADC to be free-running
120 bit_set(ADCSRA, ADPS0); // Set the ADC's clock to system clock / 128
121 bit_set(ADCSRA, ADPS1);
122 bit_set(ADCSRA, ADPS2);
123
124 bit_set(ADCSRA, ADATE); // set the Auto Trigger Enable bit in the ADCSRA register. Because
125 // bits ADTS0-2 have not been set (i.e. they are all zero), the
126 // ADC's trigger source is set to "free running mode".
127
128 bit_set(ADCSRA, ADIE); // set the ADC interrupt enable bit. When this bit is written
129 // to one and the I-bit in SREG is set, the
130 // ADC Conversion Complete Interrupt is activated.
131
132 bit_set(ADCSRA, ADEN); // Enable the ADC
133
134 bit_set(ADCSRA, ADSC); // start ADC manually first time
135
136 sei(); // Enable Global Interrupts
137}
138
144{
145 if constexpr (DUAL_TARIFF)
146 {
147 pinMode(dualTariffPin, INPUT_PULLUP); // set as input & enable the internal pullup resistor
148 delay(100); // allow time to settle
149
150 ul_TimeOffPeak = millis();
151 }
152
153 if constexpr (OVERRIDE_PIN_PRESENT)
154 {
155 pinMode(forcePin, INPUT_PULLUP); // set as input & enable the internal pullup resistor
156 delay(100); // allow time to settle
157 }
158
159 if constexpr (PRIORITY_ROTATION == RotationModes::PIN)
160 {
161 pinMode(rotationPin, INPUT_PULLUP); // set as input & enable the internal pullup resistor
162 delay(100); // allow time to settle
163 }
164
165 if constexpr (DIVERSION_PIN_PRESENT)
166 {
167 pinMode(diversionPin, INPUT_PULLUP); // set as input & enable the internal pullup resistor
168 delay(100); // allow time to settle
169 }
170
171 if constexpr (RELAY_DIVERSION)
172 {
174 }
175
176 if constexpr (WATCHDOG_PIN_PRESENT)
177 {
178 pinMode(watchDogPin, OUTPUT); // set as output
179 setPinOFF(watchDogPin); // set to off
180 }
181}
182
183#if !defined(__DOXYGEN__)
184void updatePortsStates() __attribute__((optimize("-O3")));
185#endif
191{
192 uint16_t pinsON{ 0 };
193 uint16_t pinsOFF{ 0 };
194
195 uint8_t i{ NO_OF_DUMPLOADS };
196
197 do
198 {
199 --i;
200 // update the local load's state.
202 {
203 // setPinOFF(physicalLoadPin[i]);
204 pinsOFF |= bit(physicalLoadPin[i]);
205 }
206 else
207 {
208 ++countLoadON[i];
209 // setPinON(physicalLoadPin[i]);
210 pinsON |= bit(physicalLoadPin[i]);
211 }
212 } while (i);
213
214 setPinsOFF(pinsOFF);
215 setPinsON(pinsON);
216}
217
235{
236 if constexpr (PRIORITY_ROTATION != RotationModes::OFF)
237 {
238 if (b_reOrderLoads)
239 {
240 uint8_t i{ NO_OF_DUMPLOADS - 1 };
241 const auto temp{ loadPrioritiesAndState[i] };
242 do
243 {
245 --i;
246 } while (i);
247 loadPrioritiesAndState[0] = temp;
248
249 b_reOrderLoads = false;
250 }
251
252 if constexpr (!DUAL_TARIFF)
253 {
254 if (0x00 == (loadPrioritiesAndState[0] & loadStateOnBit))
255 {
257 }
258 else
259 {
261 }
262 }
263 }
264
265 const bool bDiversionOff{ b_diversionOff };
266 uint8_t idx{ NO_OF_DUMPLOADS };
267 do
268 {
269 --idx;
270 const auto iLoad{ loadPrioritiesAndState[idx] & loadStateMask };
272 } while (idx);
273}
274
283void processPolarity(const uint8_t phase, const int16_t rawSample)
284{
285 // remove DC offset from each raw voltage sample by subtracting the accurate value
286 // as determined by its associated LP filter.
287 l_sampleVminusDC[phase] = (static_cast< int32_t >(rawSample) << 8) - l_DCoffset_V[phase];
289}
290
299void processCurrentRawSample(const uint8_t phase, const int16_t rawSample)
300{
301 // extra items for an LPF to improve the processing of data samples from CT1
302 static int32_t lpf_long[NO_OF_PHASES]{}; // new LPF, for offsetting the behaviour of CTx as a HPF
303
304 // remove most of the DC offset from the current sample (the precise value does not matter)
305 int32_t sampleIminusDC = (static_cast< int32_t >(rawSample - i_DCoffset_I_nom)) << 8;
306
307 // extra filtering to offset the HPF effect of CTx
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]);
311
312 // calculate the "real power" in this sample pair and add to the accumulated sum
313 const int32_t filtV_div4 = l_sampleVminusDC[phase] >> 2; // reduce to 16-bits (now x64, or 2^6)
314 const int32_t filtI_div4 = sampleIminusDC >> 2; // reduce to 16-bits (now x64, or 2^6)
315 int32_t instP = filtV_div4 * filtI_div4; // 32-bits (now x4096, or 2^12)
316 instP >>= 12; // scaling is now x1, as for Mk2 (V_ADC x I_ADC)
317
318 l_sumP[phase] += instP; // cumulative power, scaling as for Mk2 (V_ADC x I_ADC)
319 l_sumP_atSupplyPoint[phase] += instP; // cumulative power, scaling as for Mk2 (V_ADC x I_ADC)
320}
321
330void confirmPolarity(const uint8_t phase)
331{
332 static uint8_t count[NO_OF_PHASES]{};
333
335 {
336 count[phase] = 0;
337 return;
338 }
339
340 if (++count[phase] > PERSISTENCE_FOR_POLARITY_CHANGE)
341 {
342 count[phase] = 0;
344 }
345}
346
354void processVoltage(const uint8_t phase)
355{
356 // for the Vrms calculation (for datalogging only)
357 const int32_t filtV_div4{ l_sampleVminusDC[phase] >> 2 }; // reduce to 16-bits (now x64, or 2^6)
358 int32_t inst_Vsquared{ filtV_div4 * filtV_div4 }; // 32-bits (now x4096, or 2^12)
359
360 if constexpr (DATALOG_PERIOD_IN_SECONDS > 10)
361 {
362 inst_Vsquared >>= 16; // scaling is now x1/16 (V_ADC x I_ADC)
363 }
364 else
365 {
366 inst_Vsquared >>= 12; // scaling is now x1 (V_ADC x I_ADC)
367 }
368
369 l_sum_Vsquared[phase] += inst_Vsquared; // cumulative V^2 (V_ADC x I_ADC)
370 //
371 // store items for use during next loop
372 l_cumVdeltasThisCycle[phase] += l_sampleVminusDC[phase]; // for use with LP filter
373 polarityConfirmedOfLastSampleV[phase] = polarityConfirmed[phase]; // for identification of half cycle boundaries
374 ++n_samplesDuringThisMainsCycle[phase]; // for real power calculations
375}
376
384void processStartUp(const uint8_t phase)
385{
386 // wait until the DC-blocking filters have had time to settle
387 if (millis() <= (initialDelay + startUpPeriod))
388 {
389 return; // still settling, do nothing
390 }
391
392 // the DC-blocking filters have had time to settle
393 beyondStartUpPeriod = true;
394 l_sumP[phase] = 0;
395 l_sumP_atSupplyPoint[phase] = 0;
398
400 // can't say "Go!" here 'cos we're in an ISR!
401}
402
409{
410 bool bOK_toAddLoad{ true };
411 const auto tempLoad{ nextLogicalLoadToBeAdded() };
412
413 if (tempLoad >= NO_OF_DUMPLOADS)
414 {
415 return;
416 }
417
418 // a load which is now OFF has been identified for potentially being switched ON
420 {
421 // During the post-transition period, any increase in the energy level is noted.
423
424 // the energy thresholds must remain within range
426 {
428 }
429
430 // Only the active load may be switched during this period. All other loads must
431 // wait until the recent transition has had sufficient opportunity to take effect.
432 bOK_toAddLoad = (tempLoad == activeLoad);
433 }
434
435 if (bOK_toAddLoad)
436 {
438 activeLoad = tempLoad;
440 b_recentTransition = true;
441 }
442}
443
450{
451 bool bOK_toRemoveLoad{ true };
452 const auto tempLoad{ nextLogicalLoadToBeRemoved() };
453
454 if (tempLoad >= NO_OF_DUMPLOADS)
455 {
456 return;
457 }
458
459 // a load which is now ON has been identified for potentially being switched OFF
461 {
462 // During the post-transition period, any decrease in the energy level is noted.
464
465 // the energy thresholds must remain within range
467 {
469 }
470
471 // Only the active load may be switched during this period. All other loads must
472 // wait until the recent transition has had sufficient opportunity to take effect.
473 bOK_toRemoveLoad = (tempLoad == activeLoad);
474 }
475
476 if (bOK_toRemoveLoad)
477 {
479 activeLoad = tempLoad;
481 b_recentTransition = true;
482 }
483}
484
496{
497 // Restrictions apply for the period immediately after a load has been switched.
498 // Here the b_recentTransition flag is checked and updated as necessary.
499 // if (b_recentTransition)
500 // b_recentTransition = (++postTransitionCount < POST_TRANSITION_MAX_COUNT);
501 // for optimization, the next line is equivalent to the two lines above
503
505 {
506 // the energy state is in the upper half of the working range
507 f_lowerEnergyThreshold = f_lowerThreshold_default; // reset the "opposite" threshold
509 {
510 // Because the energy level is high, some action may be required
512 }
513 }
514 else
515 {
516 // the energy state is in the lower half of the working range
517 f_upperEnergyThreshold = f_upperThreshold_default; // reset the "opposite" threshold
519 {
520 // Because the energy level is low, some action may be required
522 }
523 }
524
525 updatePhysicalLoadStates(); // allows the logical-to-physical mapping to be changed
526
527 updatePortsStates(); // update the control ports for each of the physical loads
528
529 // Now that the energy-related decisions have been taken, min and max limits can now
530 // be applied to the level of the energy bucket. This is to ensure correct operation
531 // when conditions change, i.e. when import changes to export, and vice versa.
532 //
534 {
536 }
537 else if (f_energyInBucket_main < 0)
538 {
540 }
541}
542
550void processMinusHalfCycle(const uint8_t phase)
551{
552 // This is a convenient point to update the Low Pass Filter for removing the DC
553 // component from the phase that is being processed.
554 // The portion which is fed back into the integrator is approximately one percent
555 // of the average offset of all the SampleVs in the previous mains cycle.
556 //
557 l_DCoffset_V[phase] += (l_cumVdeltasThisCycle[phase] >> 12);
558 l_cumVdeltasThisCycle[phase] = 0;
559
560 // To ensure that this LP filter will always start up correctly when 240V AC is
561 // available, its output value needs to be prevented from drifting beyond the likely range
562 // of the voltage signal.
563 //
564 if (l_DCoffset_V[phase] < l_DCoffset_V_min)
565 {
567 }
568 else if (l_DCoffset_V[phase] > l_DCoffset_V_max)
569 {
571 }
572}
573
574#if !defined(__DOXYGEN__)
575uint8_t nextLogicalLoadToBeAdded() __attribute__((optimize("-O3")));
576#endif
585{
586 for (uint8_t index = 0; index < NO_OF_DUMPLOADS; ++index)
587 {
588 if (0x00 == (loadPrioritiesAndState[index] & loadStateOnBit))
589 {
590 return (index);
591 }
592 }
593
594 return (NO_OF_DUMPLOADS);
595}
596
597#if !defined(__DOXYGEN__)
598uint8_t nextLogicalLoadToBeRemoved() __attribute__((optimize("-O3")));
599#endif
608{
609 uint8_t index{ NO_OF_DUMPLOADS };
610 do
611 {
613 {
614 return (index);
615 }
616 } while (index);
617
618 return (NO_OF_DUMPLOADS);
619}
620
629void processLatestContribution(const uint8_t phase)
630{
631 // for efficiency, the energy scale is Joules * SUPPLY_FREQUENCY
632 // add the latest energy contribution to the main energy accumulator
634
635 // apply any adjustment that is required.
636 if (0 == phase)
637 {
638 f_energyInBucket_main -= REQUIRED_EXPORT_IN_WATTS; // energy scale is Joules x 50
639 b_newMainsCycle = true; // a 50 Hz 'tick' for use by the main code
640 }
641 // Applying max and min limits to the main accumulator's level
642 // is deferred until after the energy related decisions have been taken
643 //
644}
645
646#if !defined(__DOXYGEN__)
647void processDataLogging() __attribute__((optimize("-O3")));
648#endif
658{
660 {
661 return; // data logging period not yet reached
662 }
663
665
666 uint8_t phase{ NO_OF_PHASES };
667 do
668 {
669 --phase;
671 l_sumP_atSupplyPoint[phase] = 0;
672
673 copyOf_sum_Vsquared[phase] = l_sum_Vsquared[phase];
674 l_sum_Vsquared[phase] = 0;
675 } while (phase);
676
677 uint8_t i{ NO_OF_DUMPLOADS };
678 do
679 {
680 --i;
682 countLoadON[i] = 0;
683 } while (i);
684
688
691
692 // signal the main processor that logging data are available
693 // we skip the period from start to running stable
695}
696
704void processPlusHalfCycle(const uint8_t phase)
705{
706 processLatestContribution(phase); // runs at 6.6 ms intervals
707
708 // A performance check to monitor and display the minimum number of sets of
709 // ADC samples per mains cycle, the expected number being 20ms / (104us * 6) = 32.05
710 //
711 if (0 == phase)
712 {
714 {
716 }
717
719 }
720
721 l_sumP[phase] = 0;
723}
724
732void processRawSamples(const uint8_t phase)
733{
734 // The raw V and I samples are processed in "phase pairs"
735 const auto &lastPolarity{ polarityConfirmedOfLastSampleV[phase] };
736
738 {
739 // the polarity of this sample is positive
740 if (Polarities::POSITIVE != lastPolarity)
741 {
742 // This is the start of a new +ve half cycle, for this phase, just after the zero-crossing point.
744 {
746 }
747 else
748 {
749 processStartUp(phase);
750 }
751 }
752
753 // still processing samples where the voltage is POSITIVE ...
754 // check to see whether the trigger device can now be reliably armed
755 if ((0 == phase) && beyondStartUpPeriod && (2 == n_samplesDuringThisMainsCycle[0])) // lower value for larger sample set
756 {
757 // This code is executed once per 20mS, shortly after the start of each new mains cycle on phase 0.
759 }
760 }
761 else
762 {
763 // the polarity of this sample is negative
764 if (Polarities::NEGATIVE != lastPolarity)
765 {
766 // This is the start of a new -ve half cycle (just after the zero-crossing point)
768 }
769 }
770}
771
780void processVoltageRawSample(const uint8_t phase, const int16_t rawSample)
781{
782 processPolarity(phase, rawSample);
783 confirmPolarity(phase);
784 //
785 processRawSamples(phase); // deals with aspects that only occur at particular stages of each mains cycle
786 //
787 processVoltage(phase);
788
789 if (phase == 0)
790 {
792 }
793}
794
800{
801 // display relevant settings for selected output mode
802 DBUG(F("Output mode: "));
804 {
805 DBUGLN(F("normal"));
806 }
807 else
808 {
809 DBUGLN(F("anti-flicker"));
810 DBUG(F("\toffsetOfEnergyThresholds = "));
812 }
813 DBUG(F("\tf_capacityOfEnergyBucket_main = "));
815 DBUG(F("\tf_lowerEnergyThreshold = "));
817 DBUG(F("\tf_upperEnergyThreshold = "));
819}
Calibration values definition.
constexpr float alpha
Definition: calibration.h:54
constexpr float lpf_gain
Definition: calibration.h:53
constexpr float f_powerCal[NO_OF_PHASES]
Definition: calibration.h:34
void initializePins() const
Initialize the pins used by the relays.
Definition: utils_relay.h:368
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition: config.h:75
constexpr bool RELAY_DIVERSION
Definition: config.h:53
constexpr bool OVERRIDE_PIN_PRESENT
Definition: config.h:49
constexpr uint8_t dualTariffPin
Definition: config.h:78
constexpr uint8_t forcePin
Definition: config.h:81
constexpr RelayEngine relays
Definition: config.h:84
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition: config.h:74
constexpr bool DUAL_TARIFF
Definition: config.h:54
constexpr uint8_t diversionPin
Definition: config.h:79
constexpr uint8_t NO_OF_DUMPLOADS
Definition: config.h:38
constexpr bool WATCHDOG_PIN_PRESENT
Definition: config.h:52
constexpr bool DIVERSION_PIN_PRESENT
Definition: config.h:47
constexpr uint8_t rotationPin
Definition: config.h:80
constexpr uint8_t watchDogPin
Definition: config.h:82
constexpr int16_t REQUIRED_EXPORT_IN_WATTS
Definition: config_system.h:23
constexpr uint32_t WORKING_ZONE_IN_JOULES
Definition: config_system.h:29
constexpr uint16_t
Definition: config_system.h:32
constexpr uint8_t ::type DATALOG_PERIOD_IN_MAINS_CYCLES
Definition: config_system.h:32
constexpr uint8_t DATALOG_PERIOD_IN_SECONDS
Definition: config_system.h:31
constexpr uint8_t NO_OF_PHASES
Definition: config_system.h:19
constexpr uint8_t SUPPLY_FREQUENCY
Definition: config_system.h:27
#define DBUGLN(...)
Definition: debug.h:97
#define DBUG(...)
Definition: debug.h:96
Classes/types needed for dual-tariff support.
uint32_t ul_TimeOffPeak
Definition: dualtariff.h:62
void updatePhysicalLoadStates()
This function provides the link between the logical and physical loads.
Definition: processing.cpp:234
void processLatestContribution(const uint8_t phase)
Process the latest contribution after each phase specific new cycle additional processing is performe...
Definition: processing.cpp:629
void processStartUp(const uint8_t phase)
Process the startup period for the router.
Definition: processing.cpp:384
void processStartNewCycle()
This code is executed once per 20mS, shortly after the start of each new mains cycle on phase 0.
Definition: processing.cpp:495
void processMinusHalfCycle(const uint8_t phase)
Process the start of a new -ve half cycle, for this phase, just after the zero-crossing point.
Definition: processing.cpp:550
void processVoltageRawSample(const uint8_t phase, const int16_t rawSample)
Process the current voltage raw sample for the specific phase.
Definition: processing.cpp:780
void proceedLowEnergyLevel()
Process the case of low energy level, some action may be required.
Definition: processing.cpp:449
void processPolarity(const uint8_t phase, const int16_t rawSample)
Process with the polarity for the actual voltage sample for the specific phase.
Definition: processing.cpp:283
void processRawSamples(const uint8_t phase)
This routine is called by the ISR when a pair of V & I sample becomes available.
Definition: processing.cpp:732
uint8_t nextLogicalLoadToBeAdded()
Retrieve the next load that could be added (be aware of the order)
Definition: processing.cpp:584
void processPlusHalfCycle(const uint8_t phase)
Process the start of a new +ve half cycle, for this phase, just after the zero-crossing point.
Definition: processing.cpp:704
void processDataLogging()
Process with data logging.
Definition: processing.cpp:657
uint8_t nextLogicalLoadToBeRemoved()
Retrieve the next load that could be removed (be aware of the reverse-order)
Definition: processing.cpp:607
void confirmPolarity(const uint8_t phase)
This routine prevents a zero-crossing point from being declared until a certain number of consecutive...
Definition: processing.cpp:330
void processVoltage(const uint8_t phase)
Process the calculation for the current voltage sample for the specific phase.
Definition: processing.cpp:354
void proceedHighEnergyLevel()
Process the case of high energy level, some action may be required.
Definition: processing.cpp:408
void processCurrentRawSample(const uint8_t phase, const int16_t rawSample)
Process the calculation for the actual current raw sample for the specific phase.
Definition: processing.cpp:299
Polarities polarityConfirmedOfLastSampleV[NO_OF_PHASES]
Definition: processing.cpp:80
uint8_t n_lowestNoOfSampleSetsPerMainsCycle
Definition: processing.cpp:75
float f_energyInBucket_main
Definition: processing.cpp:53
constexpr OutputModes outputMode
Definition: processing.cpp:35
constexpr int16_t i_DCoffset_I_nom
Definition: processing.cpp:24
constexpr int32_t l_DCoffset_V_min
Definition: processing.cpp:22
constexpr int32_t l_DCoffset_V_max
Definition: processing.cpp:23
float f_upperEnergyThreshold
Definition: processing.cpp:55
uint16_t countLoadON[NO_OF_DUMPLOADS]
Definition: processing.cpp:83
constexpr float f_offsetOfEnergyThresholdsInAFmode
Definition: processing.cpp:33
void updatePortsStates()
update the control ports for each of the physical loads
Definition: processing.cpp:190
remove_cv< remove_reference< decltype(DATALOG_PERIOD_IN_MAINS_CYCLES)>::type >::type n_cycleCountForDatalogging
Definition: processing.cpp:73
constexpr uint8_t POST_TRANSITION_MAX_COUNT
Definition: processing.cpp:60
constexpr auto initThreshold(const bool lower)
set default threshold at compile time so the variable can be read-only
Definition: processing.cpp:43
constexpr float f_capacityOfEnergyBucket_main
Definition: processing.cpp:29
LoadStates physicalLoadState[NO_OF_DUMPLOADS]
Definition: processing.cpp:82
void initializeOptionalPins()
Initializes the optional pins.
Definition: processing.cpp:143
int32_t l_sum_Vsquared[NO_OF_PHASES]
Definition: processing.cpp:68
int32_t l_sumP[NO_OF_PHASES]
Definition: processing.cpp:64
Polarities polarityConfirmed[NO_OF_PHASES]
Definition: processing.cpp:79
bool b_recentTransition
Definition: processing.cpp:58
uint8_t n_samplesDuringThisMainsCycle[NO_OF_PHASES]
Definition: processing.cpp:70
constexpr float f_lowerThreshold_default
Definition: processing.cpp:50
void printParamsForSelectedOutputMode()
Print the settings used for the selected output mode.
Definition: processing.cpp:799
constexpr float f_midPointOfEnergyBucket_main
Definition: processing.cpp:31
bool beyondStartUpPeriod
Definition: processing.cpp:85
int32_t l_cumVdeltasThisCycle[NO_OF_PHASES]
Definition: processing.cpp:66
int32_t l_sampleVminusDC[NO_OF_PHASES]
Definition: processing.cpp:65
Polarities polarityOfMostRecentSampleV[NO_OF_PHASES]
Definition: processing.cpp:78
uint16_t i_sampleSetsDuringThisDatalogPeriod
Definition: processing.cpp:71
constexpr float f_upperThreshold_default
Definition: processing.cpp:51
float f_lowerEnergyThreshold
Definition: processing.cpp:54
int32_t l_DCoffset_V[NO_OF_PHASES]
Definition: processing.cpp:26
int32_t l_sumP_atSupplyPoint[NO_OF_PHASES]
Definition: processing.cpp:67
void initializeProcessing()
Initializes the ports and load states for processing.
Definition: processing.cpp:91
uint8_t activeLoad
Definition: processing.cpp:62
uint8_t postTransitionCount
Definition: processing.cpp:59
Public functions/variables of processing engine.
volatile uint8_t copyOf_lowestNoOfSampleSetsPerMainsCycle
Definition: processing.h:43
constexpr uint16_t startUpPeriod
Definition: processing.h:27
constexpr uint8_t PERSISTENCE_FOR_POLARITY_CHANGE
Definition: processing.h:24
uint8_t loadPrioritiesAndState[NO_OF_DUMPLOADS]
Definition: processing.h:22
volatile bool b_reOrderLoads
Definition: processing.h:34
volatile float copyOf_energyInBucket_main
Definition: processing.h:42
volatile int32_t copyOf_sumP_atSupplyPoint[NO_OF_PHASES]
Definition: processing.h:40
volatile int32_t copyOf_sum_Vsquared[NO_OF_PHASES]
Definition: processing.h:41
volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod
Definition: processing.h:44
volatile bool b_overrideLoadOn[NO_OF_DUMPLOADS]
Definition: processing.h:33
volatile bool b_newMainsCycle
Definition: processing.h:32
volatile bool b_datalogEventPending
Definition: processing.h:31
volatile uint32_t absenceOfDivertedEnergyCount
Definition: processing.h:30
volatile bool b_diversionOff
Definition: processing.h:35
constexpr uint16_t initialDelay
Definition: processing.h:26
volatile uint16_t copyOf_countLoadON[NO_OF_DUMPLOADS]
Definition: processing.h:45
uint8_t i
Definition: test_main.cpp:94
Polarities
Definition: types.h:26
constexpr uint8_t loadStateMask
Definition: types.h:47
constexpr uint8_t loadStateOnBit
Definition: types.h:46
LoadStates
Definition: types.h:40
OutputModes
Definition: types.h:33
Some utility functions for pins manipulation.
constexpr void bit_set(T &_dest, const uint8_t bit)
Set the specified bit to 1.
Definition: utils_pins.h:46
void setPinsOFF(const uint16_t pins)
Set the Pins state to OFF.
Definition: utils_pins.h:161
constexpr void setPinOFF(const uint8_t pin)
Set the Pin state to OFF for the specified pin.
Definition: utils_pins.h:144
void setPinsON(const uint16_t pins)
Set the Pins state to ON.
Definition: utils_pins.h:133
constexpr uint8_t bit_clear(T &_dest, const uint8_t bit)
Clear the specified bit.
Definition: utils_pins.h:72