3-phase PV router
|
Functions used by the ISR. More...
Functions | |
void | confirmPolarity (const uint8_t phase) |
Confirms the polarity of the current voltage sample for a specific phase. | |
ISR (ADC_vect) | |
Interrupt Service Routine - Interrupt-Driven Analog Conversion. | |
uint8_t | nextLogicalLoadToBeAdded () |
Retrieve the next logical load that could be added. | |
uint8_t | nextLogicalLoadToBeRemoved () |
Retrieve the next logical load that could be removed (in reverse order). | |
void | proceedHighEnergyLevel () |
Handles the case when the energy level is high, potentially adding a load. | |
void | proceedLowEnergyLevel () |
Handles the case when the energy level is low, potentially removing a load. | |
void | processCurrentRawSample (const uint8_t phase, const int16_t rawSample) |
Processes the current raw sample for the specified phase. | |
void | processDataLogging () |
Process data logging at the end of each logging period. | |
void | processLatestContribution (const uint8_t phase) |
Process the latest contribution after each phase-specific new cycle. | |
void | processMinusHalfCycle (const uint8_t phase) |
Processes the start of a new negative half cycle for the specified phase. | |
void | processPlusHalfCycle (const uint8_t phase) |
Process the start of a new positive half cycle for the specified phase. | |
void | processPolarity (const uint8_t phase, const 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. | |
void | processStartNewCycle () |
Processes the start of a new mains cycle on phase 0. | |
void | processStartUp (const uint8_t phase) |
Processes the startup period for the router. | |
void | processVoltage (const uint8_t phase) |
Processes the current voltage sample 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 | updatePhysicalLoadStates () |
Updates the physical load states based on logical load priorities and states. | |
void | updatePortsStates () |
Updates the control ports for each of the physical loads. | |
Functions used by the ISR.
This group contains functions that are executed within the Interrupt Service Routine (ISR) or are closely tied to time-sensitive operations. These functions are optimized for speed and efficiency to ensure the system operates without delays or interruptions.
|
inline |
Confirms the polarity of the current voltage sample for a specific 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.
phase | The phase number [0..NO_OF_PHASES[. |
Definition at line 457 of file processing.cpp.
ISR | ( | ADC_vect | ) |
Interrupt Service Routine - Interrupt-Driven Analog Conversion.
An Interrupt Service Routine is now defined which instructs the ADC to perform a conversion for each of the voltage and current sensors in turn.
This Interrupt Service Routine is for use when the ADC is in the free-running mode. It is executed whenever an ADC conversion has finished, approx every 104 µs. In free-running mode, the ADC has already started its next conversion by the time that the ISR is executed. The ISR therefore needs to "look ahead".
At the end of conversion Type N, conversion Type N+1 will start automatically. The ISR which runs at this point therefore needs to capture the results of conversion Type N, and set up the conditions for conversion Type N+2, and so on.
By means of various helper functions, all of the time-critical activities are processed within the ISR.
The main code is notified by means of a flag when fresh copies of loggable data are available.
Keep in mind, when writing an Interrupt Service Routine (ISR):
Definition at line 1079 of file processing.cpp.
|
inline |
Retrieve the next logical load that could be added.
This function identifies the next logical load that can be added based on the current load priorities and states. It iterates through the load priorities to find the first load that is currently OFF.
NO_OF_DUMPLOADS
if no load can be added. Definition at line 761 of file processing.cpp.
|
inline |
Retrieve the next logical load that could be removed (in reverse order).
This function identifies the next logical load that can be removed based on the current load priorities and states. It iterates through the load priorities in reverse order to find the first load that is currently ON.
NO_OF_DUMPLOADS
if no load can be removed. Definition at line 786 of file processing.cpp.
|
inline |
Handles the case when the energy level is high, potentially adding a load.
This function determines if a new load can be added based on the current energy level and recent transitions. It updates the logical load states and thresholds accordingly.
Definition at line 562 of file processing.cpp.
|
inline |
Handles the case when the energy level is low, potentially removing a load.
This function determines if a load can be removed based on the current energy level and recent transitions. It updates the logical load states and thresholds accordingly.
Definition at line 611 of file processing.cpp.
void processCurrentRawSample | ( | const uint8_t | phase, |
const int16_t | rawSample ) |
Processes the current raw sample for the specified phase.
This function processes the raw current sample for a specific phase by applying filtering to remove DC offset, compensating for the high-pass filter effect of current transformers (CTs), and calculating the instantaneous power.
phase | The phase number [0..NO_OF_PHASES[. |
rawSample | The current raw sample for the specified phase. |
Definition at line 418 of file processing.cpp.
|
inline |
Process data logging at the end of each logging period.
This function handles the data logging process by copying relevant variables for use by the main code and resetting them for the next logging period.
Definition at line 847 of file processing.cpp.
|
inline |
Process the latest contribution after each phase-specific new cycle.
This function calculates and updates the energy contribution for the specified phase after each new cycle. It ensures that the energy bucket is updated with the latest power measurements and applies necessary adjustments.
phase | The phase number [0..NO_OF_PHASES[. |
Definition at line 816 of file processing.cpp.
|
inline |
Processes the start of a new negative half cycle for the specified phase.
This function is called just after the zero-crossing point of a negative half cycle. It updates the low-pass filter (LPF) for removing the DC component from the voltage signal and ensures the LPF output remains within defined limits.
phase | The phase number [0..NO_OF_PHASES[. |
Definition at line 725 of file processing.cpp.
|
inline |
Process the start of a new positive half cycle for the specified phase.
This function is called just after the zero-crossing point of a positive half cycle. It processes the latest energy contribution, updates performance metrics, and handles data logging for phase 0.
phase | The phase number [0..NO_OF_PHASES[. |
Definition at line 904 of file processing.cpp.
|
inline |
Processes the polarity of the current voltage sample for a specific phase.
This function removes the DC offset from the raw voltage sample and determines the polarity (positive or negative) of the sample. The polarity is stored for use in zero-crossing detection and other processing tasks.
phase | The phase number [0..NO_OF_PHASES[. |
rawSample | The current raw voltage sample for the specified phase. |
Definition at line 393 of file processing.cpp.
|
inline |
Processes raw voltage and current samples for the specified phase.
This routine is called by the ISR when a pair of voltage and current samples becomes available. It handles the processing of raw samples, including polarity detection, zero-crossing handling, and half-cycle processing.
phase | The phase number [0..NO_OF_PHASES[. |
Definition at line 942 of file processing.cpp.
|
inline |
Processes the start of a new mains cycle on phase 0.
This function is executed once per 20ms (for 50Hz), shortly after the start of each new mains cycle on phase 0. It manages the energy level and load states, ensuring proper operation of the system.
Definition at line 662 of file processing.cpp.
|
inline |
Processes the startup period for the router.
This function handles the initial startup period, allowing the DC-blocking filters to settle before normal operation begins. It ensures that the system is stable before processing energy and load states.
phase | The phase number [0..NO_OF_PHASES[. |
Definition at line 530 of file processing.cpp.
|
inline |
Processes the current voltage sample for the specified phase.
This function processes the voltage sample for a specific phase by calculating the cumulative voltage squared (V²) for RMS calculations, updating the low-pass filter for DC offset removal, and preparing for zero-crossing detection.
phase | The phase number [0..NO_OF_PHASES[. |
Definition at line 491 of file processing.cpp.
void processVoltageRawSample | ( | const uint8_t | phase, |
const int16_t | rawSample ) |
Processes the current voltage raw sample for the specified phase.
This function processes the raw voltage sample for a specific phase by handling polarity detection, zero-crossing confirmation, and voltage processing. It ensures that the voltage sample is properly filtered and analyzed for further processing.
phase | The phase number [0..NO_OF_PHASES[. |
rawSample | The current raw voltage sample for the specified phase. |
Definition at line 999 of file processing.cpp.
|
inline |
Updates the physical load states based on logical load priorities and states.
This function maps the logical load states to the physical load states. It ensures that the physical loads are updated according to the logical priorities and states. The function also handles priority rotation if enabled.
The array, logicalLoadState[], contains the on/off state of all logical loads, with element 0 being for the one with the highest priority. The array, physicalLoadState[], contains the on/off state of all physical loads.
The lowest 7 bits of element is the load number as defined in 'physicalLoadState'. The highest bit of each 'loadPrioritiesAndState' determines if the load is ON or OFF. The order of each element in 'loadPrioritiesAndState' determines the load priority. 'loadPrioritiesAndState[i] & loadStateMask' will extract the load number at position 'i' 'loadPrioritiesAndState[i] & loadStateOnBit' will extract the load state at position 'i'
Any other mapping relationships could be configured here.
Definition at line 334 of file processing.cpp.
|
inline |
Updates the control ports for each of the physical loads.
This function determines the ON/OFF state of each physical load and updates the corresponding control ports. It ensures that the correct pins are set to their respective states based on the load's current status.
pinsOFF
mask.pinsON
mask.setPinsOFF
and setPinsON
functions. Definition at line 282 of file processing.cpp.