Homebrew IoTaWatt

I’m happy to troubleshoot software issues that I can replicate on the hardware. If they turn out to be hardware issues, at least the device is on my bench, with my instruments ( voltmeter, oscilloscope, etc) and I can take a methodical approach.

Here you are presenting a new problem but you have not resolved the problem of a few days ago where the voltages were randomly dropping. My approach is to assume things like this are related. For example:

In the last round of trying to insulate the software from VTs that were not running, I put in check before sampling the VT. The software looks for two readings from the VT that are 20 counts different with a timeout of 2 milliseconds. That’s not a big difference, and noise could easily satisfy this test.

Now you have this other problem that is intermittent low readings on your VTs that has not been reconciled, but it appears to be a bad connection someplace.

There are tools built into iotawatt to look at the quality of the signals. They are not yet available through the app, but you can get to them with a URL command in a browser. One such tool returns all of the samples on a channel for one cycle. That’s what I used to get to clean signals in my board design.

The op-amp can oscillate. You have substituted different capacitors, have a different board layout, and probably use different tolerance components. 20 ADC counts isnt very much noise. The oscillations are typically at a harmonic frequency of the AC line. You have three phase with several frequencies. If your circuit breeds oscillation, the combinations are endless.

All that said, you might try to find the zero detection code I mentioned (it’s in two places) and increase the number of counts (from 20 to say 200) and see anything changes. Look at the samples for a CT with nothing connected. If the opamp is oscillating, you will see there.

I’m not an electrical engineer. I’ve learned all this through a lot of experimentation over the last year. When you say nothing is different or it’s the same except, you ignore the fact that it is different by virtue of the fact that it is working differently. The differences are enormous.

Found the problem with VT1 taking out everything :slight_smile: … and it’s quite stupid… :face_with_raised_eyebrow:
I was powering the IoTaWatt from my pc, to be able to see the serial terminal.
When powering it from a mains adapter (2A) the problem is gone… unplugging and replugging the VT now gives the same behaviour as yours (falling to 0, coming back and a minor influence on the other one).

Maybe that an extra cap on the 3.3v and 5v line could solve this?

I will monitor the other problem (the missed VT cycles) when powering it from the mains adapter, maybe it’s also power related.

When the rest of the components for the second Iota arrive i’ll give it a try to share a VT between 2 boards. The layout is identical, so gnd should be gnd, but i’ll double check to be sure.

Get a powered USB hub. I have a couple of these from Amazon: Amazon Powered USB hub

Very clean power.

The Iota has been running for 2 hours now and i cannot see anymore spike differences between VT0 and VT1. They must have been power related also.

Nevertheless the problem was not at all in your design or software it has taught me a lot about the firmware. I can’t say that i understand everything (maybe not even half) but it"s very intriguing how it’s put together! Everytime i look at it i’m finding something new and always think 'man thats clever and well done" :wink:
I’ll keep digging :wink:

I should get a usb hub , i know :wink: i moved the one from my pc to the garage to power everything over there a couple of months ago but didn’t replace it.

That’s good. Much as I might like new members to my fan club, I think you have potential to join the team and contribute.

@overeasy : i i would use a shared VT between 2 boards. Would it be a problem if one of them used “BIAS” and the other one “ACBIAS”? Or would it be better to both use BIAS? (changing the pcb to introduce ACBIAS on a blank pcb is doable, but more difficult on an already soldered one)

Moving conversation from IoTaWatt 4.0 Thread to here : IotaWatt 4.0 - #97 by overeasy

I plan to give it a try and see how it goes when all the parts arrive.

The basic idea is using an op-amp to do a differential to single ended conversion. I am also a bit skeptical as I still don’t fully understand how it overcomes the problem you described, as there is still a point where we attach a kind of bias to the AC in the positive input of the op-amp, but apparently with the high impedance between the circuits and the filtering basically offered by the power circuit it eliminates problems. I am sourcing parts now and drawing it up properly.

If it works out, I will certainly post it up. Actually I might post it up once I have completed drawing anyway and see if anyone has feedback.

As also mentioned, there will be problems of loading on the transformer causing distortion in my measurements. Again, I plan to use a few tests to try and quantify the impact of that distortion and see if there is some software solution to model it and filter it out. I have not done my research on this yet, but I think I may need another inline on PCB current measure for the AC line to be able to more accurately model the impact on the 9V AC transformer as I draw more load.

