- Thread starter 1968neil
- Start date

I am building a test unit that will need to measure ac voltage, this seems to have been done with the Arduino set up and i wondered if possible to do with a picaxe. Example below :

Need this with ESP8266 12E (NodeMcu)? Check: Measure any AC voltage (250VAC) with ZMPT101B and ESP8266 12E with Android App / Adafruit IO MQTT Hello guys, and welcome, before …

surtrtech.com

The module is ideal in that it as you say it provides isolation, the output is Microcontroller friendly

We still need an answer to Premelec's questions. And I would add: Is the frequency around 50 Hz and 230 (ish) volts, and do you need to make a "true RMS" measurement? Also, do you

If you want to reproduce what that link appears to be doing, then converting to PICaxe is probably not (practically) possible, because it doesn't have available the "Library" functions used by the "Arduino". But IMHO that video doesn't show any

The link above suggests that "ZMPT101B" is actually the transformer type number and we really need to see a complete circuit diagram/detail. But a fundamental question has to be: Is a 250 volt, 50Hz transformer suitable for coupling (but safely isolating) the "AC voltage (non-mains)" that you have(n't) described ? If the limitations of the transformer are understood and acceptable, then I'm sure that we could make a

Cheers, Alan.

Ok i'm making a test jig to check the output of an AC proving unit (440v Ac) its used to test a multimeter is reading correctly before using it in the real world.

The jig will be used to test multiple units in one sitting.

The transformer module data sheet http://5nrorwxhmqqijik.leadongcdn.com/attachment/kjilKBmoioSRqlkqjoipSR7ww7fgzb73m/ZMPT101B-specification.pdf

I think what i need is to be able to measure and display the RMS value and if correct or within a particular window move onto the next measurement etc etc.

I have a very limited understanding of ADC.... having never used it to measure and AC waveform/Voltage.

Cheers

Neil

Ah, I see it's a "Current Transformer" rated at 1:1 and "2 mA". So it needs a (high valued) series resistor on the primary (mains) side and a (low valued) shunt resistor across the secondary (measurement circuit) side. However, we really need a circuit diagram (and/or data specification) for the complete module.

If one looks carefully at the (ebay) photographs of the complete module, there appears to be a SMD resistor (R13) marked "8M" near to the terminal block. But looking more carefully it may be "824" (i.e. 820k ohms), which seems more likely. That would dissipate about 70 mW at 240 volts, but the average current would be only around 0.3 mA. However, I wouldn't be very "comfortable" applying 240 Vrms (~350 v peak), let alone your 440 Vrms (~650 volts peak) to that little SMD resistor. Therefore, I think you should add a suitably rated external resistor of at least a similar value (820k ?) in series with one of the terminal block connections.

But neither that board, nor a PICaxe is accurately "calibrated", so to set up the mult-turn Pot on the module, you will need an accurate reference meter, of the "True RMS" type if you really need an accurate RMS measurement. However, if the signal to be measured is basically just a Sine Wave, then a simple Peak to Peak measurement, using the standard scaling factor, should be sufficient.

The PICaxe ADC (and virtually all micro-based devices) measures an "instantaneous" value which in your case might represent any value between +650 and minus 650 volts. Thus you need to make multiple READADC10 measurements (maybe hundreds) and then filter and average the values. The "filter" is needed to eliminate spikes and you can't use a simple "average" because the average of a symmetrical +/- waveform should be zero ! But a PICaxe program should be quite capable of making the desired measurements, probably with a simple Max - Min (i.e. peak to peak) detection algorithm, or a True RMS algorithm if really necessary.

Cheers, Alan.

Thankyou for that, i have set up the pot on a scope to be as sinusidal as possible.

Can you elaborate on the readadc10 maybe a simple bit of code ?

Im a bit green on the ADC side of things, having only really used them to measure a pot value etc.

Much appreciated

Kind Regards

Neil

Let's assume that the module and PICaxe are both running from a reasonably stable voltage of about 5 volts dc and that the output from the module is a signal that swings reasonably far towards (but not as far as) the 5v and Ground levels. If not, there are other possibilities to be tried.

Then the first thing to try is to send instantaneous output values to the Program Editor Terminal. So try something like:

Code:

```
#PICaxe 08M2
#no_data
#terminal 4800
do
readadc10 c.1 , w1
sertxd (cr,lf,#w1)
pause 88 ; Or try other values
loop
```

When you can get a string of "cyclical" numbers, then we can look at how to use them to make a useful measurement.

Cheers, Alan.

512 is basically "No Signal" because values of 511 down to 0 represent a negative voltage swing and 513 up to 1023 are positive. So you haven't got a "useful" measurement yet. If that's all you get, then put the 'scope probe on the module output or PICaxe input (which should be the same point) to ensure that you've a sinusoidal swing of around 1v to 4v (at 50 Hz of course).

When you get some rolling values, you can measure the peak-peak value, for example:

Code:

```
w2 = 1023
for w0 = 1 to 500
readadc10 c.1 , w1
w2 = w1 max w2
w3 = w1 min w3;
sertxd (cr,lf,#w1," Min= ", #w2 ," Max= ",#w3) ; optional
; pause 100
next
w4 = w3 - w2
sertxd (cr,lf,"Peak-Peak= ",#w4)
```

Cheers, Alan.

FWIW Analog Devices has a line of RMS to DC converter ICs - https://www.analog.com/en/parametricsearch/11023#/ If you really need RMS values fairly fast... another slower approach is to look at heating capability of the AC waveform and relate that to more easily measured DC heating through various tricks.

RMS is of course an abbreviation for "Root Mean Square" , i.e. the Square Root of the average (Mean) of a large number of Squared numbers. That calculation is a "problem" for basic PICaxe maths, but can be easily (and accurately) solved with a few subroutines. The X2 chips do have a Square Root function, but the Square Root of a Word (16-bits) value has a maximum of only 255, so at best the measurement (and even resolution) of a 440 volt supply will be "Give or take a couple of Volts", which may be "Good Enough" but not very impressive.

My main concern was the Square Root, but I'd "forgotten" that calculating the Square Root of a 32-bit value was "solved"

I won't go into full details (yet) but the 10-bit ADC value in this case is "signed", i.e. a 9-bit number plus a sign bit. But the result of Squaring a number is always Positive so we can "forget" the sign and then only need to drop the LSB (e.g. divide by 2, or do any "scaling" at this stage) to keep the Squared result within a 16-bits (i.e. a Word) result. That could be refined by handling rounding errors (up), or by introducing 32-bit maths at this stage (using the ** multiplier).

The "Sum" of many values will create a 32-bit result anyway, but that's easy to do by incrementing a "High Word" register whenever the 16-bit (Low Word) result overflows. Then it's probably better to take the Square Root

Cheers, Alan.

Good morning,

I tried your code Alan,

Works a treat and now makes some sense to this old timer

With no input to the module i now have a steady stream of 1's

If i apply an AC voltage to the module i get an steady output which is gives a near voltage value (ish).

Hopefully with some calibration i could get somewhere near to a spot on value ?

Thank you so much for your help.

Regards

Neil

I tried your code Alan,

Works a treat and now makes some sense to this old timer

With no input to the module i now have a steady stream of 1's

If i apply an AC voltage to the module i get an steady output which is gives a near voltage value (ish).

Hopefully with some calibration i could get somewhere near to a spot on value ?

Thank you so much for your help.

Regards

Neil

Last edited:

Unless you are anticipating the output to be significantly non-sinusoidal this might be close enough for your needs?