|
3-phase PV router
|
Functions used by the ISR. More...
Files | |
| file | load_priorities.h |
| The load priority state machine: which load to switch at each mains cycle. | |
Classes | |
| struct | adc_ctx_t |
| Interrupt Service Routine - Interrupt-Driven Analog Conversion. More... | |
Functions | |
| void | confirmPolarity (const uint8_t phase) |
| Confirms the polarity of the current voltage sample for a specific phase. | |
| template<typename V, typename F> | |
| static void | mult16x8_q8 (int16_t &result, V value, F fraction) |
| Optimized 16×8→16 signed multiplication with Q8 fractional. | |
| template<typename A, typename B> | |
| static void | multS16x16_to32 (int32_t &result, A a, B b) |
| Optimized 16×16→32 signed multiplication with assembly. | |
| template<typename A, typename B> | |
| static void | multU16x16_to32 (uint32_t &result, A a, B b) |
| Optimized 16×16→32 unsigned multiplication with assembly. | |
| template<typename A, typename B> | |
| static void | multU24x16_to32_hi8 (uint32_t &result, A a, B b) |
| Optimized 24×16→40 unsigned multiplication, returning bits 8..39. | |
| void | processCurrentRawSample (const uint8_t phase, const uint16_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 uint16_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 uint16_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 596 of file processing.cpp.

|
inlinestatic |
Optimized 16×8→16 signed multiplication with Q8 fractional.
This function performs a signed 16-bit × unsigned 8-bit Q8 fractional multiplication with rounding, returning a 16-bit result. The 8-bit value is treated as a fraction (Q8 format: 8 fractional bits).
| result | Reference to int16_t variable to store the result |
| value | 16-bit signed value |
| fraction | 8-bit unsigned fraction (Q8 format: 0.0 to 0.996) |
Definition at line 206 of file mult_asm.h.

|
inlinestatic |
Optimized 16×16→32 signed multiplication with assembly.
This function performs a signed 16-bit × 16-bit multiplication returning a 32-bit result using hand-optimized AVR assembly. It's significantly faster than GCC's library multiplication functions.
| result | Reference to int32_t variable to store the result |
| a | First 16-bit signed value |
| b | Second 16-bit signed value |
Definition at line 47 of file mult_asm.h.

|
inlinestatic |
Optimized 16×16→32 unsigned multiplication with assembly.
This function performs an unsigned 16-bit × 16-bit multiplication returning a 32-bit result using hand-optimized AVR assembly. It's significantly faster than GCC's library multiplication functions.
| result | Reference to uint32_t variable to store the result |
| a | First 16-bit unsigned value |
| b | Second 16-bit unsigned value |
Definition at line 97 of file mult_asm.h.

|
inlinestatic |
Optimized 24×16→40 unsigned multiplication, returning bits 8..39.
Computes (a × b) >> 8 without a 64-bit multiply (which would call __muldi3). Used by the integer energy bucket, where the product of an average power (up to 2^18) and a 16-bit calibration constant needs ~35 bits.
| result | Reference to uint32_t variable to store (a × b) >> 8 |
| a | Unsigned value, only its low 24 bits are used (must be < 2^24) |
| b | 16-bit unsigned value |
Definition at line 144 of file mult_asm.h.

|
inline |
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 538 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 865 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 806 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 refreshes the DC offset used to remove the DC component from the voltage signal.
| phase | The phase number [0..NO_OF_PHASES[. |
l_filterDC_V is a Q17.15 integrator: processVoltage() adds every i_sampleVminusDC to it, so each sample feeds back with a gain of 1/32768.test/native/test_dc_offset_filter for the tracking and step-response cases. Definition at line 782 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 922 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 511 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 975 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 719 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 677 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 630 of file processing.cpp.


|
inline |
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 1032 of file processing.cpp.


| void updatePhysicalLoadStates | ( | ) |
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 455 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.
pinsOFF mask.pinsON mask.setPinsState, one write per port, and only on the ports the load pins are on.Definition at line 392 of file processing.cpp.

