PDA

View Full Version : Electricity consumption meter - again



davidwf
01-02-2010, 00:18
I have trawled the forum, I have searched various phrases........

Does anyone actually have a COMPLETED and working project for reading their domestic electric meter (the ones with a flashing LED) - either via wireless link or to an LCD display.....if so would you point me in the right direction to share in your knowledge please

Thanks

seanfell
01-02-2010, 09:41
Actually i'd second that request

I've been wanting to do a similar thing for a while.
It would be great if the suppliers of the 'off the shelf' energy meters published the wireless spec's and protocols so i could pick them up via something i built.
There simple cable clamp mechanism with a wireless transmitter would be perfect for me, i just want to then build my own receiver.
None of the many i've looked at publish any detail on what's transmitted
Although a few do have a USB output for hooking up to a PC (the receiver that is)

dennis
01-02-2010, 10:14
I have a working system that detects the 1Ws pulses that these meters give. This information is then transmitted wirelesslyand displayed either on a PC or LCD. So this is a kind of "instantaneous" power consumption. It would be simple to count pulses over a 24 hour period to give total consumption.

I have not experimented with reading the meter but did download an article from Elektor magazine which described the IEC1107 meter interface and how to make a simple set up.

hippy
01-02-2010, 10:23
The meter interface protocol itself seems to be pretty well defined as IEC61107 though there are also other alternatives in use. For modules and wireless modules which connect to a meter and transfer information those will likely be proprietary protocols as it is expected a consumer will be using meter transmitter and display or PC receiver supplied by the same manufacturer.

I would expect any wireless link to be designed to be secure to stop information from one property being shown on displays in adjacent properties, and to stop someone sending malicious data which make it appear consumption is higher than it is - That would be a nightmare to track down, and would probably be illegal activity in the UK under the Computer Misuse and other Acts. That's what I'd expect, reality may be different.

@ davidwf : Electricity and gas meters with data output are only a recent thing so there will likely be few PICAXE users with experience of them. IEC61107 looks simple enough to use and interface with so perhaps if you can give a more detailed explanation of your problem someone may be able to help, even if they don't have such a meter themselves.

seanfell
01-02-2010, 10:32
>> I have a working system that detects the 1Ws pulses that these meters give. This information is then transmitted wirelesslyand displayed either on a PC or LCD. So this is a kind of "instantaneous" power consumption.

Would you mind giving out more details... ?

demonicpicaxeguy
01-02-2010, 10:56
i've been down this road before, don't be fooled by the flashing led on the front some of them flash in proportion to current draw and some flash at the same rate no matter what...

it's easier cheaper and probably quicker to build or buy your self a hall effect current sensor and have that on the mains cables entering your meter box,
the calculations should be quite simple and probably a lot less headaches,

Dippy
01-02-2010, 11:16
"i've been down this road before, don't be fooled by the flashing led on the front some of them flash in proportion to current draw and some flash at the same rate no matter what..."
- so look at it and then switch the kettle on and look at it again ;)

Current sensors (alone) don't take PF into account and can lead to large errors.
There are many sensors (with and without RF links) that do this already and there have been a lot of moans.
See this - towards the bottom under the heading "Energy Meter reliability ".
http://www.frequencycast.co.uk/energymeters.html

So, its best to get data from a proper Power Meter and display it.
Here, as an example of what can be done, is an early test prototype of a portable unit. It takes readings from one or more Energy sensors (and any other sensors) and can also allow you to switch things too.
http://www.youtube.com/watch?v=6MlACGeHtrw

davidwf
01-02-2010, 11:17
thanks for the early replies.....looks promising

for what it's worth my meter says 800 pulses per kW/h (= 1.25 W/h per flash ??) but I think I could do the maths ......:)

So, discounting the remote / RF link featrure for the time being (lets' walk before running) any guidance on PIC code for converting the flashes to 's and kw/h perfhaps displayed on the humble PIC LCD would be a good starting point.

There seems to be a lot of discussion on the internet - and this forum - but little available project wise....surely someone must have done it

demonicpicaxeguy
01-02-2010, 11:20
I would expect any wireless link to be designed to be secure to stop information from one property being shown on displays in adjacent properties, and to stop someone sending malicious data which make it appear consumption is higher than it is - That would be a nightmare to track down, and would probably be illegal activity in the UK under the Computer Misuse and other Acts. That's what I'd expect, reality may be different.


once upon a time in a previous life as a meter reader in sydney,australia in the 4 years i did that job i came across hundreds of them where my handheld thingy gave me the option to use the wireless option only a handfull of them actaully worked with any success and in most cases it was quicker to read the meter manually, they typically use 433mhz and to say hopeless is an understatment and even thats an understatement,

IEC61107 is really just for meter reading companies, not for the end user

even with the "probe" (the optical interface(circular thing with the bottom key part )) has it's own issues, they use 57600bps, they are ok but it can be a bit like "which position is the moon in" if you get what i mean

there is also the issue of the encrypted password problem this is there and encrypted for a reason and one very good one, if you can successfully sign in to a meter you are able to reset the counters which is why the electricity companies like to keep this kind of stuff closely guarded

****** a brief note as well be carefull with what attach to these things, because if the meter reader comes around and sees anything looking even a little bit suspect he/she (yes there are she meter readers) they can put in a flag/comment and these are usaully followed up*******

Dippy
01-02-2010, 12:59
Maybe I should add that I wasn't suggesting interfering with the Mains Electricty with the device mentioned/linked in my previous posting. Just wanted to make that clear.

MikeM100
01-02-2010, 13:09
Many posts on gas and electricity monitoring in this forum:

http://www.navitron.org.uk/forum/index.php/board,45.0.html

PicAxes are well suited to such applications.

Dippy
01-02-2010, 13:57
Can you point us towards the project areas of interest in that please Mike.

I had a quick look and saw some posts where people a) think a tuppeny Energy Meter is accurate, and b) once again, the idea that CTs will (by implication) always give good results.

