Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 95a03fb
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 23:53:49 2024 +0100

    Fix parameter

commit c23a6f8
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 23:49:06 2024 +0100

    Try with define

commit e690f89
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 23:25:20 2024 +0100

    Try another option

commit f022133
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 23:07:08 2024 +0100

    Revert not working option

commit 4faaae7
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 23:03:48 2024 +0100

    Try better template parsing

commit b08d716
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:51:40 2024 +0100

    Centralize defgroups

commit b173d9a
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:40:19 2024 +0100

    Fix doxyfile

commit 10cb40e
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:31:57 2024 +0100

    Make doxygen more verbose

commit 61acc00
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:22:39 2024 +0100

    Fix doc

commit 29d72ba
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:15:47 2024 +0100

    Fix doxygen

commit e9b70c9
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:12:22 2024 +0100

    Fix doc

commit 9b1587e
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:09:02 2024 +0100

    Fix doxygen groups

commit ec70ab2
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 22:05:57 2024 +0100

    Some doc tuning

commit eef1010
Author: Frédéric Metrich <[email protected]>
Date:   Sun Mar 10 21:42:19 2024 +0100

    Some doc + TEMA

commit 5aa1365
Author: Frédéric Metrich <[email protected]>
Date:   Sat Mar 9 18:34:52 2024 +0100

    Fix ewma

