Switching off power by means of KWH Meter pulses

Satchid

Member
Dear all,

I have a 48V battery with a battery charger. The battery charger has an internal fan that continues turning after the battery is fully charged.

I am looking for a system to switch the power off after my battery is full.

Now between the power outlet and the charger I have a KWH meter that delivers 1600 pulses per KWH. Also there is a red LED that flashes at the same rate.

When the battery is full, there is still a pulse every 45 seconds.

So I would like to stop the power to the charger about 10 minutes or so after the pulse interval is 45 seconds.

I would like to put a relay between the KWH meter and the charger to disconnect the charger from the power.

What would be the best way to proceed?

Greetings,

Willy
 

hippy

Technical Support
Staff member
Wait for a pulse, time until the next pulse, if less than 45 seconds, repeat that. Otherwise wait 10 minutes and turn the fan off.

The PICAXE M2 series have a 'time' variable which increments every second or so which may prove useful. Something like -

Code:
#Picaxe 18M2

Symbol PULSE   = pinC.0      ; Pin the pulse will appear on
Symbol PRESENT = 1           ; Level of pulse when present

Symbol ABSENT  = PRESENT ^ 1 ; Level of pulse when absent

; Wait for pulses to be more than 44 seconds apart
Do
  Do : Loop Until PULSE Is ABSENT
  Do : Loop Until PULSE Is PRESENT
  time = 0
  Do : Loop Until PULSE Is ABSENT
  Do : Loop Until PULSE Is PRESENT Or time >= 45
Loop while time < 45
; Wait 10 minutes ( 600 seconds )
time = 0
Do : Loop until time >= 600
; Turn the fan off
 

Jeremy Harris

Senior Member
If you wanted more data, then there is a fair chance that the energy meter you have also outputs data via an IrDA port. I'm reading data from an Elster A100C meter, using the information on this web site: http://www.rotwang.co.uk/projects/meter.html It works fine with a Picaxe, and I relay serial data to another unit, where I can use it to control loads etc, based on the energy import/export at any instant.
 

rossko57

Senior Member
Wait for a pulse, time until the next pulse, if less than 45 seconds, repeat that. Otherwise wait 10 minutes and turn the fan off.
The same thing, presented in a different way...
Set up a timer to turn off in ten minutes time.
Now check for a pulse.
Then time till the next pulse.
If less than 45 seconds, go back to beginning (resetting to another ten minutes from now.)
 

Pongo

Senior Member
Why not use count?

Code:
setfreq m4
Start:
count C.1, 40000, w1 'count pulses on C.1 for 40 seconds
If w1 < 2 Then         
	Goto tenmin
End If	
Goto Start
tenmin:
Sleep 261 '261 x 2.3 = 600.3 seconds
'turn power off
Syntax checked, not tested.
 
Last edited:

Satchid

Member
I played with the easyest first.
Pongo,
if i run the program as is in picaxe editor, then w1 emediatly becomes 32000. It is also doing that when i take the sampel program from the count in the tutorial.pdf.
Is that because it is in simulation?

Thank you,
Willy
 

Satchid

Member
Hi Hippy, Thanks
I do not understand the program. I see in simulation that the program proseed 1 line on pin C.0 is going from 0 to 1. Then another line if pin C.0 is going from 1 to 0.
Then the time variable is set to 0. and then the program is doing the another 1 line by positive going pin and negative going pin. But, it needs a puls for the program to continu. As far as I can see it is not looping for 45 seconds. But maybe this needs a real picaxe?

But I am sure i do not understand wat you are doing.
Thank you,
Willy
 

Satchid

Member
I found it now, it is indeed not posibel in simulator. tomorow i wil try to load it in a picaxe.
Thank you all.
Willy
 

Satchid

Member
Hi Pongo et all,
This is your program (below) set-up to my needs and tested (at least with a LED) on a real picaxe on a axe117 board.

Now how making shure the relay is closed when the cable is connected?
Here is the situation:

I have the electricity coming in a KWH meter.

I will use an electronic relay to switch the power cord, between the KWH meter and the charger, on or off as commanded by port B.5 on the picaxe.

The battery charger ais build-in an Electric Vehicle, therefore will be plugged and unplugged regularly. It is absolutely necessary to make sure that the battery starts charging after plug in.

How can I make that the charger has power at the moment that I plug-in the cable again?

I do not want to use a limit switch of any kind, they evidentially brake down. Could i use a second Picaxe and how should I detect that the cable wants to supply current?