The (overly) quick look I had doesn't suggest detailed technical knowledge.


I've probably missed something in my 2 minute impetuous haste and it would be a shame if people got the wrong info. and this subject is a very trendy bandwagon currently.

MikeM100
01-02-2010, 14:53
You might look at this post:

http://www.navitron.org.uk/forum/index.php?PHPSESSID=26a7a02j345cca2gcbv3pmbld0&topic=8881.0

This blog is also relevant to the subject:

http://sustburbia.blogspot.com


And the most comprehensive site is here:

http://www.bwired.nl/Gas.asp

Yes, it is a trendy subject and for good reason. I don't think energy prices will be going down in the future. In the above Navitron post I have described an ultra simple gas meter logger using nothing more than a bicycle odometer and a reed switch !

This particular subject renewed my interest in PicAxes as I have been 'tinkering' with a gas meter logger and used the PicAxe logger as a basis for my experiments.

Dippy
01-02-2010, 15:03
Mmmm.... that first link was gas.
This post is about electric.

I saw the post. Jeeez.
Lovely tatty veroboard and exposed wires next to a gas meter!
No highlighted discussion about safety or spark prevention.
And just think , incompetent people will copy it.

I think my worries about little knowledge are confirmed ;)

davidwf
01-02-2010, 15:03
So, on the face of it the available clip on current probes aren't that accurate as they don't (can't) take into account the power factor weighting......but then again the flashing LED type is claimed (by some) not to be that accurate either :mad:
My meter says 800 flashes per kW/h rather that 1000 that others have reported.

My own thoughts are that the LED version "should" be better as it is an integral part of the meter and therefore presumably does take into account the power factor......

thoughts on this ?

......and, of course I am still searching for that elusive working PIC based project....:)

Dippy
01-02-2010, 15:13
David,
I have recently been involved in designing a networked Energy meter.
Yes, the proper chips DO take into account the measured Power Factor.
It involves measuring current and volt and determing PF and doing a pile of maths very, very rapidly.

(Yes, it was PIC based, but not PICAXE, sorry)

"So, on the face of it the available clip on current probes aren't that accurate as they don't (can't) take into account the power factor weighting".
- if it clip-on CT only then remove "on the face of it" from your sentence :)
You will see a small sample of the criticisms if you check my link on the previous page.


If you think that your official electricity meter is over-reading then report it to your supplier.

There are half a dozen big manufacturers who make the nitty-gritty chip. Maybe you should investigate to see the flashing LED spec. Or try and get some info from your supplier or the meter manufacturer.

dennis
01-02-2010, 18:44
@ Seanfell - I am travelling but will get you some details by the weekend. In its simplest form you just need a single 08M that detects pulses with an LDR taped with black tape over the meter LED window. Each time a pulse is detected the 08M sends an update command to the PC which is running the free Parallax DAQ software. This software then adds another line in excel when the pulse is received and adds the PC time. Excel then calculates the rest.

My current system does not use the PC but uses a wireless link and displays power on an LCD display. Total of 3 08Ms used. One counts mains cycle pulses , one detects meter pulses proccesses data and handles wireless TX. The other 08M handles wirelss RX and updates the serial LCD.

@ DPGuy The meter LED is labelled 1Ws and flash rate ceretainly depends on power consumption. Accuracy is unknown but at least relates to what you are paying for !
Can a Hall effect accurately monitor the range 60W to 10kW ?

Dennis

davidwf
01-02-2010, 19:22
dennis...

sounds the sort of thing I am after....if nothing else then it will be a good building block

Thanks
DF

BeanieBots
01-02-2010, 21:08
Can a Hall effect accurately monitor the range 60W to 10kW ?

A correctly spec'd one can, but can a 10-bit ADC give the required resolution:rolleyes:



clip on current probes aren't that accurate as they don't (can't) take into account the power factor weighting

As a simple example.
Unloaded torroidal transformer gives a reading of ~40W.
Actual losses in the unloaded transformer ~0.7W.
Error = ~5700% ... That's some error:eek:

Guess it boils down to what sort of equipment you want to measure.
If it's the kettle, then fine, if it's your transformer powered items on standby, then expect to be a factor of ~1000 out!

SgtB
02-02-2010, 01:22
Here's a blog about an itron meter with wirelss and IR. http://davestech.blogspot.com/2008/02/itron-remote-read-electric-meter.html I've been counting the IR pulses on mine for a few days, and they seem to line up which is fortunate, but I'm sick as a dog and haven't gotten too into it. It outputs a 10ms pulse per w/h. The blog never gets an actual wireless reading, but it's good reading IMHO.

Here's a photo of the pulse I found. http://www.flickr.com/photos/blalor/3876765280/ I 'm thinking the carrier signal is just uC noise, but who knows.

Dippy
02-02-2010, 11:47
Well I gave up reading it when I saw the quality of soldering :)

