3-phase PV router
Loading...
Searching...
No Matches
processing.h
Go to the documentation of this file.
1
11
12#ifndef PROCESSING_H
13#define PROCESSING_H
14
15#include "config.h"
16
17// analogue input pins
18inline constexpr uint8_t sensorV[NO_OF_PHASES]{ 0, 2, 4 };
19inline constexpr uint8_t sensorI[NO_OF_PHASES]{ 1, 3, 5 };
20// ------------------------------------------
21
23
24inline constexpr uint8_t PERSISTENCE_FOR_POLARITY_CHANGE{ 1 };
25
26inline constexpr uint16_t initialDelay{ 3000 };
27inline constexpr uint16_t startUpPeriod{ 3000 };
28
29// for interaction between the main processor and the ISR
30inline volatile uint16_t absenceOfDivertedEnergyCount{ 0 };
31inline volatile bool b_datalogEventPending{ false };
32inline volatile bool b_newMainsCycle{ false };
33inline volatile bool b_overrideLoadOn[NO_OF_DUMPLOADS]{};
34inline volatile bool b_reOrderLoads{ false };
35inline volatile bool b_diversionOff{ false };
36inline volatile bool EDD_isIdle{ true };
37
38// since there's no real locking feature for shared variables, a couple of data
39// generated from inside the ISR are copied from time to time to be passed to the
40// main processor. When the data are available, the ISR signals it to the main processor.
41inline volatile int32_t copyOf_sumP_atSupplyPoint[NO_OF_PHASES];
42inline volatile int32_t copyOf_sum_Vsquared[NO_OF_PHASES];
43inline volatile float copyOf_energyInBucket_main;
46inline volatile uint16_t copyOf_countLoadON[NO_OF_DUMPLOADS];
47
48#ifdef TEMP_ENABLED
50#else
52#endif
53
55
56void processCurrentRawSample(const uint8_t phase, const int16_t rawSample);
57void processVoltageRawSample(const uint8_t phase, const int16_t rawSample);
58
59#if defined(__DOXYGEN__)
61inline void processStartUp(uint8_t phase);
62inline void processStartNewCycle();
63inline void processPlusHalfCycle(uint8_t phase);
64inline void processMinusHalfCycle(uint8_t phase);
65inline void processRawSamples(const uint8_t phase);
66inline void processVoltage(uint8_t phase);
67inline void processPolarity(uint8_t phase, int16_t rawSample);
68inline void confirmPolarity(uint8_t phase);
69inline void proceedLowEnergyLevel();
70inline void proceedHighEnergyLevel();
71inline uint8_t nextLogicalLoadToBeAdded();
72inline uint8_t nextLogicalLoadToBeRemoved();
73inline void processLatestContribution(uint8_t phase);
74inline void processDataLogging();
75inline void updatePortsStates();
76inline void updatePhysicalLoadStates();
77#else
78void initializeProcessing() __attribute__((optimize("-O3")));
79inline void processStartUp(uint8_t phase) __attribute__((always_inline));
80inline void processStartNewCycle() __attribute__((always_inline));
81inline void processPlusHalfCycle(uint8_t phase) __attribute__((always_inline));
82inline void processMinusHalfCycle(uint8_t phase) __attribute__((always_inline));
83inline void processRawSamples(const uint8_t phase) __attribute__((always_inline));
84inline void processVoltage(uint8_t phase) __attribute__((always_inline));;
85inline void processPolarity(uint8_t phase, int16_t rawSample) __attribute__((always_inline));
86inline void confirmPolarity(uint8_t phase) __attribute__((always_inline));
87inline void proceedLowEnergyLevel() __attribute__((always_inline));
88inline void proceedHighEnergyLevel() __attribute__((always_inline));
89inline uint8_t nextLogicalLoadToBeAdded() __attribute__((always_inline, optimize("-O3")));
90inline uint8_t nextLogicalLoadToBeRemoved() __attribute__((always_inline, optimize("-O3")));
91inline void processLatestContribution(uint8_t phase) __attribute__((always_inline));
92inline void processDataLogging() __attribute__((always_inline, optimize("-O3")));
93inline void updatePortsStates() __attribute__((optimize("-O3")));
94inline void updatePhysicalLoadStates() __attribute__((always_inline));
95#endif
96
97#endif /* PROCESSING_H */
container for datalogging
Definition types.h:73
Configuration values to be set by the end-user.
constexpr TemperatureSensing temperatureSensing
Definition config.h:84
constexpr uint8_t NO_OF_DUMPLOADS
Definition config.h:32
constexpr uint8_t NO_OF_PHASES
void initializeProcessing()
Initializes the processing engine, including ports, load states, and ADC setup.
void updatePhysicalLoadStates()
Updates the physical load states based on logical load priorities and states.
void processLatestContribution(uint8_t phase)
Process the latest contribution after each phase-specific new cycle.
void updatePortsStates()
Updates the control ports for each of the physical loads.
void processStartUp(uint8_t phase)
Processes the startup period for the router.
void processStartNewCycle()
Processes the start of a new mains cycle on phase 0.
void processMinusHalfCycle(uint8_t phase)
Processes the start of a new negative half cycle for the specified phase.
void processVoltageRawSample(const uint8_t phase, const int16_t rawSample)
Processes the current voltage raw sample for the specified phase.
void proceedLowEnergyLevel()
Handles the case when the energy level is low, potentially removing a load.
void processPolarity(uint8_t phase, int16_t rawSample)
Processes the polarity of the current voltage sample for a specific phase.
void processRawSamples(const uint8_t phase)
Processes raw voltage and current samples for the specified phase.
uint8_t nextLogicalLoadToBeAdded()
Retrieve the next logical load that could be added.
void processPlusHalfCycle(uint8_t phase)
Process the start of a new positive half cycle for the specified phase.
void processDataLogging()
Process data logging at the end of each logging period.
uint8_t nextLogicalLoadToBeRemoved()
Retrieve the next logical load that could be removed (in reverse order).
void confirmPolarity(uint8_t phase)
Confirms the polarity of the current voltage sample for a specific phase.
void processVoltage(uint8_t phase)
Processes the current voltage sample for the specified phase.
void proceedHighEnergyLevel()
Handles the case when the energy level is high, potentially adding a load.
void processCurrentRawSample(const uint8_t phase, const int16_t rawSample)
Processes the current raw sample for the specified phase.
volatile uint8_t copyOf_lowestNoOfSampleSetsPerMainsCycle
Definition processing.h:44
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
constexpr uint8_t sensorV[NO_OF_PHASES]
Definition processing.h:18
constexpr uint8_t sensorI[NO_OF_PHASES]
Definition processing.h:19
volatile float copyOf_energyInBucket_main
Definition processing.h:43
volatile int32_t copyOf_sumP_atSupplyPoint[NO_OF_PHASES]
Definition processing.h:41
volatile int32_t copyOf_sum_Vsquared[NO_OF_PHASES]
Definition processing.h:42
volatile uint16_t copyOf_sampleSetsDuringThisDatalogPeriod
Definition processing.h:45
volatile bool b_overrideLoadOn[NO_OF_DUMPLOADS]
Definition processing.h:33
void printParamsForSelectedOutputMode()
Print the settings used for the selected output mode.
volatile bool b_newMainsCycle
Definition processing.h:32
volatile bool EDD_isIdle
Definition processing.h:36
volatile bool b_datalogEventPending
Definition processing.h:31
volatile bool b_diversionOff
Definition processing.h:35
constexpr uint16_t initialDelay
Definition processing.h:26
PayloadTx_struct< NO_OF_PHASES > tx_data
Definition processing.h:51
volatile uint16_t absenceOfDivertedEnergyCount
Definition processing.h:30
volatile uint16_t copyOf_countLoadON[NO_OF_DUMPLOADS]
Definition processing.h:46