I hope this is clear?

Thank you,

Willy

main:

low B.4 ; I have put a test LED between B.5 and (low) B.4, power to the picaxe = 3V.
high B.5 ;initial start the charger responding in x'
Sleep 5 ; wait for charger start up
start:
count C.0, 40000, w1 ;count pulses on C.0 for 40".
if w1 <= 2 then ;if there are les that 2 pulse in 40" then battery is full and stop charger
goto stop_charger
end if
high B.5 ;start charger charging
goto start

stop_charger:
Sleep 5 ;switch of after xxx minutes(2.3x10000)"

low B.5 ;stop charger

goto start


end
 

rossko57

Senior Member
The battery charger ais build-in an Electric Vehicle, therefore will be plugged and unplugged regularly. It is absolutely necessary to make sure that the battery starts charging after plug in.
I'm not sure if you want to detect when mains is applied to the charger, or detect when the battery is connected to the charger (so you can then activate the relay and charger).
Where is the Picaxe powered from?
Guessing the Picaxe is sited, along with the kwh meter and the relay, off the vehicle? Also the charger is on the vehicle, and plugged in when required?

I don't see why you wouldn't use a switch to detect the plug; it's not going to be any less reliable than the relay switching the actual load. You don't have to switch the load with it, just use it to signal the Picaxe to control the relay. A little cleverness perhaps, like waiting for a few seconds (to allow the plug to be fitted properly) before relay on.
 

Pongo

Senior Member
I'm not sure if you want to detect when mains is applied to the charger, or detect when the battery is connected to the charger (so you can then activate the relay and charger).
As I read it, the charger is built into the vehicle, and the operator connects an AC mains power cord to charge the battery. So Satchid wants to detect the operator connecting the charger, and then connect the AC to it via the picaxe controlled relay. I don't see how to do that without some kind of plug detecting switch or push button either, except for solutions that involve a connection to the AC line and I'm not going there ;)
 

Satchid

Member
Dear Rossko57, Pongo et all,
Thank you for asking, I did not know what more to say.
Yes, the Picaxe is sited, along with the kWh meter and the relay, off the vehicle. The charger is on the vehicle, and plugged in to the mains when required.


The picaxe, the kWh meter and the relay are a distance away from the plug, so a sensor switch would be difficult.

While I was writing this, I was thinking of a resistor across the contacts of the relay, there would be no voltage when the cable is unplugged. With some electronics it can send a signal to sensing picaxe that on his turn activate the switching picaxe.

But: how to program the second picaxe because when the switching picaxe activate, the contacts close and there will be also no voltage across the relay contacts.
Pongo, It can be connected via an optocoupler to the picaxe.


Or can it be done with only one picaxe? I am using a 14m2.

Thank you,

Willy
 
Last edited:

Satchid

Member
hi
Conserni
I have a question,
If a picaxe in sleepmode, let is say sleep period, How can the picaxe wakend before the end of the period by means of an input from an input pin?

Thanks

Willy
 

hippy

Technical Support
Staff member
If a picaxe in sleepmode, let is say sleep period, How can the picaxe wakend before the end of the period by means of an input from an input pin?
If using an X2 you can use "SLEEP 0" and have a HINTx pin wake the PICAXE from sleep. Otherwise I don't recall there is any way to wake from SLEEP.

You could use shorter NAP commands and then decide whether to NAP again or continue the program by polling an input pin.
 

Satchid

Member
Hi Hippy et all,
I am trying to use the time command to time the few minutes before switching off.
I include also a line to detect if the cable is plugged in (before the loop comand at the end)

The sintax is ok, but is the logic solid? Could somebody please check this?
To test if the cable is connected, I will place a small transformer 220:5 over the relay contacts. and derive a 5volt dc from that to set C.2
There will only be 220 volt over the contacts if the power is connected to the charger wile also if the contacts are open.

Code:
main:

	low B.4 ;0 volt from test LED on B.5
	high B.5 	;initial start the charger responding in 2'(close the contacts 
	;Sleep 5   ; wait for charger startup  
start:
	count C.0, 40000, w1   ;count pulses on C.0 for 40".
  if w1 <= 2 then       ;if there are les that 2 pulse in 40" then goto stop charger
	goto stop_charger
  end if
	high B.5 		    ;start power to charger (close relay)
	goto start

stop_charger:
let w0 = 0
let w0 = time + 10  ;10 seconds delay befor "low B.5" relay is opend

