Multiple readadc10 commands in a row

hax

New Member
Hi all,

For a crude energy monitor design, I'd like to capture half of a sine wave by using the readadc10 command, to measure AC voltage and AC current at 50 hz.

The voltage would be read with a single diode rectified transformer, with no capacitor, say a 20v transformer with a resistor divider to get 0 to 5v.

The current would be read with a LEM current sensor.


How quickly could the readadc10 command work?

I was thinking that I could store say hopefully 20 data points of the half sine wave. That would be one sample every 500uS. Is this realistic?

What picaxe has the fastest readadc10 ability?

The "data acquisition" could start at any random point of the sine wave. And after sampling say 40 data points, the software would choose the point at which the voltage is the highest (which would be the peak part of the sine wave), and the corresponding current value at that point in time could be used to calculate the watts. Is this asking too much of the picaxe?
 

oracacle

Senior Member
It should take too long, think every 500us would be an issue though.
You maybe better off doing some signal conditioning first, either a peak detector of envelope follower should work. You maybe be able to use them PICAXE comparators but I don't them well enough to advice
Also UK mains AC is 50hz so you are only going to get a peak every 20000us, that's 40 readings in every wave.
 

erco

Senior Member
My gut tells me that a Picaxe is too slow to sample that fast with ADC10. You could write a test program to loop through a few thousand consecutive ADC10s and time it by hand and djvide for a quick check. Sounds like a perfect opportunity ton use caps & inductors to find voltage & current peaks & zero crossings. Analog. Baby!
 
Last edited:

hippy

Technical Support
Staff member
How quickly could the readadc10 command work?
Testing on a 20X2 shows ten consecutive READADC10 take about 780us, so around 80us each at 64MHz.

What picaxe has the fastest readadc10 ability?
I would guess the 20X2 is the best choice as it allows 64MHz operation without an external crystal.

After sampling say 40 data points, the software would choose the point at which the voltage is the highest (which would be the peak part of the sine wave), and the corresponding current value at that point in time could be used to calculate the watts. Is this asking too much of the picaxe?
The PICAXE should easily be capable of this. You don't really need to sample, can run for a couple of mains cycles and determine what the highest reading was. This takes about 50ms to read 200 samples, a sample every 250us ...
Code:
#Picaxe 20X2

Symbol ADC_PIN = 9 ; C.1 / ADC9

Symbol sample  = w0
Symbol maximum = w1
Symbol counter = w2

#Define Highest(lhs, rhs) lhs Min rhs

SetFreq M64
Do
  maximum = 0
  counter = 200
  Do
    ReadAdc10 ADC_PIN, sample
    maximum = Highest(maximum, sample)
    counter = counter - 1
  Loop Until counter = 0
  ...
Loop
The beauty of this is it doesn't matter how long each sample loop takes so long as you run it for long enough to have read the maximum or thereabouts.

The only thing speed does is give you more responsiveness and a better chance of reading the peak or close to it with a shorter loop time.

So you could even use an 08M2.
 
  • Like
Reactions: hax

hippy

Technical Support
Staff member
The voltage would be read with a single diode rectified transformer, with no capacitor, say a 20v transformer with a resistor divider to get 0 to 5v.
I would recommend using a multi-turn pot or a multi-turn pot plus R divider. At least for the prototype and it will probably be useful for calibration in production if one were heading that way.

This way you can easily tweak the pot to suit whatever mathematical constants make the PICAXE maths easier when it comes to calculating the RMS or peak voltage, Watts etc -- It's much easier to divide by powers of two and tweak the input to suit that than have to figure out how to do complicated maths without losing accuracy or resolution.
 

Flenser

Senior Member
I just tested the cmd "READADC10 B.2, W1" on an 18M2 and it took 721 instructions at all clock frequencies from 250kHz - 32MHz:
4MHz: 721us
8MHz: 360.5us
16MHz: 180.25us
32MHz: 90.125us

On a 20X2 the "READADC10 B.2, W1" took 1210 instructions at all clock frequencies from 250kHz - 64MHz
4MHz: 1210us
8MHz: 605us
16MHz: 302.5us
32MHz: 151.25us
64MHz: 75.625us