A search in the forum shows numerous methods of sensing the flashing LED.
There are numerous threads on using PICAXE timer as a stopwatch (in effect).
There are numerous threads on using RF...

Put the three elements together, plus some patience. Then build and calibrate and Bob's yer Uncle.

David, what is your skill/experience level?

"I am still searching for that elusive working PIC based project"
- does this mean you are waiting for someone to supply you with a finished PICAXE based device?

Perhaps YOU could do it and provide it to the Forum as a definitive project?

ciseco
02-02-2010, 12:54
here's something that will work and is cheap to build

http://www.openkontrol.org/wiki/tiki-index.php?page=Electricity+LED+pulse+meter+reader

Miles
________
BMW M78 specifications (http://www.bmw-tech.org/wiki/BMW_M78)

davidwf
02-02-2010, 14:11
David, what is your skill/experience level?

"I am still searching for that elusive working PIC based project"
- does this mean you are waiting for someone to supply you with a finished PICAXE based device?

Perhaps YOU could do it and provide it to the Forum as a definitive project?

My experience level.....mmmm....without wishing to appear big-headed......electronics as a hobby - very good, construction and prototyping - even better....PIC - beginner....very beginner :D I struggle and tend towards "belt and braces" approach....but I am very determined !

No, I am not looking for a finished project - far from it - I will be more than happy to do that as I have with the coolbox controller, curtain and lights controller and fridge thermostat ! :)

hippy
02-02-2010, 14:28
@ davidwf : It seemed you were after a completed project in your first post, though it's perhaps best if you detail what help you need, are looking for, or where you are having problems.

It's always best to be clear about PICAXE or PICmicro rather than "PIC", as forum users cannot easily tell if using PICAXE and you want PICAXE code, or actually are talking about something else. That goes for everyone. PICAXE and PICmicro ("PIC") are very different beasts when put along side each other.

davidwf
02-02-2010, 15:14
OK, wrists slapped :(

I am after some suitable PICAXE code as requested by others in this forum, as previously stated I struggle with the programming side of things, the hardware side I have no problem with

hippy
02-02-2010, 15:45
But what is "suitable PICAXE code" ? What do you want / would like that code to do, or show ?

dennis
09-02-2010, 19:39
@ Seanfell

Sorry about the delay - my trip got extended and I am still not home yet but write up the project and code when I finally gewt home.

Dennis

mark.duyvesteyn
09-02-2010, 19:57
only draw back is that you need to have a pc or mac on al the time (or openWRT router)

www.sites.google.com/site/19acussen (http://sites.google.com/site/19acussen/)

I have started an instructable but have been away for work and pretty busy so havn't had time to finish it..yet.. must get on to it.

http://www.instructables.com/id/the-real-5-web-based-power-and-gas-meter/

All pretty basic picaxe and python code, grabbed and modified from around the net.

mark.duyvesteyn
09-02-2010, 20:08
My own thoughts are that the LED version "should" be better as it is an integral part of the meter and therefore presumably does take into account the power factor......

i did a test over a week correlating flashes to meter rotations and it was 99.9% accurate. That is the light flashed 50,000 times and the the meter went round 50,000/800. It was only out by about 30 or so flashes, which is prob from restarts e.t.c.

Thalass
20-02-2010, 03:27
Hi. This looks like exactly the project I want to do. I've been keeping track of my energy usage manually by photographing the meter and entering the data into a spreadsheet. But at best that's once a day, and often several days, between readings. If i could get an instantaneous (or close to it) reading it would be great.

I've attached an image of the meter. The LEDs in the green circles light up together (labled kWh for the visible red, and a digital symbol for the IR) - these flash at a rate proportional to the load, though I don't know exactly what one flash indicates. 1/1000th of a kWh? 1/800th (as mentioned above), or 1/100th? I haven't the patience to stand there counting flashes and comparing to the meter readout. haha.

The LED in the yellow circle is labled "kVARn". I'm not sure what the Rn part is, though. It flashes with slightly different timing.

I think the IR LED is what I'd be interested in monitoring. The two red LEDs to the left I have no idea about. To the right of the LCD is a pair of buttons to change the information displayed, and to the right is the proper interface that I assume the meter reader uses. (and I don't want to screw with that).

It's a pretty new meter, the house itself is only six months old or so. To me the IR LED looks to be the key to reading instant power usage (though one minute resolution is probably as accurate as I'd need.). Does this look right?

westaust55
20-02-2010, 03:35
The LED in the yellow circle is labeled "kVARn". I'm not sure what the Rn part is, though. It flashes with slightly different timing.



kVAr = kilo Volt-Ampere reactive.
Not sure about the "n" - maybe what is flowing in the neutral conductor ?

kVAr is the reactive power component of the total load electrical demand.

A resistive load is pure/real power in Watts.
When there is inductive (lagging) or capacitive (leading) components in the electrical load, the current lags or leads the "real" power component.


The meter is seemingly made by Email an electrical equipment manufacturer (meters, circuit breakers, etc).
Do you have a model number from the front of the meter?
If so, you or others can do a search and get more details about the meter.