My plan is to get everything I need to build standard IoTaWatt 4.0, and also buy bits to experiment on a breadboard. If my experiments fail, then I have all I need to produce something that is known to work so its not a complete loss and hopefully I learn something in the process.

Sounds OK, but can’t be sure without seeing the schematic. Careful of that polarity, especially if you share a DC supply (like both connected to the same USB hub).

I am about to order some CT’s, what CT’s would you recommend perform best with IoTaWatt (probably ones you already have basic calibration settings for)?

I was going to get the SCT-013-000 but reading through some of your comments, you suggested earlier that you found other CT’s performed with better linearity and phase shift, but couldn’t find which models you measured.

I am running in Australia 240V@50hz single phase and will want to monitor on the grid (100A), solar (50A) and then a few individual circuits (20A). If there is no significant difference in accuracy then will probably go for 100A everywhere.

I am going to start with basically vanilla IoTaWatt to get it going then do my homebrew changes from there.

50A solar? How big is your inverter?

Lol yep. It is a gross over estimate :slight_smile: 5kW @ 240V = 20.8A Probably 30A is sufficient.

The SCT013-000 work fine if accuracy is your only issue. I’ve tested a lot of other CTs so that I could put them in the IotaWatt tables to be easily configured.

That said, it does make sense to use a CT that is matched to your current range for better resolution. The solar-edge inverter input that feeds the solar use graphic that I posted uses a $2 HWCT04 solid core CT that has a range of about 41A on the IotaWatt - just about perfect full range on that PV system that puts out just under 8Kw on a cool bright sunny day.

Here are the other factors that would drive my decision:

  1. Price. You can pay a small fortune for a Dent or revenue grade brand name, but at the end of the day, most of the CTs I’ve tested seem to get a result within 1% of a revenue grade meter.

  2. Form factor. This is huge for me because I have a US 200A panel that doesn’t have a lot of extra room inside. The SCT013-000 is big and clunky compared to some of the alternatives.

  3. Ease of connection. Installation goes a lot easier with a healthy length of good quality lead with a 3.5mm stereo jack. The SCT013-000 have that. Few others do. I have resorted to buying inexpensive 3.5mm patch cords to make leads for those cheap HWCT04s.

To round out the choices available, we have been looking at the SCT006 and SCT019 for IotaWatt. They are full range at 33A and 250A respectively. They can be supplied with the same 1M 3.5mm jack that comes on the SCT013-000 and they can have TVS diode protection.

Both of those, along with the SCT013-000 can satisfy most requirements when connected to IotaWatt, and as with all the others, need only be plugged in and configured by selecting it from a menu on the app. No resistor soldering or calibration required.

Not sure when they come available, so using SCT013-000 is still a reasonable choice if your panel has room for them, and since you are a DIY board, you can always up the burdens to increase the resolution. The software lets you specify the value of the burden on each channel and will compute the proper cal factor for an SCT013-000.

For instance, if you put 47 ohm resistors on a few inputs, they would become 42.5A inputs with SCT013-000 CTs with a little more than double the resolution. Just tell the app what values you supplied, and it will do the rest.

Thanks for that I have ordered my Cts and just waiting on everything to arrive.

One other question

How does iotawatt 4.3 currently detect if a CT is plugged into it?

I noticed that you are using 3.5mm TRS socket with switch but the switch is just bringing ADC to BIAS

This means nothing plugged in has same reading as plugged in but no current.

Does Iotawatt currently try and detect plugged in sockets?

No, it does not differentiate between plugged and unplugged. sampling of the input is based on whether it has been configured. If it is configured and nothing is plugged into it, it will simply sample as zero watts.

The reason for the shorting switch is for the case where the burden resistor is removed to use voltage type CTs (external burden). In that case, if one is configured but not plugged in, iotawatt will report zero watts.

Automatically detecting and sampling channels is impossible without knowing the details of what is actually plugged in. That’s what the configuration provides.

Sampling a configured but unplugged channel is really no problem at all.

The only thing i was missing with this is the possibility to 'unconfiguring" an input you do not want to use anymore.
But yes, its not really a problem to leave it configured and not connected.

Bob, how did you choose the ADC you are using for IoTaWatt?

I noticed that it doesn’t do simultaneous sampling and was wondering what the impact is on accuracy in the current design by using out of sync current + voltage samples?

