Detail of my sketch, Mk2_fasterControl_1a.ino * * (initially released as Mk2_bothDisplays_1 in March 2014) * This sketch is for diverting suplus PV power to a dump load using a triac or * Solid State Relay. It is based on the Mk2i PV Router code that I have posted in on * the OpenEnergyMonitor forum. The original version, and other related material, * can be found on my Summary Page at www.openenergymonitor.org/emon/node/1757 * * In this latest version, the pin-allocations have been changed to suit my * PCB-based hardware for the Mk2 PV Router. The integral voltage sensor is * fed from one of the secondary coils of the transformer. Current is measured * via Current Transformers at the CT1 and CT1 ports. * * CT1 is for 'grid' current, to be measured at the grid supply point. * CT2 is for the load current, so that diverted energy can be recorded * * A persistence-based 4-digit display is supported. This can be driven in two * different ways, one with an extra pair of logic chips, and one without. The * appropriate version of the sketch must be selected by including or commenting * out the "#define PIN_SAVING_HARDWARE" statement near the top of the code. * * September 2014: renamed as Mk2_bothDisplays_2, with these changes: * - cycleCount removed (was not actually used in this sketch, but could have overflowed); * - removal of unhelpful comments in the IO pin section; * - tidier initialisation of display logic in setup(); * - addition of REQUIRED_EXPORT_IN_WATTS logic (useful as a built-in PV simulation facility); * * December 2014: renamed as Mk2_bothDisplays_3, with these changes: * - persistence check added for zero-crossing detection (polarityConfirmed) * - lowestNoOfSampleSetsPerMainsCycle added, to check for any disturbances * * December 2014: renamed as Mk2_bothDisplays_3a, with some typographical errors fixed. * * January 2016: renamed as Mk2_bothDisplays_3b, with a minor change in the ISR to * remove a timing uncertainty. * * January 2016: updated to Mk2_bothDisplays_3c: * The variables to store the ADC results are now declared as "volatile" to remove * any possibility of incorrect operation due to optimisation by the compiler. * * February 2016: updated to Mk2_bothDisplays_4, with these changes: * - improvements to the start-up logic. The start of normal operation is now * synchronised with the start of a new mains cycle. * - reduce the amount of feedback in the Low Pass Filter for removing the DC content * from the Vsample stream. This resolves an anomaly which has been present since * the start of this project. Although the amount of feedback has previously been * excessive, this anomaly has had minimal effect on the system's overall behaviour. * - removal of the unhelpful "triggerNeedsToBeArmed" mechanism * - tidying of the "confirmPolarity" logic to make its behaviour more clear * - SWEETZONE_IN_JOULES changed to WORKING_RANGE_IN_JOULES * - change "triac" to "load" wherever appropriate * * January 2020: updated to Mk2_fasterControl_1 with these changes: * - Half way through each mains cycle, a prediction is made of the likely energy level at the * end of the cycle. That predicted value allows the triac to be switched at the +ve going * zero-crossing point rather than waiting for a further 10 ms. These changes allow for * faster switching of the load. * - The range of the energy bucket has been reduced to one tenth of its former value. This * allows the unit's operation to commence more rapidly whenever surplus power is available. * - controlMode is no longer selectable, the unit's operation being effectively hard-coded * as "Normal" rather than Anti-flicker. * - Port D3 now supports an indicator which shows when the level in the energy bucket * reaches either end of its range. While the unit is actively diverting surplus power, * it is vital that the level in the reduced capacity energy bucket remains within its * permitted range, hence the addition of this indicator. * * February 2020: updated to Mk2_fasterControl_1a with these changes: * - removal of some redundant code in the logic for determining the next load state. * * Robin Emley * www.Mk2PVrouter.co.uk */