You should not take these measurements as exact values. Because of the way PICAXE programs are compressed the measured duration of any command does vary by a few percent as code is added or removed from before its position in the program (and making my 20X2 measurement at 64MHz consistent with Hippy's).
This doesn't take into account the overhead for your program to save the 20 readings.
 
Last edited:

hippy

Technical Support
Staff member
I just tested the cmd "READADC10 B.2, W1" on an 18M2 and it took 721 instructions at all clock frequencies from 250kHz - 32MHz:
On a 20X2 the "READADC10 B.2, W1" took 1210 instructions at all clock frequencies from 250kHz - 64MHz

You should not take these measurements as exact values.
Thanks for testing and you are right to note it's not an exact science, particularly as alignment in memory can have an affect. and it's hard to have any control over that.

I was actually expecting the M2's to be slower than the X2 but I guess it comes down to exactly what configuration each does in preparing its hardware for a read. My 28X2 tests before trying a 20X2 were comparable.

I guess the bottom line is an M2 at 32MHz compares similarly with a 20X2 at 64MHz.
 

inglewoodpete

Senior Member
I was actually expecting the M2's to be slower than the X2 but I guess it comes down to exactly what configuration each does in preparing its hardware for a read. My 28X2 tests before trying a 20X2 were comparable.
The difference in speed is probably associated with the token size difference in M2s (5-bits) vs. X2s (6-bits).
 

AllyCat

Senior Member
Hi,

I think the OP's target is probably possible, but there are a number of potential "gotchas":

Firstly, I thought that the ADC used its own clock (divider), so its execution time didn't necessarily "track" directly with SETFREQ, but perhaps I'm mistaken?

Secondly, If you're storing a "list" of values, then you'd normally use @BPTRINC, but that can store only a Byte (8 bits), not a Word. Also, storing the two extra bits from a READADC10, into an additional byte might be considered rather inefficient.

Generally, the "overhead" associated in using a program loop is quite high, so really "fast"code normally employs linear code, e.g. READADC pin , w0 : READADC pin , w1 : ..... etc.. , (which will soon run out of Words, even in an X2), or better, @BPTRINC and then performs a "Post Processing" activity.

It depends upon the nature of the "sine wave", but mains "Power Meters" normally measure both Voltage and Current "dynamically", because they might not be in phase, unless it's a purely resistive load (i.e. a Unity Power Factor or Zero Phase Angle). So personally, I would probably "interleave" Voltage and Current measurements with a block of linear code. 8-bit (i.e. byte) measurements may be sufficient, because you could combine two (or more) consecutive measurements to interpolate a more accurate "peak" of a (or the) sine wave(s).

Finally, for the hardware, I would probably NOT use a series diode (or any capacitors), but a (10k) series resistor to the ADC input pin. Then a Reverse diode to ground (preferably Schottky) to prevent the pin being pulled too far negative. Possibly the on-chip "electrostatic protection diode" could perform that function, but there were reports that current flowing in this (substrate) diode can upset the accuracy of the ADC converter. See the ("obsolete") Enhanced Programming Interface in User Manual 1.

Cheers, Alan.
 

hippy

Technical Support
Staff member
It depends upon the nature of the "sine wave", but mains "Power Meters" normally measure both Voltage and Current "dynamically", because they might not be in phase, unless it's a purely resistive load (i.e. a Unity Power Factor or Zero Phase Angle). So personally, I would probably "interleave" Voltage and Current measurements with a block of linear code. 8-bit (i.e. byte) measurements may be sufficient, because you could combine two (or more) consecutive measurements to interpolate a more accurate "peak" of a (or the) sine wave(s).
Good point. My suggested solution was in respect of determining peak voltage as per the initial question.

As to what's appropriate to create a "crude energy monitor" that's beyond my knowledge and experience. Determining peaks of voltage and current over a few mains cycles then applying some fudge factor calculation may be enough, but it may need to be more involved than that.

If sampling then processing voltage and current, beyond having to read twice as much, one has to store that data and have a place to store it, any tricks used to maximise storage will impact on sample rate.

For the hardware, I would probably NOT use a series diode
I would use that because it guarantees the substrate won't be pulled negative, but I'm no expert on that.
 

AllyCat

Senior Member
Hi,
I would use that because it guarantees the substrate won't be pulled negative, ...
Yes, I must admit that I originally considered the "Enhanced Serial Download Circuit" (Manual 1 page 45) to be over-complex and would simply use a forward diode. But here, we are attempting to make an analogue measurement, and all diodes do have a significant (temperature-dependent) forward voltage drop, and some stray (parallel) capacitance:

Perhaps simply adding 600 mV to the (calculated) ADC value will be "good enough", but some caution may be required with the location (and values) of the resistors when combining a diode with a Potential Divider. The advantage of a negative "shunt" diode is that it doesn't influence any positive voltage that is being measured.

Cheers, Alan.
 

hax

New Member
Thankyou so much for your replies.

I think an 8 bit measurement should suffice. I'm aware that the system won't measure reactive power, but for my purposes that should be ok.

To explain a little more, I'm using this to measure the consumption in each of the 3 phases in my house, one of the phases has a solar system installed, amongst other regular loads, sometimes it is exporting to grid, other times it's not. So I need to sum all 3 phases to find out if I'm net exporting.

This info can then be used to switch the hot water heater on if there is enough sunlight.

Sounds like 3x 08M2 chips could be used. One for each phase, with a pwm output on each, reporting an 8 bit power measurement, with another pin signalling whether the phase is exporting or importing power from the grid. Or one 20x2 that does the lot.
 

tmfkam

Senior Member
Hi all,

For a crude energy monitor design, I'd like to capture half of a sine wave by using the readadc10 command, to measure AC voltage and AC current at 50 hz.

The voltage would be read with a single diode rectified transformer, with no capacitor, say a 20v transformer with a resistor divider to get 0 to 5v.
I used a very similar approach in my Grid Frequency Meter project, listed somewhere on this forum. I alternately read Voltage and frequency. For a close approximation it worked really well.
 

hax

New Member
That AD7755 looks interesting. Plenty available on eBay still. It was interesting to read that it has a frequency output plus a pin that goes high for out of phase current (exporting solar). That's basically what I was "inventing" with the 08m2 idea. Well it's time to heat up the soldering iron and test some code.

Hippy, I'll have to look at your code example more closely. I can't follow it just yet.

One other thought is that I might not need to measure the analog value of the voltage. I can just assume it's somewhere around 240v. All I need to know is whether the phase angle between the voltage and the current is more than 90 degrees. So I could set up the AC voltage input as just a digital input. This would save some processing time. I'd just look for the current peak value from the LEM current sensor.

Thanks again for your replies.
 

AllyCat

Senior Member
Hi,

Yes, for Export/Import detection you need only the sign of the Current and Voltage signals, which could be done with two digital inputs (e.g. a zero-crossing trigger and a polarity detector).

The timing of Zero-crossing is potentially much more accurate than of a "peak" voltage/current signal, but is not directly measurable with "sampled" signals. However, even a full analogue power measurement including Power Factor (phase) correction shouldn't be too difficult if you assume a sinusoidal line frequency (i.e. pure 50 / 60 Hz). That's a reasonable assumption for an Immersion Heater and Motor-based systems, etc., but probably not electronics based on (bridge) rectification circuitry, etc.. A pair of (matched) R+C Low-Pass filters could be used to "de-spike" the waveforms, if necessary (without upsetting the relative phase shifts).

For a pure sine-wave, 3 samples per cycle is "sufficient", but 12 samples (i.e. every 30 degrees) make the calculations much easier (and still with greater than a 1ms sampling period). Then, the peak sample value (voltage or current) will be within 2% of the true peak (strictly +0/-4%) and there always should be a sample between zero-crossing and the half-peak (i.e. 50%) value. Thus you could calculate the times of crossing the 50% levels (which are nominally 120 degrees apart) by interpolating between the values immediately above and below this threshold. Sine and Cosine are easily calculated by (any) PICaxe by using a lookup table method.

Then, the main design choice becomes how to achieve mains isolation: Capacitor-Coupling, Magnetic (e.g. Transformer of Hall Effect) or Optical (e.g. Opto-Isolator or LED+LDR), etc..

Cheers, Alan.
 
Last edited:

papaof2

Senior Member
"Pure sine wave" might not apply to your local power provider :-( The waveform from the pure sine wave inverter on my solar backup system is much cleaner than the power provided by the local power co-op - and I have the 'scope pictures to confirm that.
Would the difference affect the sampling? Possibly only if the sampling hit at a "bad" point on every cycle? Co-op power first, then the PSW inverter with a 440 watt load. Sorry for the image quality but this old body no longer does well with long handheld exposures.

co-op-AC-sm.jpg

psw-inv-440W.jpg
 

hax

New Member
OK I have ordered a few AD7755 chips and will be going with a circuit similar to Jeremy Harris' one. It's just so precise compared to trying to roll my own. I love the idea of keeping every single joule that I produce, and not exporting any more than I have to.

I have 3 phases to monitor, so the circuit and code will be a bit different to Jeremy's. I will have 3 channels of pulses to count (up to 1.5KHZ in my case, which corresponds to a 15KW load per phase), but when exporting solar (which is only on one of the phases), the catch is that one of those pulse trains will have to subtract from the other two (at up to 10kw or 1KHZ). Fortunately, the AD7755 has a pin that goes high when the voltage and current is out of phase (exporting) which can be used to signal the picaxe to start subtracting.

I wonder if anyone can get me started on the code, as I don't think the count command will work here. Are there any tricks to do this elegantly? I guess an interrupt should occur as soon as any counter is sensed. But I'm not sure if it will be fast enough. I'll go with the 20X2 for sure.
 

hippy

Technical Support
Staff member
I don't think the count command will work here. Are there any tricks to do this elegantly?
By measuring the high or low period of the pulse, or both, one can calculate what the frequency is.

f = count / time

f = 1 / (Thigh + Tlow)
 

hax

New Member
By measuring the high or low period of the pulse, or both, one can calculate what the frequency is.

f = count / time

f = 1 / (Thigh + Tlow)

Thanks Hippy, That will be enough for an approximation to get something going, and will be better than my original rough idea in the first post.

The holy grail would be for the picaxe to monitor all 3 pins for edge transitions, sum or subtract as required, till 3600 pulses are recorded, then turn on the triac, then wait till 3600 pulses are depleted, then turn off triac, repeat.

If the picaxe can't do it, a solution could be to run each pulse channel through a dual BCD counter, then poll the counters as fast as possible. Hmm I've got a month or so to ponder this.
 

hippy

Technical Support
Staff member
The holy grail would be for the picaxe to monitor all 3 pins for edge transitions, sum or subtract as required, till 3600 pulses are recorded, then turn on the triac, then wait till 3600 pulses are depleted, then turn off triac, repeat.

If the picaxe can't do it, a solution could be to run each pulse channel through a dual BCD counter, then poll the counters as fast as possible. Hmm I've got a month or so to ponder this.
I am not sure which pulses you would be counting, in what time frame, why 3600, or what triac you are controlling. It may help to detail the exact theory of operation of what you are wanting to do.

Some PICAXE have internal hardware timers which can be used as 16-bit counters so there should be no need to add external counters to detect how many pulses there have been.
 

hax

New Member
Ok I'll try to explain more clearly. The aim is to use every joule of my excess solar production by storing the energy in a large hot water heater, while at the same time not exporting any power. This maximises the financial gain, as the tariff for importing is much higher than exporting power.

The problem comes when much of the time the solar system might be only producing say 2kw. If the 3.6kw element was turned on, the balance of 1.6kw would be purchased from the grid. We don't want to purchase any power from the grid so we have to dynamically change the load from 0 to 3600 watts depending on what excess solar is available.

That sounds complicated! How do we change a fixed 3.6kw resistive heater element?

Well there are a few ways:

1. Have multiple elements in the tank and only energise the ones that will more-or-less equal the excess instantaneous solar produced. (Very complicated solution that involves quite a bit of hardware modification to the heater)

2. Have some sort of 3.6kw controllable sinewave inverter drive the unmodified element. (Still a very complicated solution that requires a lot of power electronics)

3. Turn the unmodified heater element on/off as required so that the average power use is equal to the excess solar production.

Now you might assume that option 3 above won't work because the power meter doesn't average the on/off times. It will just charge you for the consumption while the element is on, and will only pay you a low rate while exporting when the element is off. Well it turns out that's not exactly the case.... The power meter WILL average the import/export energy as long as it is less than 3600 joules.


Forum member Jeremy Harris explains it well
Here and there is more info with graphs Here
It's exploiting the fact that most domestic energy meters have a "bucket" to fill of 3600 joules before they increment the counter forwards or backwards. The "bucket" can be filled or drained during this time, for as long as you like, and the counter does not increment in any direction.

So in theory you can fill the grid with 3599 joules of solar, then turn on the element, deplete the grid of 3599 joules, turn off the element and keep repeating this as long as you like!!!! As long as you don't go over 3600 joules, the power meter won't increment.

I want to do exactly what Jeremy did but with 3 phases. Each of the 3 X AD7755 power monitor chips will have two pins connected to the picaxe. One of which goes high every time 10 joules are measured, and the other pin will indicate whether the energy is imported or exported from the grid.

The picaxe has to add all energy pulses imported, and subtract all energy pulses exported.

As soon as 359 pulses are counted (3590 joules or less) it needs to turn on the solid state relay (triac). The pulses will now be draining the "bucket" so when the bucket gets to close to zero, the picaxe must turn off the triac. The process repeats.

Does that make sense?

Basically we need the picaxe to be a pulse counter for 3 inputs, with the ability to increment and decrement the counters by way of 3 more logic pins. The maximum frequency of each counter is 1.5khz.
 

hippy

Technical Support
Staff member
Does that make sense?
Yes, that makes more sense - it's simply tracking the accumulator you can't get at so you can figure out if it's going to start charging you do you can stop using their leccy before it does.

Basically we need the picaxe to be a pulse counter for 3 inputs, with the ability to increment and decrement the counters by way of 3 more logic pins. The maximum frequency of each counter is 1.5khz.
It seems you would need to handle 3 signals, each rising edge indicating 10 Joules had passed through the system and 1 to 3 inputs which indicates whether each should be added or subtracted from your PICAXE equivalent of the meter's accumulator.

To handle the worse case scenario accurately you would need to do this all within about 60ms.

I guess the question is, can a PICAXE handle an optimised version of below in 66ms ... ?
Code:
Symbol now                  = b2
Symbol now.phase1.pulse     = bit16 ; b2.bit0
Symbol now.phase2.pulse     = bit17 ; b2.bit1
Symbol now.phase3.pulse     = bit18 ; b2.bit2
Symbol now.phase1.direction = bit19 ; b2.bit3
Symbol now.phase2.direction = bit20 ; b2.bit4
Symbol now.phase3.direction = bit21 ; b2.bit5

Symbol was                  = b3
Symbol was.phase1.pulse     = bit24 ; b3.bit0
Symbol was.phase2.pulse     = bit25 ; b3.bit1
Symbol was.phase3.pulse     = bit26 ; b3.bit2
Symbol was.phase1.direction = bit27 ; b3.bit3
Symbol was.phase2.direction = bit28 ; b3.bit4
Symbol was.phase3.direction = bit29 ; b3.bit5

Symbol acc                  = w4 ; b5:b4

Init:
  acc = 0
  now = Pins

MainLoop:
  Do
    was = now
    Do
      now = Pins
    Loop Until now <> was
    If now.phase1.pulse <> was.phase1.pulse And now.phase1.pulse = 1 Then
      ; Phase has passed 10 joules
      If now.direction = 1 Then
        acc = acc + 10 Max 3600 ; Exporting
      Else
        acc = acc Min 10 - 10   ; Importing
      End If
    End If
    ... Repeat for Phase 2
    ... Repeat for Phase 3
    ... Handle turning load on or off
  Loop
 

PhilHornby

Senior Member
I was wondering (not knowing a great deal about three phase and its metering) ...

If you could arrange for the Solar PV Inverter and the Immersion Heater to be on the same phase, couldn't you just go with the circuit as specified by Jeremy? [just monitoring a single phase]

A supplemental thought - does a three phase meter even do the "Energy Bucket" thing that he and Robin Emley came up with? - it would itself, have to track usage across all phases, in a similar manner to that which you are proposing. I suspect the answer to that question could even be different for different models of meter...
EDIT
This (rather old) web page seems to indicate that three phase meters do implement a 'shared Energy Bucket'.
 
Last edited:

hax

New Member
Thanks very much Hippy for the code. I will give it a go.

PHIL: it seems that 3 phase meters are no different. They just aggregate their measurements to a single counter, and a single bucket just like the picaxe will.

There are reports that some meters use smaller buckets of around half the 3600 joules, but that's no problem, it just means a tweak of the code and shorter on/off times. A common 3600 watt element happens to have a nice neat 1 second on period to use up 3600 joules, and that on time will always be longer when the sun is shining. So we are not pulsing very quickly at all.



It just so happens that I do have a single phase HWS and a single phase solar inverter, so I could put them on the one phase, but I also have an outdoor spa and pool, each single phase on a 30A circuit and each has another 3kw heater, as well as an induction cooktop and air conditioning. (No gas here) So the beauty of this 3 phase approach is that it's monitoring the whole house for consumption and dumping only the excess solar.

I just can't get past the simplicity of this approach.
 

PhilHornby

Senior Member
OK I have ordered a few AD7755 chips and will be going with a circuit similar to Jeremy Harris' one.
I don't know how you are getting on, but @Jeremy's hardware documentation was a little sparse, so I've been having a few issues trying to build a practical board.

I found some documentation relating to a now obsolete AD7755 Evaluation Board, which answered some of them. It's a shame I can't find the actual board anywhere...

I'll ask the remaining questions in the original thread.
 

AllyCat

Senior Member
Hi,

I'm planning a similar project and will contribute to Jeremy's original thread in due course, if he doesn't put in an appearance there. My project isn't particularly "time-critical", so currently I'm awaiting an AD7755 to come in from China. Overall, I haven't identified any "better" Energy Monitoring Chip than that, noting that the SOP24 (1.25 mm pad pitch) and SSOP24 (0.65 mm pad pitch) packages typically cover more "PCB Real Estate" than the AD7755 DIP24. That's because the vast majority of {S}SOP24 "breakout" boards have a 0.6 inch row pitch, compared with the 0.3 inches of AD's DIP.

However, I've been looking at PIC(axe)'s capabilities and think that the OP (hax) would probably need to use a "Three Phase" Monitoring chip, for example the ADE7758 (although I've not examined its data sheet in detail). A problem is that PIC(axe) chips (at least the M2s) don't have a "silicon" hardware Up/Down Counter, and only very limited Up-Counting capabilities; thus interrupts appear to be the only method to count the Energy pulses. In M2s, only "Timer0" and "Timer1" have an External Clock option, but T1 is used extensively by the PICaxe Basic interpreter timing and T0 is principally only an 8 bit counter (plus pre/post scalers).

Jeremy's estimate of an Interrupt Service Time of just under 1 ms seems correct (at 32 MHz), but the "CF" pulse from the 7755 is only 80 us wide. That's probably sufficient if the PICaxe program is continuously executing (i.e. polling) just a "Waiting For Interrupt" Loop (or a PAUSE), but not for a more complex architecture. The "Interrupt On Change Flags" are available, but I don't believe that they could be sufficient to maintain accurate interrupt-counting from three separate sources (i.e. Three-phase mains).

Like Jeremy's described concept (unfortunately not documented), I hope to include a Radio Link from the Energy Monitor, however not just for "data" distribution/monitoring, but also ideally to directly control the Load Power. That's partly because our immersion heater is not on a "dedicated spur" from the meter/consumer unit board, but also because other "heating" devices (such as a kettle) might benefit from some PV-related control. IMHO, apart from Bathing/Showering, Hot(ish) Water from the tank is not necessarily particularly useful, for example most Washing Machines (now) use only Cold Fill.

Perhaps I should consider a WiFi-based link, but feel more comfortable with the sub-GHz ISM bands; preferably 868 MHz now. However, I haven't identified any simple "4-terminal" (i.e. Data, Supply, Ground and Antenna) modules for 868 MHz, so have been looking at CC1101 or RFM69 Transceiver modules. Those can handle the framing, modulation and CRC, etc. automatically in the "background", but the custom configuration (initialisation) via their 4-wire SPI Bus, might make this rather a "Big" development task with a PICaxe. Any other thoughts?

Cheers, Alan.
 

PhilHornby

Senior Member
Like Jeremy's described concept (unfortunately not documented), I hope to include a Radio Link from the Energy Monitor, however not just for "data" distribution/monitoring, but also ideally to directly control the Load Power. That's partly because our immersion heater is not on a "dedicated spur" from the meter/consumer unit board, but also because other "heating" devices (such as a kettle) might benefit from some PV-related control.
IMHO, apart from Bathing/Showering, Hot(ish) Water from the tank is not necessarily particularly useful, for example most Washing Machines (now) use only Cold Fill.
I had been thinking along the same lines - and for the same reasons (Oil boiler connected to Immersion Heater circuit), but in the end, I bit-the-bullet and managed to rewire the Boiler onto a lighting circuit. No one need ever find out...

While hot water heating is not going to necessarily utilise all the available PV power, it will still do something useful. (I now have enough to data to know that we use about 35 litres of heating oil per month, just heating water. That's about £35 at current rates - so 'better than a poke in the eye' :)
Perhaps I should consider a WiFi-based link, but feel more comfortable with the sub-GHz ISM bands; preferably 868 MHz now. ...
Any other thoughts?
Up to now, my favourite has been the HC-12, but they're increasingly difficult to find - especially the real ones. An alternative I've been meaning to investigate, is ESP-NOW. This uses an ESP8266 module, but running an alternative protocol to WiFi. This protocol gets rid of the lengthy WiFi negotiation, meaning the ESP can 'sleep' to save power (just like an HC-12). It's a Peer-to-peer system, but AIUI, there can be multiple peers.

I'm not convinced that any Radio-based comms. would be timely enough to implement the 'energy-bucket' idea though - unless it used a very simple protocol (susceptible to errors). I wondered about a mains-carrier type signalling system; since I'm not capable of directly implementing such a system, I idly toyed with the idea of manipulating the ethernet signals on a Powerline adapter...

You might need some sort of sharing/budgeting scheme for each potential device, which in turn, would mean interrogating the PV Inverter for its Power output. (I have working hardware & software for the Growatt inverter, which does that, if anyone requires it).
 

AllyCat

Senior Member
Hi,

Yes, "Fakes" appear to have been a particular issue with the HC12s, but also I believe they are only/mainly 433 MHz. IMHO the 433 MHz (ISM) and 2.4GHz (WiFi / Bluetooth) bands are getting rather "congested", hence my preference for 868 MHz. As for the communication latency/delays, I wouldn't expect to transmit continuous "Switch ON/OFF" commands, but some sort of average "target" power level and leave the Immersion Heater/Receiver electronics module to determine the exact "firing" points. Personally, I've always "hated" the concept of mains-borne signalling and a brief test in my previous house created horrible interference with Broadcast Radio and failed to communicate reliably. Our PV system has a modest "Sofar" Hybrid Inverter, "Pylontech" battery and "Solarman" monitoring software, which IMHO don't exactly score "5 stars" for their UI capability. :(

We often recommend on this forum that one shouldn't attempt to "Reinvent the Wheel", so I've been looking at what is currently available (having been shocked by the description of the products that caused Jeremy to "Roll his Own"). Wireless linking seems quite common now, to avoid the costs and inconvenience of running "data" cables between the Meter (Consumer Unit), Immersion Heater and EV Charger, etc.. For example, the products from myenergi : "Zappi" (EV Charger), "Eddi" (Heating Controller) and "Harvi" (Radio-Linked Current-Transformer). The latter is particularly interesting because it claims to "harvest" its power supply from the Current Transformer (at the Consumer Unit), so needs negligible "installation". The "major" products are quite expensive (perhaps due to a high specification) however "Harvi" seems not unreasonable at about 55 UKP (but perhaps we can do better with a PICaxe ;) ).

The Specification gives some "clues", although I hadn't found* free access to their patent (GB2562550). In particular, all the above products employ 868 MHz communications (915 for USA), with a separate "Smart Hub" (shouldn't it be Hubbi :) ) to interface with WiFi/Internet/Phones/App., etc.. Initially, I couldn't see how it could "harvest" its power from the Current Transformer, particularly as the aim of the system is to minimise the current in the Import/Export (Meter) cable. I wondered if clipping onto the (insulation of the) Live Meter Tail could give some capacitive coupled supply current (relative to any available Earth contact). However, that seems several orders of magnitude too small, but might be sufficient to give a voltage waveform for estimating the Power Factor (i.e. I/V phase angle).

A clue is that the "current harvesting" requires at least 1 Amp to flow, but it can work down to 0.2 Amp by reducing the period between transmissions to 30 seconds (i.e. lowering the average power supply drain). Also, the specification item: "Energy Harvesting Range: 0.2A to 65A (including reactive current)" suggests that a capacitor "wired across the mains" might give that minimum current without consuming any "real" power ;) . However, I'd still be interested to see their circuit diagram, because the Current transformer would normally be expected to deliver only a fraction of a volt a.c. peak-peak. Perhaps Energy Harvesting is "a step too far" for my/a PICaxe project, but a 2 x AA battery (Alkaline, NiMH or Lithium) supply could be acceptable, taking advantage of PICaxe's low power drain capabilities.