do
  if time > w0 then 


    low B.5
    end if
if pinC.2 = 1 then goto start   ;if cable is connected then go to start.

loop
 
Last edited:

lbenson

Senior Member
In "stop_charger", "let w0 = 0" has no significance, since w0 is set again in the next line.

In that line, if the value of time is such that adding 10 to it will cause it to overflow, then it will wrap around to a value between 0 and 9, and the "if time > w0" test will immediately be true.

If when posting you enclose your code between "[ code]" and "[ /code]" (without the spaces), then any formatting (indentation) will show, and your code will be easier to read.
 

hippy

Technical Support
Staff member
Don't know about the rest of the logic but ...

let w0 = time + 10
if time > w0 then

Will not work as expected if 'time' has a value of 65525 seconds or more. It would be better to reset 'time' to zero then check for 'time > 10'.

You would really need to post a block diagram of your set-up showing all power and signal connections for anyone else to determine if the rest of the logic were correct.
 

Satchid

Member
Hippy & Ibenson
Is this what you mean, is the position of the time reset to 0 (let time = 0) ok?

Code:
main:

	low B.4 ;0 volt from test LED on B.5
	high B.5 	;initial start the charger responding in 2'(close the contacts 
	;Sleep 5   ; wait for charger startup  
start:
	count C.0, 40000, w1   ;count pulses on C.0 for 40".
  if w1 <= 2 then       ;if there are les that 2 pulse in 40" then goto stop charger
	goto stop_charger
  end if
	high B.5 		    ;start charger charging 	
	goto start

stop_charger:
 

let w0 = time
let w0 = time + 10  ;delay befor relay is open

do
let time = 0	
  if time > w0 then 
    low B.5
    end if
if pinC.2 = 1 then goto start   ;if cable is connected then go to start.

loop
 

hippy

Technical Support
Staff member
reset 'time' to zero then check for 'time > 10' ...

Code:
time = 0
do
  if time > 10 then
 

Satchid

Member
Hi,
I have loaded the program to an 14m2 at 4Mhz.

After upload it starts normally, there is no no pulses at the C.0 input pin. After a wile, B.5 is going low as expected. Then it is in the do-loop.
If I now make High C.2, the program is starting again from main.
This is doing it time and again
But when I leave this wait for a few hours before i activate C.2, then B.5 is high and stays high, meaning the program is not working animore.

What could could be done?
Thanks.

Code:
main:
	low B.4 ;0 volt from test LED on B.5
	high B.5 	;initial start the charger responding in 2'(close the contacts 
	Low B.3
	goto start

start:
	count C.0, 40000, w1   ;count pulses on C.0 for 40".
  if w1 <= 2 then       ;if there are les that 2 pulse in 40" then goto stop charger
	goto stop_charger
  end if
	high B.5 		    ;start charger charging 	
	goto start

stop_charger:
 let w0 = time + 10  ;delay befor relay is open
time = 0
do	
 if time > w0 then   ;if time > w0 then is juist en moet command vervangen
    low B.5
    high B.3
    end if
 if pinC.2 = 1 then goto main:   ;if cable is connected then go to start.
loop
 
Last edited:

hippy

Technical Support
Staff member
Code:
time = 0
do	
 if time > w0 then
As previously stated, that should be ...

Code:
time = 0
do	
 if time > [b]10[/b] then
 

Satchid

Member
Thank you Hippy, Of caorse, it works now.
I would like to know what the reasoning behind this is so that next time I can find the solution myselve.

Greetings,
Willy
 

rossko57

Senior Member
In BASIC programming, things happen in sequence:

let w0 = time + 10 ;delay before relay is open
time = 0

Shortly AFTER setting w0 to a value based on the current value of 'time', you reset 'time' to zero. There is no longer any relationship between w0 and the new value of time.

time = 0
let w0 = time + 10 ;delay before relay is open

That would work better, with w0 getting set to +10 "in the future" of 'time'.
But you already know that 'time' is zero, you just made it so. It follows that w0 is always going to be 10 (except in the very occasional case where 'time' moves on a tick between the BASIC instructions). No point calculating 0 + 10, you already know it will be 10.

time = 0
let w0 = 10 ;delay before relay is open

This version would work just as well.

And then if you consider, you don't use w0 for anything other than the comparison - you might as well simply put 10 directly into the comparison, and not use w0 at all. That makes your program simpler.
 
Top