Dippy
20-02-2010, 11:47
Could you email the Manufacturers and ask them ?
What does a flash mean?
What comes out the IR LED?
They may give you some good info - takes guesswork out of the equation.

Thalass
20-02-2010, 13:51
westaust55: Attached is a photo of the label on the unit. I've tried googling the cat number, and model number, etc. Nothing that I can pick out as useful. heh.

Dippy: By 'flash', the LED comes on then goes off - with a 50% duty cycle. Rather than a blink as such. It always seems to be 50% on, 50% off. Just a faster rate for greater current draw. The IR LED and the visible red LED marked "kWh" are on at the same time. Using the IR would probably reduce confusion with the other red LEDs in the area, I guess.

I attempted to search for an "email electronics company" or "email power meter", but nothing useful comes up that I can find. What a stupid name for a company. wtf.

papaof2
20-02-2010, 16:56
The label has "Meter constants" followed by "1 varh/imp" and "1Wh/imp".

My suggestion would be to have someone turn on a high wattage device (1KW heater or electric kettle) while you're watching the meter to see what change that much load makes. If my reading of the label is correct and the spec for the LED is in watt hours, one kilowatt for one minute is about 16 watt hours, so the LED should flash an additional 16 times during each minute the 1KW load is on.

Google has a few pages if you search for
em3330 meter

There's a page on reading the EM3330 Code 0350 meter: http://www.synergy.wa.gov.au/Residential_Segment/SmartPower/SmartPower_Savings.html

That meter is also used for "bi-directional" power measurements (when you have local generation capability): http://www.westernpower.com.au/documents/renewableEnergySystems/draftReportServiceandTariffSept09.pdf

John

westaust55
21-02-2010, 02:09
Try reading the attached document.

That is likely an Ampy 5192B 3 phase kWhr meter, as used by Western Power here in WA.
See page 6 (section 5.1) here:http://www.westernpower.com.au/documents/contractors/amrInstallationPolicy.pdf


Edit: A compounding problem is that these types of relay are Supply Authority programmable so there may/will still be variances between what a manual says as default and what Western Power deliver to your home.

Thalass
21-02-2010, 11:40
Wow thanks. My google-fu has been failing me lately. Too many projects at once I think.

The description on the smartpower page there does sound about right, as I did ask for the bi-directional and also three phase meter, as I want three phase for my garage (charging an electric car in the near future) and possibly for other things. And I intended to set up some kind of grid-connected power generating system too. Whether we live here long enough to do all that remains to be seen hah.


Thanks for your help guys. I'll read this stuff and try and learn the picaxe code, then see what I can put together. Can't promise it'll be good, though hehe

bpowell
26-03-2010, 07:34
here's something that will work and is cheap to build

http://www.openkontrol.org/wiki/tiki-index.php?page=Electricity+LED+pulse+meter+reader

Miles

Hello!

I'm joining the ranks of those working on a real-time power meter! I've breadboarded the circuit found on the link above, and after much learning, (which I love) I have a Picaxe receiving and counting the pulses...It's been a great experience so far learning about the different inputs (Just figured that one out...schmitt trigger vs. TTL)

Now that I have the circuit working as I'd like, I'll get started brain storming the code.

My objective is:

1: Monitor pulses from my power meter's IR LED then either:
A: count pulses in a specified time period or
B: Determine the elapsed time between pulses
3: Send the data via 433 mhz RF link to a Picaxe in the house which will calculate the consumption to cost and display various statistics on an LCD...I'm also thinking of making my own "Ambient Orb"....having a Picaxe receive the consumption information and light up various colors LED's...Green for good...Yellow for moderate consumption, Red for "going crazy!"

So, that's where I am...any thoughts from the forum regarding which method to implement? Counting the number of pulses in say 5 seconds, or, counting the time between pulses...say, 3 pulses, and then send that data?

I'm in the States, and my meter has 1000 pulses per kw/h.

Brendan

hippy
26-03-2010, 10:28
Counting or timing .... Perhaps the first thing to do is to work out what the timing and rate of pulses will be and what you want to show with regards to electricity consumption. This will be harder to deal with for lower consumption; a pulse every W/h and drawing 1W will only give one pulse an hour. Even with a moderate load of 1kW you'll get 1000 pulses an hour, one every 3.6 seconds.

This suggests to me that measuring timing between pulses is the way to go. This allows instantaneous consumption to measured as best it can be. It's effectively using counting, but with a variable counting period which ensures a count of only 1.

If you want to measure more average consumption, per hour or per day, you have to decide is that for a particular period, the last day or hour is that one which passed by some time ago, or the last 24 or 1 hour measured back 'from now' ?

I'm guessing that ideally you'd want all data displays and to be able to switch between each without invalidating other displays. I suspect that ideally you need to store every pulse and its intervening period and then calculate using that data set. That could be quite demanding and require some large data storage.

A key factor is how accurate you want your data / results to be ? Should it match the meter reading exactly after a few months or are you happy with a less accurate system ?

Grant Fleming
26-03-2010, 12:41
I attempted to search for an "email electronics company" or "email power meter", but nothing useful comes up that I can find. What a stupid name for a company. wtf.

