3-phase PV router
Loading...
Searching...
No Matches
config_derived.h
Go to the documentation of this file.
1
23
24#ifndef CONFIG_DERIVED_H
25#define CONFIG_DERIVED_H
26
27#include "config_system.h"
28#include "config.h"
29
30// A config.h of the former layout defines CONFIG_H (debug.h stops on it too, with the reason)
31#if defined(CONFIG_H)
32#error "This config.h has the former layout, with #include lines and derived values. config.h now only holds the settings: create it again with the configurator, or see 'config.h holds the settings only' in the CHANGELOG to update it by hand."
33#endif
34
35#include "types.h"
36#include "debug.h"
37
38//--------------------------------------------------------------------------------------------------
39// From calibration.h: the values of the board, as the firmware uses them
40//
41#include "calibration.h"
42
43static_assert(NO_OF_PHASES == 3, "f_powerCal and f_voltageCal below list 3 phases");
44
47
52
57
58//--------------------------------------------------------------------------------------------------
59// From the sampling: a V and an I conversion per phase in a sample set (adc_chain.h), and the
60// datalog period
61//
62#include "adc_chain.h"
63#include "datalog_math.h"
64
65// Expected number of sample sets per mains cycle. One ADC conversion takes 13 ADC clocks
66// at F_CPU / 128 (104 us at 16 MHz); a sample set is one V and one I conversion per phase.
67inline constexpr uint8_t ADC_CLOCKS_PER_CONVERSION{ 13 };
68inline constexpr uint8_t ADC_PRESCALER{ 128 };
69inline constexpr uint32_t SAMPLE_SET_PERIOD_US{ 1UL * AdcChain::NO_OF_CONVERSIONS * ADC_CLOCKS_PER_CONVERSION * ADC_PRESCALER / (F_CPU / 1000000UL) };
70inline constexpr uint8_t SAMPLE_SETS_PER_CYCLE{ 1000000UL / (SUPPLY_FREQUENCY * SAMPLE_SET_PERIOD_US) };
71inline constexpr uint8_t SAMPLE_SETS_MARGIN{ 4 };
72inline constexpr uint8_t N_MIN{ SAMPLE_SETS_PER_CYCLE - SAMPLE_SETS_MARGIN };
73inline constexpr uint8_t N_MAX{ SAMPLE_SETS_PER_CYCLE + SAMPLE_SETS_MARGIN };
74
76inline constexpr uint32_t MAX_SAMPLE_SETS_PER_DATALOG{ static_cast< uint32_t >(DATALOG_PERIOD_IN_MAINS_CYCLES) * N_MAX };
79
80//--------------------------------------------------------------------------------------------------
81// From the load map
82//
85inline constexpr bool REMOTE_LOADS_PRESENT{ NO_OF_REMOTE_LOADS != 0 };
86
87#include "remote_loads_core.h"
88
99
100//--------------------------------------------------------------------------------------------------
101// The objects built from the settings
102//
103#include "rotation_groups.h"
104#include "utils_dualtariff.h"
105#include "utils_override.h"
106#include "utils_relay.h"
107#include "utils_temp.h"
108
111
112inline constexpr RelayDiverter relayDiverter{ relays };
118
119#include "remote_loads.h" // the RF shell; needs remoteLoads and the RF feature flags
120
121#endif /* CONFIG_DERIVED_H */
The six ADC conversions of the 3-phase board, and the ADMUX pipeline of the free-running ADC.
Calibration values definition.
constexpr float f_ctRating[NO_OF_PHASES]
Definition calibration.h:52
constexpr float f_powerCalPerAmp[NO_OF_PHASES]
Definition calibration.h:53
constexpr float f_powerCalOldBoard[NO_OF_PHASES]
Definition calibration.h:38
constexpr float f_voltageCalOldBoard[NO_OF_PHASES]
Definition calibration.h:43
constexpr float f_voltageCalNewBoard[NO_OF_PHASES]
Definition calibration.h:54
The scheduled boosts: a window and the bitmasks of its targets, for each entry.
Manages override pins and their associated bitmasks for forced operation.
Manages a collection of relays and their behavior based on surplus and import thresholds.
Builds and schedules the RF payloads of every remote unit.
The rotation groups, resolved: the priority places each group holds.
What the target codes of config.h stand for, once the load map and the relays are known.
Implements temperature sensing functionality for multiple sensors.
Definition utils_temp.h:97
Router configuration: loads, relays, control pins and features.
constexpr uint8_t loadPrioritiesAtStartup[NO_OF_DUMPLOADS]
Definition config.h:91
constexpr ScheduledBoosts scheduledBoosts
Definition config.h:172
constexpr bool RELAY_DIVERSION
Definition config.h:63
constexpr TemperatureSensing temperatureSensing
Definition config.h:177
constexpr PcbVersion PCB_VERSION
Definition config.h:21
constexpr RelayEngine relays
Definition config.h:130
constexpr uint8_t physicalLoadPin[NO_OF_DUMPLOADS]
Definition config.h:50
constexpr OverridePins overridePins
Definition config.h:157
constexpr RotationGroups rotationGroups
Definition config.h:100
constexpr uint8_t ADC_PRESCALER
RemoteLoadCore< NO_OF_REMOTE_UNITS > remoteLoads
The one and only remote-load controller.
constexpr uint8_t SAMPLE_SETS_MARGIN
constexpr TargetMap targetMap
What LOAD(), RELAY() and ALL_...() stand for, in overridePins and scheduledBoosts.
constexpr uint8_t SAMPLE_SETS_PER_CYCLE
constexpr uint8_t ADC_CLOCKS_PER_CONVERSION
constexpr uint32_t SAMPLE_SET_PERIOD_US
constexpr Rotation::Table rotationTable
The priority places each rotation group rotates in.
constexpr float f_voltageCal[NO_OF_PHASES]
constexpr uint32_t MAX_SAMPLE_SETS_PER_DATALOG
constexpr bool REMOTE_LOADS_PRESENT
constexpr uint8_t NO_OF_REMOTE_UNITS
constexpr BoostSchedule boostSchedule
constexpr bool NEW_BOARD_CALIBRATION
constexpr RelayDiverter relayDiverter
constexpr uint8_t N_MIN
constexpr float f_powerCal[NO_OF_PHASES]
constexpr uint8_t N_MAX
constexpr TempSensors tempSensors
constexpr uint8_t DATALOG_POWER_SHIFT
constexpr OverrideTable overrideTable
constexpr uint8_t NO_OF_REMOTE_LOADS
Basic configuration values to be set by the end-user.
constexpr conditional< DATALOG_PERIOD_IN_SECONDS *SUPPLY_FREQUENCY >=UINT8_MAX, uint16_t, uint8_t >::type DATALOG_PERIOD_IN_MAINS_CYCLES
constexpr uint8_t NO_OF_PHASES
constexpr uint8_t SUPPLY_FREQUENCY
Integer arithmetic of the datalog: power and RMS voltage per phase.
The text output: informational messages (info) and debug messages (debug)
constexpr uint8_t NO_OF_CONVERSIONS
Definition adc_chain.h:44
constexpr uint8_t powerShift(const uint32_t maxSampleSets)
The shift by which the ISR scales the power down before adding it to the datalog sum.
constexpr uint8_t countUnits(const uint8_t(&map)[N])
Highest remote unit number appearing in the map (0 if fully local).
Definition load_map.h:110
constexpr uint8_t countRemoteLoads(const uint8_t(&map)[N])
Number of entries of the map that are driven remotely.
Definition load_map.h:127
Support for remotely controlled loads via RF using RFM69.
Unit grouping and payload bookkeeping for remotely controlled loads.
The rotation groups: which loads take turns, checked and resolved at compile time.
Some basics classes/types.
Some utility functions for dual tariff feature.
Compile-time utilities for managing override pins and index-to-bitmask mapping.
Some utility functions for the relay output feature.
Provides utilities for managing temperature sensors.