commit 16e5ba4
Author: Frédéric Metrich <[email protected]>
Date:   Sat Mar 9 13:02:04 2024 +0100

    Squashed commit of the following:

    commit fb99ae1
    Author: Frédéric Metrich <[email protected]>
    Date:   Sat Mar 9 12:45:35 2024 +0100

        Add DEMA

    commit 52892c2
    Author: Frédéric Metrich <[email protected]>
    Date:   Fri Mar 8 12:42:21 2024 +0100

        Add parenthesis

    commit 843ad1c
    Merge: f817917 8ef9f7b
    Author: Frédéric Metrich <[email protected]>
    Date:   Fri Mar 8 12:41:28 2024 +0100

        Merge branch 'multi-relays' of https://github.com/FredM67/PVRouter-3-phase into multi-relays

    commit f817917
    Author: Frédéric Metrich <[email protected]>
    Date:   Fri Mar 8 12:39:40 2024 +0100

        Try DEMA

    commit 8ef9f7b
    Author: Frédéric Metrich <[email protected]>
    Date:   Thu Mar 7 21:53:34 2024 +0100

        Try double EWMA

    commit f9cfd64
    Merge: 685e204 d3bedad
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Mar 6 10:08:53 2024 +0100

        Merge branch 'multi-relays' of https://github.com/FredM67/PVRouter-3-phase into multi-relays

    commit 685e204
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Mar 6 10:08:49 2024 +0100

        Fix test

    commit d3bedad
    Author: Frédéric Metrich <[email protected]>
    Date:   Tue Mar 5 23:01:56 2024 +0100

        Some doc

    commit fcf91d3
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Feb 28 21:03:13 2024 +0100

        Fix links

    commit cdbd3e6
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Feb 28 20:59:52 2024 +0100

        Default readme to fr

    commit b334503
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Feb 28 20:39:10 2024 +0100

        Set default to no relay

    commit a8160a0
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Feb 28 15:02:38 2024 +0100

        Typo

    commit 47b9ebe
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Feb 28 14:57:37 2024 +0100

        Multi relays engine

    commit 26f896b
    Author: Frédéric Metrich <[email protected]>
    Date:   Mon Feb 26 16:12:32 2024 +0100

        Squashed commit of the following:

        commit c73c567
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Feb 26 11:11:24 2024 +0100

            Add some alias for type_trait

        commit eb53c16
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Feb 26 11:10:55 2024 +0100

            Update color in schematic

        commit eac769e
        Author: Frédéric Metrich <[email protected]>
        Date:   Thu Feb 15 21:29:47 2024 +0100

            Update Readme.md (#82)

        commit 82d84ee
        Author: Frédéric Metrich <[email protected]>
        Date:   Tue Feb 13 14:37:48 2024 +0100

            Added Thermostat_tri_HC.pdf

        commit fad5e19
        Author: Frédéric Metrich <[email protected]>
        Date:   Tue Feb 13 14:36:53 2024 +0100

            Update Thermostat_tri_HC.drawio

        commit f03b4ca
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Feb 12 11:07:04 2024 +0100

            WIP: 1772479 Fix mvAvg

        commit 5e5646a
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Feb 5 00:04:30 2024 +0100

            Update CodeQL

        commit 4684e01
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:35:01 2024 +0100

            Upt readme

        commit d957494
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:32:24 2024 +0100

            Try again

        commit 46884f3
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:30:21 2024 +0100

            Try fix

        commit c7db21e
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:28:09 2024 +0100

            Fix readme

        commit 248a89a
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:23:14 2024 +0100

            Reorganize readmes

        commit fff68e0
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:11:19 2024 +0100

            Fix branch name

        commit 656308b
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:10:39 2024 +0100

            Fix filenames

        commit b911d8d
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:08:55 2024 +0100

            Fix links

        commit 83d5591
        Author: Frédéric Metrich <[email protected]>
        Date:   Sun Feb 4 23:07:18 2024 +0100

            Multilinugal readme + more details

        commit 1772479
        Author: Frédéric Metrich <[email protected]>
        Date:   Fri Feb 2 11:39:13 2024 +0100

            Fix mvAvg

        commit 90204aa
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Jan 22 22:02:08 2024 +0100

            Fix relay template

        commit eef84ea
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Jan 22 16:36:28 2024 +0100

            Enhanced sliding average...

        commit 1ea9c53
        Author: Frédéric Metrich <[email protected]>
        Date:   Tue Nov 14 05:22:20 2023 +0100

            Reorganize folders

        commit 8522341
        Author: Frédéric Metrich <[email protected]>
        Date:   Tue Nov 14 05:20:39 2023 +0100

            Upd

        commit a6a660b
        Author: Frédéric Metrich <[email protected]>
        Date:   Wed Nov 8 23:11:58 2023 +0100

            Update Readme.md

        commit 145c86e
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Nov 6 09:13:08 2023 +0100

            Update Readme.md

        commit 4d0936b
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Nov 6 07:40:13 2023 +0100

            Update Readme.md

        commit 85910b9
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Nov 6 07:21:08 2023 +0100

            Update Readme.md

        commit efbda93
        Author: Frédéric Metrich <[email protected]>
        Date:   Mon Nov 6 07:19:52 2023 +0100

            Update Readme.md (#79)

        commit cfb0204
        Author: Frédéric Metrich <[email protected]>
        Date:   Wed Oct 4 07:58:16 2023 +0200

            Formatting

        commit e0cefcd
        Author: Frédéric Metrich <[email protected]>
        Date:   Thu Sep 21 17:29:28 2023 +0200

            Fix comment

        commit 0cf1661
        Author: Frédéric Metrich <[email protected]>
        Date:   Thu Sep 21 13:21:59 2023 +0200

            Update schema

    commit 839af94
    Author: Frédéric Metrich <[email protected]>
    Date:   Wed Sep 20 15:58:02 2023 +0200

        Move pin assignment to ctor
  • Loading branch information
FredM67 committed Mar 12, 2024
1 parent 1106590 commit 6bb45d3
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 102 deletions.
9 changes: 5 additions & 4 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ EXTRACT_ALL = YES
# be included in the documentation.
# The default value is: NO.

EXTRACT_PRIVATE = NO
EXTRACT_PRIVATE = YES

# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual
# methods of a class will be included in the documentation.
Expand All @@ -488,7 +488,7 @@ EXTRACT_PACKAGE = NO
# included in the documentation.
# The default value is: NO.

EXTRACT_STATIC = NO
EXTRACT_STATIC = YES

# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
# locally in source files will be included in the documentation. If set to NO,
Expand Down Expand Up @@ -2177,6 +2177,7 @@ INCLUDE_FILE_PATTERNS =
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = __cdecl= \
__DOXYGEN__ \
TEMP_SENSOR \
OFF_PEAK_TARIFF \
RF_PRESENT \
Expand Down Expand Up @@ -2369,7 +2370,7 @@ UML_LIMIT_NUM_FIELDS = 10
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.

TEMPLATE_RELATIONS = NO
TEMPLATE_RELATIONS = YES

# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
# YES then doxygen will generate a graph for each documented file showing the
Expand Down Expand Up @@ -2511,7 +2512,7 @@ PLANTUML_INCLUDE_PATH =
# Minimum value: 0, maximum value: 10000, default value: 50.
# This tag requires that the tag HAVE_DOT is set to YES.

DOT_GRAPH_MAX_NODES = 50
DOT_GRAPH_MAX_NODES = 200

# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
# generated by dot. A depth value of 3 means that only nodes reachable from the
Expand Down
4 changes: 2 additions & 2 deletions Mk2_3phase_RFdatalog_temp/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ EXTRACT_ALL = YES
# be included in the documentation.
# The default value is: NO.

EXTRACT_PRIVATE = NO
EXTRACT_PRIVATE = YES

# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual
# methods of a class will be included in the documentation.
Expand All @@ -485,7 +485,7 @@ EXTRACT_PACKAGE = NO
# included in the documentation.
# The default value is: NO.

EXTRACT_STATIC = NO
EXTRACT_STATIC = YES

# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
# locally in source files will be included in the documentation. If set to NO,
Expand Down
40 changes: 39 additions & 1 deletion Mk2_3phase_RFdatalog_temp/Mk2_3phase_RFdatalog_temp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,49 @@
* - heavy refactoring (again)
* - stl add-ons
* - add relay-output feature
*
* __February 2024: changes:__
* - refactoring of 'temperature feature'
* - refactoring of 'relay feature'
* - new sliding average (EWMA)
* - more documentation
*
* __March 2024: changes:__
* - multi-relay feature
* - add DEMA and TEMA sliding average
* - some tiny fixes
* - even more documentation
*
* @author Fred Metrich
* @copyright Copyright (c) 2023
* @copyright Copyright (c) 2024
*
*/

/*!
* @defgroup TimeCritical Time critical functions
* Functions used by the ISR
*/

/*!
* @defgroup RelayDiversion Relay diversion feature
* Functions used for the relay diversion
*/

/*!
* @defgroup TemperatureSensing Temperature sensing feature
* Functions used for the temperature sensing
*/

/*!
* @defgroup DualTariff Dual tariff feature
* Functions used for the dual tariff feature
*/

/*!
* @defgroup RF RF feature
* Functions used for the RF feature
*/

static_assert(__cplusplus >= 201703L, "**** Please define 'gnu++17' in 'platform.txt' ! ****");
static_assert(__cplusplus >= 201703L, "See also : https://github.com/FredM67/PVRouter-3-phase/blob/main/Mk2_3phase_RFdatalog_temp/Readme.md");

Expand Down
3 changes: 3 additions & 0 deletions Mk2_3phase_RFdatalog_temp/dualtariff.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*
* @tparam N # of loads
* @tparam D
*
* @ingroup DualTariff
*/
template< uint8_t N, uint8_t OffPeakDuration = 8 >
class _rg_OffsetForce
Expand Down Expand Up @@ -65,6 +67,7 @@ inline constexpr auto rg_OffsetForce{ _rg_OffsetForce< NO_OF_DUMPLOADS, ul_OFF_P
/**
* @brief Print the settings for off-peak period
*
* @ingroup DualTariff
*/
inline void printDualTariffConfiguration()
{
Expand Down
38 changes: 37 additions & 1 deletion Mk2_3phase_RFdatalog_temp/ewma_avg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
* The parameter decides how important the current observation is in the calculation of the EWMA.
* The higher the value of alpha, the more closely the EWMA tracks the original time series.
*
* Computation of DEMA (Double EMA) with half-alpha has been added to get a better response of the average,
* especially when "peak inputs" are recorded.
*
* Computation of TEMA (Triple EMA) with quarter-alpha has been added to get a even better response of the average,
* especially when "peak inputs" are recorded. This seems to be the "optimal" solution.
*
* @section note Note
* This class is implemented in way to use only integer math.
* This comes with some restrictions on the alpha parameter, but the benefit of full integer math wins
Expand Down Expand Up @@ -71,26 +77,56 @@ template< uint8_t A = 10 >
class EWMA_average
{
public:
/**
* @brief Add a new value and actualize the EMA, DEMA and TEMA
*
* @param input The new value
*/
void addValue(int32_t input)
{
ema_raw = ema_raw - ema + input;
ema = ema_raw >> round_up_to_power_of_2(A);

ema_ema_raw = ema_ema_raw - ema_ema + ema;
ema_ema = ema_ema_raw >> round_up_to_power_of_2(A);
ema_ema = ema_ema_raw >> (round_up_to_power_of_2(A) - 1);

ema_ema_ema_raw = ema_ema_ema_raw - ema_ema_ema + ema_ema;
ema_ema_ema = ema_ema_ema_raw >> (round_up_to_power_of_2(A) - 2);
}

/**
* @brief Get the EMA
*
* @return auto The EMA value
*/
auto getAverageS() const
{
return ema;
}

/**
* @brief Get the DEMA
*
* @return auto The DEMA value
*/
auto getAverageD() const
{
return (ema << 1) - ema_ema;
}

/**
* @brief Get the TEMA
*
* @return auto The TEMA value
*/
auto getAverageT() const
{
return 3 * (ema - ema_ema) + ema_ema_ema;
}

private:
int32_t ema_ema_ema_raw{ 0 };
int32_t ema_ema_ema{ 0 };
int32_t ema_ema_raw{ 0 };
int32_t ema_ema{ 0 };
int32_t ema_raw{ 0 };
Expand Down
4 changes: 3 additions & 1 deletion Mk2_3phase_RFdatalog_temp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static_assert(__cplusplus >= 201703L, "See also : https://github.com/FredM67/PVR

/**
* @brief Interrupt Service Routine - Interrupt-Driven Analog Conversion.
*
* @details 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.
*
Expand All @@ -71,6 +72,7 @@ static_assert(__cplusplus >= 201703L, "See also : https://github.com/FredM67/PVR
* - Variables shared with main code may need to be protected by "critical sections"
* - Don't try to turn interrupts off or on
*
* @ingroup TimeCritical
*/
ISR(ADC_vect)
{
Expand Down Expand Up @@ -425,7 +427,7 @@ void loop()

tx_data.temperature_x100[idx] = tmp;
} while (idx);

temperatureSensing.requestTemperatures(); // for use next time around
}

Expand Down
22 changes: 13 additions & 9 deletions Mk2_3phase_RFdatalog_temp/processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
#include "processing.h"
#include "utils_pins.h"

/*!
* @defgroup TimeCritical Time critical functions Group
* Functions used by the ISR
*/

int32_t l_DCoffset_V[NO_OF_PHASES]; /**< <--- for LPF */

// Define operating limits for the LP filters which identify DC offset in the voltage
Expand Down Expand Up @@ -412,7 +407,7 @@ void processStartUp(const uint8_t phase)
void proceedHighEnergyLevel()
{
bool bOK_toAddLoad{ true };
auto tempLoad{ nextLogicalLoadToBeAdded() };
const auto tempLoad{ nextLogicalLoadToBeAdded() };

if (tempLoad >= NO_OF_DUMPLOADS)
{
Expand Down Expand Up @@ -453,7 +448,7 @@ void proceedHighEnergyLevel()
void proceedLowEnergyLevel()
{
bool bOK_toRemoveLoad{ true };
auto tempLoad{ nextLogicalLoadToBeRemoved() };
const auto tempLoad{ nextLogicalLoadToBeRemoved() };

if (tempLoad >= NO_OF_DUMPLOADS)
{
Expand Down Expand Up @@ -575,10 +570,13 @@ void processMinusHalfCycle(const uint8_t phase)
}
}

#if !defined(__DOXYGEN__)
uint8_t nextLogicalLoadToBeAdded() __attribute__((optimize("-O3")));
#endif
/**
* @brief Retrieve the next load that could be added (be aware of the order)
*
* @return The load number if successfull, NO_OF_DUMPLOADS in case of failure
* @return The load number if successful, NO_OF_DUMPLOADS in case of failure
*
* @ingroup TimeCritical
*/
Expand All @@ -596,6 +594,9 @@ uint8_t nextLogicalLoadToBeAdded()
return (NO_OF_DUMPLOADS);
}

#if !defined(__DOXYGEN__)
uint8_t nextLogicalLoadToBeRemoved() __attribute__((optimize("-O3")));
#endif
/**
* @brief Retrieve the next load that could be removed (be aware of the reverse-order)
*
Expand All @@ -620,7 +621,7 @@ uint8_t nextLogicalLoadToBeRemoved()
}

/**
* @brief Process the lastest contribution after each phase specific new cycle
* @brief Process the latest contribution after each phase specific new cycle
* additional processing is performed after each main cycle based on phase 0.
*
* @param phase the phase number [0..NO_OF_PHASES[
Expand All @@ -644,6 +645,9 @@ void processLatestContribution(const uint8_t phase)
//
}

#if !defined(__DOXYGEN__)
void processDataLogging() __attribute__((optimize("-O3")));
#endif
/**
* @brief Process with data logging.
* @details At the end of each datalogging period, copies are made of the relevant variables
Expand Down
15 changes: 15 additions & 0 deletions Mk2_3phase_RFdatalog_temp/processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ void processRawSamples(uint8_t phase);

void processVoltage(uint8_t phase);

#if defined(__DOXYGEN__)
inline void processStartUp(uint8_t phase);
inline void processStartNewCycle();
inline void processPlusHalfCycle(uint8_t phase);
inline void processMinusHalfCycle(uint8_t phase);
inline void processVoltage(uint8_t phase);
inline void processPolarity(uint8_t phase, int16_t rawSample);
inline void confirmPolarity(uint8_t phase);
inline void proceedLowEnergyLevel();
inline void proceedHighEnergyLevel();
inline uint8_t nextLogicalLoadToBeAdded();
inline uint8_t nextLogicalLoadToBeRemoved();
inline void processLatestContribution(uint8_t phase);
#else
inline void processStartUp(uint8_t phase) __attribute__((always_inline));
inline void processStartNewCycle() __attribute__((always_inline));
inline void processPlusHalfCycle(uint8_t phase) __attribute__((always_inline));
Expand All @@ -74,6 +88,7 @@ inline void proceedHighEnergyLevel() __attribute__((always_inline));
inline uint8_t nextLogicalLoadToBeAdded() __attribute__((always_inline));
inline uint8_t nextLogicalLoadToBeRemoved() __attribute__((always_inline));
inline void processLatestContribution(uint8_t phase) __attribute__((always_inline));
#endif

void processDataLogging();

Expand Down
3 changes: 1 addition & 2 deletions Mk2_3phase_RFdatalog_temp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ inline void printConfiguration()
DBUGLN(F("is present"));

relays.printConfiguration();
relays.printConfiguration();
}
else
{
Expand Down Expand Up @@ -265,8 +266,6 @@ inline void printForSerialText()
{
Serial.print(F("/"));
Serial.print(relays.get_average());
Serial.print(F("/"));
Serial.print(relays.get_averageD());
}

for (phase = 0; phase < NO_OF_PHASES; ++phase)
Expand Down
12 changes: 12 additions & 0 deletions Mk2_3phase_RFdatalog_temp/utils_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

#include <Arduino.h>

#if defined(__DOXYGEN__)
inline constexpr void togglePin(const uint8_t pin);

inline constexpr void setPinON(const uint8_t pin);
inline void setPinsON(const uint16_t pins);

inline constexpr void setPinOFF(const uint8_t pin);
inline void setPinsOFF(const uint16_t pins);

inline bool getPinState(const uint8_t pin);
#else
inline constexpr void togglePin(const uint8_t pin) __attribute__((always_inline));

inline constexpr void setPinON(const uint8_t pin) __attribute__((always_inline));
Expand All @@ -23,6 +34,7 @@ inline constexpr void setPinOFF(const uint8_t pin) __attribute__((always_inline)
inline void setPinsOFF(const uint16_t pins) __attribute__((always_inline));

inline bool getPinState(const uint8_t pin) __attribute__((always_inline));
#endif

/**
* @brief Set the specified bit to 1
Expand Down
Loading

0 comments on commit 6bb45d3

Please sign in to comment.