'Email' electrical devices/systems have been around for a quite a few decades now, before computer e-mail was in use so before the word 'E-mail' (Electronic-mail) ever had been made!

I have had to repair Email refrigeration units on shipping containers in the early 80's.

I can imagine search engines would throw up all sorts of unwanted results if you were not specific enough in search key-words! Glad you have eventually found the info you need.

bpowell
26-03-2010, 14:56
This suggests to me that measuring timing between pulses is the way to go. This allows instantaneous consumption to measured as best it can be. It's effectively using counting, but with a variable counting period which ensures a count of only 1.

If you want to measure more average consumption, per hour or per day, you have to decide is that for a particular period, the last day or hour is that one which passed by some time ago, or the last 24 or 1 hour measured back 'from now' ?

I'm guessing that ideally you'd want all data displays and to be able to switch between each without invalidating other displays. I suspect that ideally you need to store every pulse and its intervening period and then calculate using that data set. That could be quite demanding and require some large data storage.

A key factor is how accurate you want your data / results to be ? Should it match the meter reading exactly after a few months or are you happy with a less accurate system ?

Hi Hippy,

I'm a little confused about the first paragraph above...when you mention the count will always be "1"....However, after stewing it around in my mind last night, I'm thinking focusing on the time between pulses, rather than the number of pulses in a time period is the way to go as well.

Regarding the displays...yes, I may (pending approval of SWMBO) have more than one display in the house...so I'm thinking the transmitter side will simply send the time between pulses, nothing more...and all the math / calculations will be handled on the receivers.

With regards to accuracy, I'm not going to blow a fuse over it (ba-da-dum! Okay, bad pun)...the closer I can get it to line up with the meter, the better, but my real objective is to get a real-time feedback on power consumption to help me (and the kids) be more conscious of what we're using in the house...(with the added benefit of saving some $$ on the power bill, which I will roll right back into Picaxe chips! :) )

Here is an idea I had last night...haven't coded it yet, but have a 18 hour shift coming up at work which will give me plenty of time to write code...

1: Set interrupt for meter pulse
2: Get first pulse, go to interrupt
3: Since this is first pulse, set seconds counter to 0 and return
4: Count elapsed seconds, store that variable in B1
5: Next pulse arrives
6: Interrupt knows this is pulse #2...takes elapsed seconds from B1 and stores in b2
7: Reset B1 to 0, Return, start counting elapsed seconds, store that in B1
8: Next pulse arrives...
9: interrupt knows this is pulse #3...takes elapsed seconds from B1 and averages with that stored in B2...transmits that number to the receivers
10: Reset all counters and start over again.

Some initial hurdles...yesterday, when I was testing my detector circuit...the heat-pump was on, and I think I had more than a pulse a second...so maybe I'd need to add some intelligence when pulses are coming in that fast, to switch to a "pulses within 5 seconds" scheme or something...just brainstorming there.

Well, Just some food for thought.

Brendan

lbenson
26-03-2010, 17:20
> more than a pulse a second

Since a picaxe at 4mHz can execute about 2000 instructions per second, you shouldn't have any trouble keeping up with your original scheme of interrupting with each pulse and recording the time (perhaps in tens or hundreds of milliseconds) since the previous pulse. This assumes that you have some place to log the data quickly, and some way to record the time (using a timer and accounting for rollovers if necessary). If the ticks came too fast, you could up the speed.

Your main loop (which gets interrupted) could be one which keeps the time and occasionally sends the data off to your main recording and logging PC or other device.

hippy
26-03-2010, 18:36
An 'instantaneous energy used' meter would be a good starting point. That should be relatively straight forward with quite simple maths but would need some thinking about to actually do that maths.

I'd aim for a very simple system; whenever a new pulse arrives, note the time ( 't' seconds ) since last pulse, reset and start the timer going again. The instantaneous power is ...

kWh = 3600 / t

So if t=0.24s that's 15kWh, t=3.6s that's 1kWh, t=3600s is 1Wh, and so on.

At high power the pulses will be coming thick and fast ( well, not that fast ) so nothing to do other than to display the value calculated as above. But you don't always want to wait for the next pulse as it'll continue show whatever was used last even if that was so high it's blown the fuse !

As long as the previous 't' has been stored, every second that 't' can have a second added to it and the kWh=3600/t calculation done again. That way the usage will decay which will be more realistic. With only 1000 pulses per kWh it's just not possible to quickly tell what a low power is accurately, just something one has to live with and it's the same issue with bike speedo's when just crawling along.

bpowell
28-03-2010, 06:39
An 'instantaneous energy used' meter would be a good starting point. That should be relatively straight forward with quite simple maths but would need some thinking about to actually do that maths.

I'd aim for a very simple system; whenever a new pulse arrives, note the time ( 't' seconds ) since last pulse, reset and start the timer going again. The instantaneous power is ...

kWh = 3600 / t

So if t=0.24s that's 15kWh, t=3.6s that's 1kWh, t=3600s is 1Wh, and so on.

At high power the pulses will be coming thick and fast ( well, not that fast ) so nothing to do other than to display the value calculated as above. But you don't always want to wait for the next pulse as it'll continue show whatever was used last even if that was so high it's blown the fuse !