*EDIT: It appears that the Patent is available from the .GOV IPO website ; remarkably concise and readable for a patent application (voice of experience). :)

Cheers, Alan.
 

Attachments

Last edited:

PhilHornby

Senior Member
*EDIT: It appears that the Patent is available from the .GOV IPO website ; remarkably concise and readable for a patent application (voice of experience). :)
https://www.ipo.gov.uk/p-ipsum/Document/ApplicationNumber/GB1718943.2/fc4fa766-0537-43a3-b984-68109980573e/GB2562550-20181121-Publication document.pdf

So have I understood it correctly - it uses the Current Transformer (without the 'burden resistor') to charge up a local power supply, then switches the burden back in circuit and uses that supply to take 'several' readings of the voltage across the burden - almost what @hax was proposing at the start of the thread :unsure:

Could you just use an additional Current Transformer (with the burden removed) to power the circuit❓
 

AllyCat

Senior Member
Hi,

Yes, having examined the Patent in some detail, it appears that this thread has gone almost full-circle. After "harvesting" a voltage for the supply rail, the patent describes taking (typically) "64 ADC samples" of the input current over one 50 Hz cycle, but using an a.c. (coil) current transformer in preference to a "LEM" (Hall effect ?) sensor (post #1). Indeed, I also considered using a second clip-on transformer, because low-resistance switching of the burden resistor(s) might not be easy, and a separate "harvesting" coil could be attached where there is a higher (non-reversible) load current (e.g. the input to the fuse box). I believe the "current-current" CT (SCT013-000 = 1 : 2000 turns) version wouldn't even need a/the burden resistor to be removed, but unfortunately I didn't order that type. I don't know the efficiency of such a "single turn (primary)" transformer, but clearly at 1.0 Amp, the secondary current cannot be more than 0.5 mA, hence the need to limit the number of samples and RF transmissions.

Then, the "post-processing" is far more sophisticated and quite ingenious; the ADC resolution is not specified, but is obviously a "signed" value (i.e. over a full a.c. cycle). In practice, 8 bit values may well be sufficient, due to the principle of "oversampling" (combining multiple measurements) to give a higher resolution result). Here, the patent describes performing a Fast Fourier Transform (FFT) on the sampled data, which is well beyond the capability of PICaxe Basic. The purpose is to "fit" the data points to a 50 Hz sine-wave in Amplitude and Phase (which might be possible by a PICaxe using a different method?) that, similar to a scatter diagram, can give a higher accuracy result than of the individual data points. It's notable here that a sine-wave current is assumed, which surprises me because I would expect electronic devices employing Bridge Rectification (e.g. to generate a dc supply rail) and Thyristor/SCR phase-controlled motors and Light dimmers, etc. to distort the current waveform significantly.

