# zmpt101b Module

#### 1968neil

##### Senior Member
Have any of you had any success with the zmpt101b ac module ?

I'm looking at measuring an AC voltage (non Mains) and would like some help/advice if possible ?

Regards
Neil

#### premelec

##### Senior Member
That module appears to be mainly an isolation unit - why do you need to use it? Perhaps be more informative on what voltages you want to measure and the accuracy needed...

#### 1968neil

##### Senior Member
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 :

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

#### AllyCat

##### Senior Member
Hi,

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 understand what the YouTube video above was actually doing ?

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 evidence that the "numbers going up and down" at the end were any real indication of the true RMS value.

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 far better (e.g. accurate) measurement with a PICaxe than shown in that video. But that gets us back to what are you actually trying to measure?

Cheers, Alan.

#### 1968neil

##### Senior Member
Hi 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

#### AllyCat

##### Senior Member
Hi,

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.

#### 1968neil

##### Senior Member
Hi 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

#### AllyCat

##### Senior Member
Hi,

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
sertxd (cr,lf,#w1)
pause 88        ; Or try other values
loop``````
That should send a string of numbers between perhaps 200 and 800 to the Terminal Emulator, which might trace a reasonable sine wave over about 10 or 20 samples (if not try changing the PAUSE up or down by 1 or 2, or a few more). They might/should average around a value of 512. The PICaxe can read the ADC much faster than that, but you and the Terminal can't.

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.

#### 1968neil

##### Senior Member
Hi Alan,
Have tried that with success, thankyou.
I get a constant stream of 512 (i'm using a 40X2 chip)
I'm running the module and the Chip from the same 5v regulated supply with good decoupling and smoothing

Regards
Neil

#### AllyCat

##### Senior Member
Hi,

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
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)``````
Then we can consider the calibration.

Cheers, Alan.

#### premelec

##### Senior Member
@1968neil
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.

#### AllyCat

##### Senior Member
HI,

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" in a thread some years ago. So if you do need an accurate True RMS value, then it can certainly be done with a PICaxe (even an 08M2). And since that YouTube video above appeared to be taking only one "sample" from each mains cycle, a PICaxe version could be faster and more accurate than is shown there.

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 before calculating the average, for example after summing 100 samples you would divide the Square Root result by 10 (e.g. display the final digit after a "decimal point").

Cheers, Alan.

#### 1968neil

##### Senior Member
Good morning,

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:

#### tmfkam

##### Senior Member
For my Grid Frequency Meter I simply used the output of a (standard) low voltage transformer, half wave rectified the low voltage AC, sampled this a few times and stored only the peak reading, the peak reading was then multplied by a *factor* which was chosen to give the equivalent RMS value from the peak value as measured by a (reasonably) accurate multimeter. This is good enough to give a value within 2%-3% of the measured value. The transformer of course provides for safe isolation. If you wanted, you could reduce the sampling time by using full wave rectification.

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