Also, after a quick glance at the code I believe that the sampling basically waits for a zero crossing, then does the sampling for a while and then stops to return to the main loop for other processing so potentially missing important information when not sampling.

Does this mean that IoTaWatt only collects power data for a subset of the total time? I.e. If we have appliances that use power in cyclic bursts IoTaWatt could potentially miss a lot of information?

I am not sure if this is even a thing to worry about if there are any devices out there that may exhibit this behavior. From previous discussions you said the accuracy was within 1% of other solutions which seems quite good to me.

I was considering a few additional changes along the lines of improving accuracy. It is probably not in the slightest bit warranted as you have said IoTaWatt is about 1% accurate compared to other measuring solutions running in parallel.

I am interested in what I can learn from this more than the end product, I could have just bought another OTS solution if that is what I wanted.

The avenues I am considering are:

  • Using existing ADC up-sampling the voltage channel in code to get better estimates of the voltage at the time the current was sampled (assuming current and voltage sampled evenly could just up-sample 2x the voltage)
  • Look into a simultaneous sampling ADC (potentially more expensive but there are 16 channel ones and also have higher SPI rate of 20MHz supported by the ESP)
  • Consider creating an analog anti-aliasing filter on the ADC inputs
  • Write code to sample at regular intervals using the hardware timer in an interrupt handler so don’t miss data when other work needs to be done (been testing this on my breadboard for now)

Hi Brendon,

640 sample pairs per cycle is approximately 1/2 degree of an AC cycle. Phase shift for the VTs and CTs that are affordable and typically used have phase shift in the 2 degree range. Moreover, the phase shift of the CT alone varies by up to several times that depending on current at the low end. So the effect of any phase shift of the voltage is secondary to the phase shift of the VT and CT. This is not true of slower devices, but true with IotaWatt’s high sample rate.

More importantly, when collecting sample pairs at high speed, IotaWatt uses the current sample directly, but averages the bracketing voltage samples to fully compensate for that timing phase shift.

Lastly, after the sample pairs are collected, the relative phase lead between the VT and CT is calculated and the sample pairs are skewed and interpolated to compensate for that difference.

It does. IotaWatt measures up to 15 channels, and it can only measure one thing at a time. So it samples the various channels round-robin style and maintains a time weighted average for each channel. The basic pulse is:

Sampling is initiated about a ms before zero crossing.
Upon zero crossing sample accumulation begins
After two more crossings (one full cycle) accumulation stops.
The samples are processed to develop voltage and power and saved.

At this point, no more sampling can be done until the next zero crossing, so control is returned to the main loop and services that handle web requests, SD logging, time-synchronization, and logging to internet services like Emoncms are dispatched.

As the next zero crossing approaches, we go back to the sample code and start over.

So it takes 1.5 AC cycles to measure a channel. At 60 cycles, that amounts to 40 channels sampled per second. Realistically, it achieves about 38, which means each channel in a fully loaded IotaWatt gets sampled 2.5 times/second or about every 400ms.

If you have an appliance that uses power in bursts shorter than 400ms, maybe. In a more practical vein, most power limiting schemes use PWM and limit total power by clipping each AC cycle using a semiconductor. Light dimmers work this way. The amount of clip doesn’t vary much from cycle to cycle. With it’s high sample rate, IotaWatt does a great job of sampling these clipped cycles.

Let me know how that works out.

And can you provide more information about the “simultaneous sampling, 16 bit, 20Mhz SPI ADC” that you reference. Specifically, a link to the datasheet and the cost.

@overeasy (or maybe others). I made 2 homebrew IotaWatts, and one has a rock solid voltage sensing reading: when entering the calibration page of the vt is does not jump around alot, mostly 0.1 to 0.5V.
The other one on the other hand is jumping around like 5V… on all of the 3 VT inputs. (i made 3 identical VT connections, just like you have 1)
I checked all of the connections (and reheated the soldering) , but something seems to not go completely right.
I know its a longshot, but would you have any idea?

Let’s start with some questions:

Are these three biased by the same OPamp and are they the only inputs on that OPamp?

Is there a 10uf or better ceramic capacitor between the bias and ground?

Does it happen with just one VT connected? Other combinations? All the same?

Can you run the following:

http://iotawatt.local/command?sample=0

to get a look at the samples that are being collected on channel 0 (or one of the others).

Do you have an oscilloscope?