A feature of the Patent is that the "remote current monitor" (Harvi) does NOT measure the Voltage (amplitude or phase), so it cannot "know" the Power level. It is the receiver (e.g. Zappi/Eddi) which is connected to the mains supply that measures the Voltage/Phase and calculates the Power, in association with the (amplitude/phase/time) data received from the Current Sensor (Harvi). Here, the assumption of a voltage sine wave probably is reasonable; I suspect that the waveform distortion shown by Papaof2 in #17 is not directly very significant, but it may be indicative of a large non-sinusoidal load current "pulse" (near to the peak voltage) causing a voltage drop across the source/distribution resistance. Thus, this measurement system is probably not as accurate as the AD7755 and similar dedicated chips, but is potentially much more "User-Friendly". For me, a particular "disadvantage" of the AD7755 (and similar) is not that it's "obsolete" (or available only in a SMD package) but that it's an additional component which needs a regulated 5 volt supply rail at a significant current.
_______

An architecture with the "Main Controller" located close to the Tank/Immersion Heater and a "remote" current sensor (wired or wireless) seems common now and the "distributed processing" of the Eddi/Harvi is ingenious. Unproven, but personally I would propose to detect the Voltage Phase (not necessarily Amplitude, which should be relatively constant) by a small stray capacitance (a few pF) at or near the CT clip. The ~700 V pk-pk would be reduced by capacitive division to a few volts (across say 1 nF) with the (approximate) "zero-crossings" detected by a digital or comparator input. Thus the nominal voltage peak can be found equidistant between the crossing edges, to be used to calculate the "real" (phase-corrected) power, perhaps taking into account some distortion in the current-waveform.