As long as the previous 't' has been stored, every second that 't' can have a second added to it and the kWh=3600/t calculation done again. That way the usage will decay which will be more realistic. With only 1000 pulses per kWh it's just not possible to quickly tell what a low power is accurately, just something one has to live with and it's the same issue with bike speedo's when just crawling along.

Hi Hippy,

Thanks for these formulas and ideas...already, you've found a more graceful way to solve the problem than I was thinking!

I'm sitting up late trying to work out the math...since Picaxe doesn't do 3600 / .24...I'm trying to figure out an alternative.

I'm also establishing to realistic windows, so I don't have to go too crazy with the code....I'm okay with a resolution of 10th of seconds...(Frankly, I'm okay with a resolution of "seconds" but I can see that at times, the flashes come in faster than that...so I figure dividing a second into 10's would make it easier.

However, I need to make sure the value I send does not exceed 65,500 (the size of a word), and I need to be able to do some simple math on the receiving side to figure out "real time" kw/h usage...and maybe even plug in my electric companies kw/h cost...and have the picaxe say, "You're spending..."

So, it's a work in progress.

I've moved the hardware for the IR Led sensor from breadboard to circuit board...still works. That's a start!

Dippy
28-03-2010, 10:37
Why don't you constantly measure time between pulses and use an interrupt to pop out and deal with request.
Then you can send the previous time-between-pulses as he reply.
Therefore it will give a near-instant reply.

hippy
28-03-2010, 11:02
If you keep the 2.4s readings in milliseconds you get 2400ms and the maths becomes -

Wh = 3600000 / t

which, to keep within PICAXE limits is the same as -

Wh = ( 36000 / t ) * 100

You may lose seme accuracy that way but it can be clawed back, say multiply 't' and 3600 by 1.5 -

t = ( t / 2 ) + t
Wh = ( 54000 / t ) * 100

Or multiply by 1.75, better as you want the top value as close to 65535 as you can get it -

t = ( ( t / 2 ) + t ) / 2 ) + t
Wh = ( 63000 / t ) * 100

The resolution you want is really as large as possible, because only a small change in time can make a quite big difference in kWh consumption. I would expect milliseconds is good enugh but haven't looked at the numbers. You can store the number in the best unit which doesn't cause overflow and have a scaling factor to apply after doing the maths.

Once you have some hardware and some basic maths implemented it's just a case of thinking on 'how to' and trying things out, and you can observe the results.

bpowell
29-03-2010, 04:05
Hi Gang,

