3-phase PV router
Loading...
Searching...
No Matches
main.cpp File Reference

Main code for the PVRouter 3-phase project. More...

#include <Arduino.h>
#include "config_derived.h"
#include "datalog_math.h"
#include "pin_edges.h"
#include "processing.h"
#include "shared_var.h"
#include "types.h"
#include "utils.h"
#include "utils_relay.h"
#include "validation.h"
#include "main.h"
#include "override_masks.h"
#include "temp_schedule.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

OverrideMasks getDualTariffForcingBitmask (const bool bOffPeak, const int16_t currentTemperature_x100)
 Calculates the dual tariff forcing bitmasks based on current conditions.
 
OverrideMasks getOverrideBitmask (const bool bOffPeak, const int16_t currentTemperature_x100)
 Gets the combined bitmasks of all active override pins and dual tariff forcing.
 
void handlePerSecondTasks (bool &bOffPeak, int16_t &iTemperature_x100)
 Handles tasks that need to be executed every second.
 
bool isDiversionEnabled ()
 Reads the diversion pin.
 
bool isRouterOff ()
 Tells whether the router is OFF.
 
void loop ()
 Main processor loop.
 
bool proceedDualTariffLogic ()
 Handles dual tariff state transitions and priority rotation during off-peak periods.
 
void proceedLoadPriorities (const bool bOverridden)
 Handles load priority rotation.
 
void proceedRotation ()
 Proceeds with load priority rotation.
 
void processTemperatureData (const bool bStartNow)
 Processes temperature data from DS18B20 sensors.
 
template<uint8_t pin>
PinEdges readPinEdges ()
 Reads an active-LOW input pin, and tells how it changed since the previous reading.
 
void runTemperatureTransaction (const bool onTime)
 Runs the 1-Wire transaction of this mains cycle, if any.
 
void setup ()
 Called once during startup.
 
void updatePowerAndVoltageData ()
 Updates power and voltage data for all phases.
 

Variables

int16_t temperatureReadings [tempSensors.size()]
 The last reading of each sensor, in hundredths of °C, as endRead() returned it (none yet: setup()).
 
TempSchedule::Scheduler< tempSensors.size(), TempSchedule::conversionCycles(SUPPLY_FREQUENCY) > tempSchedule
 The round of the temperature sensors: one 1-Wire transaction per mains cycle (temp_schedule.h).
 

Detailed Description

Main code for the PVRouter 3-phase project.

Author
Frédéric Metrich (frede.nosp@m.ric..nosp@m.metri.nosp@m.ch@l.nosp@m.ive.f.nosp@m.r)

This file contains the main logic for the PVRouter, including the setup and loop functions, as well as interrupt service routines (ISRs) and utility functions for managing load priorities, temperature sensing, and telemetry data.

  • Interrupt-Driven Analog Conversion: Uses an ISR to process ADC data for voltage and current sensors.
  • Load Management: Includes functions for load priority rotation, forced full power, and dual tariff handling.
  • Telemetry: Sends telemetry data in various formats (e.g., IoT, JSON).
  • Temperature Sensing: Supports DS18B20 sensors for temperature monitoring.
  • Watchdog: Toggles a pin to indicate system activity.
Version
0.1
Date
2026-11-24

Definition in file main.cpp.

Variable Documentation

◆ temperatureReadings

int16_t temperatureReadings[tempSensors.size()]

The last reading of each sensor, in hundredths of °C, as endRead() returned it (none yet: setup()).

Definition at line 56 of file main.cpp.

◆ tempSchedule

The round of the temperature sensors: one 1-Wire transaction per mains cycle (temp_schedule.h).

Definition at line 53 of file main.cpp.