Finally, the various manufacturers seem rather secretive about the method that they use to apply variable power control to the Heating Element. "Eddi" claims a "Pure Sine Wave PWM (Pulse Width Modulation)" control (the ideal if true), but another manufacturer's FAQ says: "Is the Solar +++ a “proportional controller” or a switch? Answer: Solar +++ uses electronic control technology to cleverly allow only the same as the excess power generated to be diverted to the immersion. ...... It is not an open and close switch."
However, I suspect that the following product uses the type of SCR control disliked by Jeremy (and me), but to be fair this Test Report is posted on the manufacturer's website:
"Solar Immersion Heater Controller Model AF2.1 ..... EMC Compliance tests. Examiner’s comments:
The DUT operates with an unconventional PWM. The switching point to proportionally vary the power to the load changes continuously from one half cycle to the next, based on a spread-spectrum rotating vector load pattern. This unusual configuration increases higher order harmonics by spreading the instantaneous impulse noise across the spectrum. The test standard specifies a 200ms minimum, 10 cycle averaged result, which this design takes advantage of. The instantaneous result is above the harmonic limit, but the average is below, giving a pass."


Cheers, Alan.
 

lbenson

Senior Member
I'm not sure whether this is too off-topic or not, or too non-picaxe, but what I use for power monitoring (and switching if desired) is a Sonoff PowR2 with Tasmota firmware, which gives me views like these on my phone:
25467 25468
In addition to these canned views, there's a scripting language which I haven't used yet.
 