Here's an update on how I'm coming with this project...the hardware is built and working (no RF just yet, but that's down the road)...the software is built and in testing...still a few quirks to work out.

I'm measuring 10 ms at a time, and incrementing a variable every 10ms by one...when a pulse triggers, I take that variable and send it out via serial...Haven't built the receiver yet...but it'll have code along the lines of:

Receive 240 (2.4 seconds)
w/h = (36000 / 240) * 10 = 1500 (1.5 kw/h)

This gives me a resolution of about 10 w/h...which I think is okay.
Receive 241 (2.41 seconds)
w/h = 1490 (1.49 kw/h)

What I'm trying to work in now is a delay...even though I'm saying "real-time", in actuality, I imagine after a few days of "real time" monitoring, I'd probably like to throttle back to an update every ten seconds or so...no need hogging up the 433 mhz band with an update or two every second! however, whenever I sneak a delay anywhere in my code; I get a real odd reading...I have another Picaxe blinking an IR led every 350 ms or so...so I'll get "35, 34, 35, 34," which is okay...but then when I add a delay, I get, "35, 8, 34, 8, 35, 8"...so I'm still trying to figure that out.

So far though, so good!

Code is attached:



' Real Time Power Meter LED detector / Counter
' This will go on our power meter, and hopefully send data in the house for
' Real-time monitoring of power consumption
'
' First, need a circuit to detect the IR LED and send clear logic signals
' To the Picaxe...may be onto something...
' Using a varient of a circuit found here: http://ciseco.co.uk/forum/viewtopic.php?f=15&t=59
' Will use INPUT 2 on the picaxe 8m, as it's a Schmitt Trigger level input
' Input is normally high, goes low on a pulse
'
' Built for Picaxe 08M
' March 2010


' A Standard Picaxe 08M
' __________
' 5V VCC 1- | |- 8 0V GND
' Serial In 2- | |- 7 Out 0 / Serial Out / Infraout
' ADC 4 / Out 4 / In 4 3- | 08M |- 6 In 1 / Out 1 / ADC 1
' Infrain / In 3 4- | |- 5 In 2 / Out 2 / ADC 2 / pwm 2 / tune
' ----------
'

' The LED Detector / Counter / Transmitter
' __________
' 5V VCC 1- | |- 8 0V GND
' Serial In 2- | |- 7 Serial Out
' LED Status 3- | 08M |- 6
' 4- | |- 5 LED Flashing Trigger input
' ----------
'
' Available Bytes: b0 - b13
' Available Words: w0 - w6
'
' Currently 168 Bytes out of 256




#Picaxe08m ' Instruct Compiler to use a Picaxe 08M Chip

' *** Declare Variables

Symbol LEDin = pin2 ' Using input 2 as it's a Schmitt Trigger input, which has the logic
' levels I need to make this work
Symbol LEDout = 4 ' Something to blink and help develop circuit
Symbol ElapsedTime = w6 ' b12 and b13 now unavailable due to w6
Symbol Countdown = w5 ' b10 and b11 now unavailable due to w5
Symbol PreviousTime = w4 ' Previous elapsedTime b8 & b9 now unavailable

' *** End Declare Section


' *** Start Init Section / set up variables

Low LEDout
ElapsedTime = 0
Countdown = ElapsedTime + 1500 ' Countdown is 15 seconds (give or take)

setint %00000000, %00000100 ' Set interrupt on input 2, going low (first #=input, Second #=mask)

' *** End Init Section



main: ' The Main program

' Want to send an updaet every 15 seconds regardless of value change

do while ElapsedTime < Countdown
pause 10 ' wait 10 ms (may adjust for fine tuning later)
inc ElapsedTime 'ElapsedTime = ElapsedTimei + 1
loop


gosub Update ' loop complete; so 15 seconds has elapsed with no pulse (or same freq)

goto main ' Start over


interrupt:


' ToDo: In here, need to take elapsed time, compare with previous value (to see if changed)
' If changed, then transmit new elapsed time between pulses to serial (RF later)
' If not changed, reset ElapsedTime counter and
' And jump back to program
If ElapsedTime = PreviousTime Then
ElapsedTime = 0
' There's a little bug here; if for some reason, the flashes come in the same frequency
' (exactly) then there will be no updates until the frequency changes. As resetting
' ElapsedTime means it will never be = or > Countdown
' Will look and see if this is an issue down the road; initial testing indicates
' it won't be a problem; value should always be changing...
Else
Gosub Update ' Send the new time...
PreviousTime = ElapsedTime 'Reset the compare variable
ElapsedTime = 0 ' Reset Elapsed Time
Endif

do while LEDin <> 1 ' Wait for interrupt condition to clear before re-arming
loop

setint %00000000, %00000100 ' Set interrupt on input 2, going low (first #=input, Second #=mask)

Return



Update: ' Here is where we transmit the time between pulses on serial

high LEDout

Setint OFF ' Turn the interrupt off to prevent it from triggering during x-mit

sertxd("Elapsed Time Between Pulses: ",#ElapsedTime," centi-seconds",13,10)
Gosub Reset_Countdown ' may be able to remove this later for space...


do while LEDin <> 1 ' Wait for interrupt condition to clear before re-arming
loop

setint %00000000, %00000100 ' Set interrupt on input 2, going low (first #=input, Second #=mask)

low LEDout

Return


Reset_Countdown: 'This sets the 15 second count down timer...system should update every
' 15 seconds even if no pulse is detected...elapsedtime will continue to
' increment, so this will show decaying power consumption
' Until 11 minutes...where the counter rolls over...then the universe explodes

Countdown = ElapsedTime + 1500
if Countdown < ElapsedTime Then
' What do do if roll-over? 65535
' Roll-over means nearly 11 minutes have elapsed without a flash...
' Either a power out, or I've gone crazy and unplugged EVERYTHING
' Let's assume I'm crazy
ElapsedTime = 0 ' For the moment, just reset and start over...unlikely to see this event
Countdown = ElapsedTime + 1500
endif

Return


end

hippy
29-03-2010, 09:04
What I'm trying to work in now is a delay... whenever I sneak a delay anywhere in my code; I get a real odd reading...I have another Picaxe blinking an IR led every 350 ms or so...so I'll get "35, 34, 35, 34," which is okay...but then when I add a delay, I get, "35, 8, 34, 8, 35, 8"...so I'm still trying to figure that out.

I haven't examined the code but did note you are using interrupts. If the PICAXE is in a PAUSE when the interrupt occurs it will prematurely abort the PAUSE. Something which follows that interrupted PAUSE and assumes it was as long as it was expected to be will be incorrect.

One simple solution to that is to have not one large PAUSE but a FOR-NEXT loop of shorter PAUSE which amount to the same. One of the PAUSE may get shortened but that is the most time you will lose.

Alternatively you need to use a mechanism which either does not interrupt or timing which is not affected by interrupts. As the pulses are so slow you should be able to get away without using interrupts, just use polling.

bpowell
29-03-2010, 15:00
I haven't examined the code but did note you are using interrupts. If the PICAXE is in a PAUSE when the interrupt occurs it will prematurely abort the PAUSE. Something which follows that interrupted PAUSE and assumes it was as long as it was expected to be will be incorrect.

One simple solution to that is to have not one large PAUSE but a FOR-NEXT loop of shorter PAUSE which amount to the same. One of the PAUSE may get shortened but that is the most time you will lose.

Alternatively you need to use a mechanism which either does not interrupt or timing which is not affected by interrupts. As the pulses are so slow you should be able to get away without using interrupts, just use polling.

Hi Hippy,

I'm off to work; but will hopefully have time to play around with code (sans hardware) at lunch.

This was my first go at using Interrupts...I really like the concept, but if they're not right for this application, then I can go to a for-next loop.

My understanding from the manual is if an interrupt triggers in a pause, when the interrupt returns, the pause will be completed regardless of the time remaining...my pauses are only 10ms...and the difference I was seeing in numbers (35 to 8 equals 350ms to 80ms...) 270 ms are lost...this is more than just one pause being shortened...so that's what was confusing me.

Last night, as I tossed and turned worrying about this project...(Well, really, I just fell asleep, but I wanted to be more dramatic)...I had a thought. pulses are coming in every 350 ms...which the sensor is recording well...however, when I add that 1000 second pause (or 15 seconds, whatever). when I release out of the pause, the system is dumped into "start counting" mode again, right in front of an incoming pulse...hence the small number....the next number is accurate, then the pause, then the short number again....maybe that's what's happening.

I had a couple of ideas...do the pause, then a do/loop waiting for a pulse before releasing back into the code...this would "sync" the pulses back up...or, having a pulse trigger the interrupt, then have the interrupt start the timer, and wait for another pulse...(meaning 2 pulses are needed for a measurement).

All of the above, as well as looking at a for/next loop will give me something to do at lunch and back at home!

Thanks again!

Brendan

SAborn
29-03-2010, 16:37
The easy solution is to put the project on hold till the 18mx2 hits the market as a multi tasking chip would do this job nicely.

I am currently building a amp/voltage data logger for a wind generator using a CT and get good enough results from the CT.
I also use the CT to generate a square wave to the line frequency to calculate the alternator rpm.

I had the Ct on my mains line to test it out on a known frequency and consumption and all works very well so far.

The problem with the meters is they are often not in the best location to record data from and then there is the problem with using a CT that it needs to be placed around the main neutral line so it will read all phases and all power used.

The CT is read with a opamp and 08m and my data is logged to a 12v computer that dose all the number crunching down to what ever decimal point you want.
I think there will be errors in any system but they will average out, and any log of power useage is far better than none at all.

MartinM57
29-03-2010, 16:47
The easy solution is to put the project on hold till the 18mx2 hits the market as a multi tasking chip would do this job nicely.Interesting. Where have you found what the multi-tasking abilities of the 18M2 are (and any limitations from what an ideal multi-tasking environment might be considered to have)?

hippy
29-03-2010, 17:37
@ bpowell : I've had a better look at the code and it's far too complicated for me to work through so I expect that is maybe where the problem lies.

I think you need to greatly simplify what you have. Don't worry about lack of pulse timeouts to start with, have something simple which interrupts, records elapsed time, resets the timer and returns. Set a flag to say new data is ready, print out the recorded elapsed time.

I'd even go as far as saying drop the sensor and use a push button to get it all to work to start with. The following is what I'd start with and should work with either a button or your sensor to Pin 2 ( leg 5 ) of an 08M so should be compatible with your hardware. It looks for a rising edge interrupt to record elapsed time, ignores the falling edge though that is still handled through the interrupt. That can be changed to work the otehr way if needs be. It's not perfect, can lose up to 5ms on every interrupt and isn't a calibrated time loop but a good place to start -



#Picaxe 08M
#Terminal 4800

Symbol elapsedTime = w0 ' b1:b0
Symbol recordedTime = w1 ' b3:b2
Symbol interruptLevel = b4

interruptLevel = %000100
SetInt interruptLevel, %00100

Do
Do
Pause 5
elapsedTime = elapsedTime + 5
Loop Until recordedTime <> 0
SerTxd( "Interval = ", #recordedTime, "ms", CR, LF)
recordedTime = 0
Loop

Interrupt:
If interruptLevel <> 0 Then
recordedTime = elapsedTime
elapsedTime = 0
End If
interruptLevel = interruptLevel ^ %00100
SetInt interruptLevel, %00100
Return

bpowell
29-03-2010, 20:09
@Hippy:

Wow! Very nice (and efficent code!) I'll download that tonight and do some playing! Thank you!

Taking an objective look, I can see how my program was a little elaborate...first things first; get it working!

I do have a question in your code though...maybe you can help me?

First you set the interrupt up:
interruptLevel = %000100
SetInt interruptLevel, %00100

So, if I'm reading this right, pin 2 will interrupt if it goes high.

Then, in the interrupt you have:
interruptLevel = interruptLevel ^ %00100
SetInt interruptLevel, %00100

Oh wait...I think I just figured it out while I typed...however, in the interest of full disclosure, I'll not delete my question, but explain what I think the answer is:

You are flipping the interruptLevel from 1 to 0 (so every other interrupt will be on the signal going positive...and only the positive interrupts are the ones the program uses to calculate duration. The level then gets flipped from 0 to 1 on the next pass.

The XOR threw me for a bit, but as I walked through it (3rd or 4th time) I got it!

Thanks Hippy and everyboty else! I'm new to this stuff, but it's sure a lot of fun to learn!

Brendan

hippy
29-03-2010, 23:52
Yes - Spot on with the toggling of interrupt level ...

SetInt %00100, %00100 to look for a high, then
SetInt %00000, %00100 to look for the low, then repeats forever

davidwf
26-10-2011, 01:02
As the nights are getting longer again so my thoughts are turning to digging out the PICAXE stuff :rolleyes: ...... anyone progressed with this and got a working design up and running yet ?

Azza
28-10-2011, 12:43
I just came across your post, I have a completed and working Electricity Monitor, it uses a Picaxe 20x2 and results are sent by wireless (xbee) to my server. I have also just completed a stand alone receiver for the electricity monitor using Maximite and Xbee. Details of both these projects are available on my web page http://codenquilts.com.au/?page_id=97

Mike.

davidwf
28-10-2011, 13:14
Azza, thanks for that....looks very interesting :)