3-phase PV router
Loading...
Searching...
No Matches
temp_schedule.h File Reference

Which 1-Wire transaction of the temperature sensors runs on which mains cycle. More...

#include <stdint.h>
Include dependency graph for temp_schedule.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TempSchedule::Action
 The transaction to run, and the sensor it reads (ADDRESS, READ, CLOSE). More...
 
class  TempSchedule::Scheduler< N, CONVERSION_CYCLES >
 The round of the sensors, one transaction per mains cycle. More...
 

Namespaces

namespace  TempSchedule
 

Enumerations

enum class  TempSchedule::Step : uint8_t {
  TempSchedule::NONE , TempSchedule::CONVERT , TempSchedule::ADDRESS , TempSchedule::READ ,
  TempSchedule::CLOSE
}
 The 1-Wire transaction of a mains cycle. More...
 

Functions

constexpr uint16_t TempSchedule::conversionCycles (const uint8_t supplyFrequency)
 The mains cycles from the conversion to the first read.
 
constexpr bool TempSchedule::fitsInPeriod (const uint8_t noOfSensors, const uint8_t supplyFrequency, const uint16_t periodCycles)
 Whether a round ends within its datalog period.
 
constexpr uint16_t TempSchedule::roundCycles (const uint8_t noOfSensors, const uint8_t supplyFrequency)
 The mains cycles of a round on time: from the conversion to the last CLOSE.
 

Variables

constexpr uint16_t TempSchedule::CONVERSION_MS { 750 }
 
constexpr uint8_t TempSchedule::STEPS_PER_SENSOR { 3 }
 

Detailed Description

Which 1-Wire transaction of the temperature sensors runs on which mains cycle.

Author
Frédéric Metrich (frede.nosp@m.ric..nosp@m.metri.nosp@m.ch@l.nosp@m.ive.f.nosp@m.r)
Version
0.1
Date
2026-11-23

A reset of the 1-Wire bus, and each 0 written, keep interrupts off for 65 to 70 µs (the OneWire library): the ADC interrupt then starts up to ~1100 cycles late, and must still write ADMUX within the 1664 cycles of its conversion. The heaviest ADC interrupts are those of the mains cycle's work, run once per cycle shortly after L1's positive crossing (processing.cpp, processStartNewCycle()): a slot that delays one of them can make it miss that deadline. The calls at the other crossings (each phase's half cycles) are lighter.

The main loop therefore runs the bus I/O as short transactions, one per mains cycle at most, each started as soon as the loop sees the new cycle (Shared::b_newMainsCycle, set once processStartNewCycle() is done): its long slots end before the negative crossing, among the ordinary ADC interrupts. A round:

  • the conversion of every sensor (reset, Skip ROM, Convert T);
  • once the conversion time has passed, for each sensor:
    • ADDRESS: reset, Match ROM and the first 4 bytes of its ROM code,
    • READ: the last 4 bytes, Read Scratchpad and the 9 bytes of the scratchpad (a read slot keeps interrupts off ~13 µs only: these may run past the negative crossing),
    • CLOSE: the reset that checks the sensor is still there; the reading is decoded. The bus allows any pause between two time slots: a transaction split over cycles is still a valid one.

A transaction runs only on a cycle seen on time, the loop idle when it began: after a long pass (the per-second work, the display, an RF frame), the flag may be several milliseconds old, and the transaction waits for the next cycle.

One round per datalog period: started when the loop handles the end of the period (before the datalog output, whose UART interrupts would add to the delay of the ADC interrupt), or at the next cycle, it ends long before the period does (fitsInPeriod()), and the datalog sends its values. With sensors built in, the loop handles the datalog event, raised at L1's crossing, on the pass that sees the new cycle: 1248 us after the event, and the datalog output of a temperature build is that much later.

Note
This header has no Arduino dependency, so it can be exercised by the native test suite.

Definition in file temp_schedule.h.