AllyCat

Senior Member
Hi,

Yes, I also considered posting about the similar "Smart Plugs" which I have been testing, but the details could fill several dedicated threads. So I'll start with a link to a rather surprising forum, specifically from post #43 by "Kim", which is both entertaining and informative. It covers some of the aspects why these devices perhaps need a "Health Warning." ;)

For the uninitiated, Tasmota is not an "App" (BTW which App do you use?) but firmware that normally needs to be "flashed" into the Smart Device itself, although a few "pre-flashed" devices are available. To be honest, references to "GitHub" and a "Spudger" fill me with dread. :( But to be fair, the Sonoff devices do appear to be primarily targeted at "lighting" and not to be totally sealed up by glue. They do need to be wired into a mains circuit (which is not really encouraged on this forum), whist the advantage (and disadvantage) of the Smart Plugs is that they can be simply pushed into any 13 Amp or 16 Amp mains socket to "Plug and Play". However, if you delve deeply into their specification, you may find that the Maximum Load is "Resistive Only" and the limit for "Reactive Loads" (motors, etc.) might be as low as 2 Amps.

The relevance to this thread is that (our) standard Immersion Heaters consume 3 kW or almost 13 Amps and these switches appear to be variously rated at 10A, 13A (UK) or 16A (Europe). The switch I used carries a "well known" brand name, marked 13A, but has just been returned to "South American River Company" because it failed after 3 months (permanent voltage output regardless of switch status). I will add that its relay would rarely (if ever) have needed to break the full current, because that is normally performed by the Immersion Heater's Thermostat. Also, 10% of the Amazon.co.uk reviews for the Sonoff rate only 1*, mainly because of failures, with a significant proportion reporting "caught fire". Incidentally, it's also worth noting that a Thyristor (or SCR) effectively contains two "diode forward drops" (PNPN junctions = ~1.5 volts), so a "Solid State Relay" may dissipate around 18 watts at 3kW output (13A), therefore very likely they will need a Heat Sink in some form.

To summarise a few reasons why a "Health Warning" might be relevant :
- The "App" will very probably need to be "registered" (with ridiculous T&Cs) and be dependent on a Server Centre somewhere in China.
- The manufacturer / seller might "pull the plug" (metaphorically) on the App or Server Centre at any time.
- Tasmota potentially avoids these issues, but some manufacturers are modifying existing products so that they cannot be flashed.
- Some of the cheaper versions do NOT have Energy Monitoring (including the Sonoff "Basic" version).
- Purchasing and setting up the remote switching for 3kW mains loads needs some caution !

Cheers, Alan.
 

lbenson

Senior Member
I don't use any App--just my browser on any device accessing the web page which Tasmota presents (or Annex). I also have a horror of anything cloud-related. And for the most part, I don't actually switch them--just use them to monitor when the already-present controls on the boiler and water pump cause current to be drawn.

I do switch one which controls an electric heater in my barn--1500 watts, 120V.

18 months and counting, and I have no complaints.
 

PhilHornby

Senior Member
I've just remembered what you said ...

Jeremy's estimate of an Interrupt Service Time of just under 1 ms seems correct (at 32 MHz), but the "CF" pulse from the 7755 is only 80 us wide. That's probably sufficient if the PICaxe program is continuously executing (i.e. polling) just a "Waiting For Interrupt" Loop (or a PAUSE), but not for a more complex architecture. The "Interrupt On Change Flags" are available, but I don't believe that they could be sufficient to maintain accurate interrupt-counting from three separate sources (i.e. Three-phase mains).
I've just powered up my AD7755 for the first time, with a load attached - no Picaxe yet, just the 'scope.

I was somewhat perplexed to see that the CF signal is only 18uS wide (not 80). Checking the datasheet and Jeremy's code, this is indeed correct for 'high frequency mode'. Can an 08M2 using interrupts at 32MHz, really handle that reliably?

I suppose the question applies specifically, to these few instructions:-

Rich (BB code):
main:

    pause 1000                                            ;loop around aimlessly waiting for an interrupt
    goto main
I'm about to do some tests to find out ...
 

AllyCat

Senior Member
Hi,

PICaxe documentation indicates that (M2) interrupts are polled between each Program Instruction (typically > 50us @ 32 MHz) which is why I mis-remembered the value. But an interrupt can also be serviced during a PAUSE, so presumably (if Jeremy's code works properly) the interrupt Port is polled quite frequently during this command (I thought it might have been at the PAUSE parameter/increment period, i.e. 125 us @ 32 MHz, but presumably not). A test could be to use the PAUSEUS command which has such a tight loop (10 "base PIC" Op-Codes) that it presumably cannot poll the Port.

A direct solution is to replace the main: / PAUSE loop with a Basic Polling Loop, for example of the appropriate Interrupt-On-Change Flag(s). The Subroutine Jump (and Particularly RETURN) are so slow in PICaxe Basic, that a few POKE/PEEKSFR commands are probably faster (bearing in mind that the "interrupted" PAUSE immediately falls into the GOTO main anyway). Alternatively, the non- "high frequency" modes generate a 50:50 duty cycle, but I think they are at a so much lower frequency that they don't meet the needs of the "Energy Bucket" system.

The reason that I discounted this for the "three phase" design is because, although one could grab the status of 3 IOC flags and increment the "count" by 1, 2 or 3, I couldn't see how to also grab the 3 "direction" (Import/Export) flags. These could be decoded in a 6-bit lookup table (READ one of 64 bytes) to give -3 to +3), but how to set and clear all these flags at the appropriate times ?


Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
I was somewhat perplexed to see that the CF signal is only 18uS wide (not 80). Checking the datasheet and Jeremy's code, this is indeed correct for 'high frequency mode'. Can an 08M2 using interrupts at 32MHz, really handle that reliably?
As long as the PICAXE firmware is checking the input pin more frequently than every 18us then yes. If there is ever a period of execution longer than that during which the input isn't checked then it could be missed. I honestly don't have a definitive answer to that.

It should be possible to stretch that pulse to a longer period using an R-C or monostable, and there are a number of software tricks using on-chip hardware where one can make that a latching or recorded event.
 

AllyCat

Senior Member
Hi,
Figure 1 in that Application Note does seem rather "Strange":

- The line marked "NEUTRAL" is capacitor-coupled to the 7805 regulator input and connects via the Load to V1P (i.e. the Positive Input).
- The line marked "220v PHASE" connects to the Star Point, V1N and the Earth/0v of the 7805 (so can't use the full differential input swing).

Of course it should work, but why is a "Demonstration/Reference Design" all hanging on the Live Mains (including the Counter/Stepper Motor)? :confused:

Cheers, Alan.
 

hippy

Technical Support
Staff member
Of course it should work, but why is a "Demonstration/Reference Design" all hanging on the Live Mains
It is hard to say and the datasheet doesn't explain it. The transformerless PSU designs I have seen have been 'neutral chassis' rather than 'live chassis' as here.

As you say; it should work, so perhaps it doesn't matter, maybe even has some advantage, though I wouldn't know what.
 
Top