Page 1 of 1

Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 3:22 pm
by acestu
Hi Fellas,

I am just trying to put a little program together that will monitor the power to a mains pump, I have the signal conversion sorted from the pump with an opto isolator which is connected to pin A0, however when I run the simulation nothing happens, I have tried to follow the chart and it should call the fault macro but it does not.
power_monitor.fcf
(17 KiB) Downloaded 218 times
Any help would be appreciated.

thanks in advance
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 4:32 pm
by medelec35
Hi Acestu,
Problem is with you decision Icon.
Instead of
STATE <= 0
(<= means less or = )
So it will never see logic1
and you cant get less than 0 with bytes.

You can have
STATE > 0
or
STATE
or
STATE =1

When you alter to one of the above your Flowchart should work.

Martin

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 5:45 pm
by acestu
Hi Martin,

Thanks for that, I am a bit confused today with all that is going on, I will have another go now.


Cheers
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 5:57 pm
by acestu
Hi Martin,

I have tried and it still does not want to work, I am assuming that if my switch is down (on) that it is supplying a value of 1 at the input pin B0, therefore if the switch is switched off then 0 is supplied to the pin B0(power failure) so the calculation must ask if the input pin B0 equals 0, which would be:

if STATE = 0


Or am I wrong :oops:
power_monitor.fcf
(17 KiB) Downloaded 211 times
thanks
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 6:11 pm
by medelec35
ah sorry you are correct. I misread :oops:
I was thinking if logic or voltage at input is high = +5V then go into macro, as that's what i usually do
If the other way around then you are correct the two that will work are:

if STATE = 0
or
if STATE <1

Martin

Attached is a correct Flowchart.
I added an input to monitor within your fault Detection macro.

Note it states A0 on your control panel, but I have let flowchart as B0

Martni

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 6:55 pm
by acestu
Hi Martin,

I still don't know what is happening here because it seems to be back to front, as in when I first start the simulation the switch is down thus providing a signal of 1 which should make the LCD say "Healthy Supply" and when you switch the switch off then that is when the fault macro should be called.... does that make sense..


thanks
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 7:15 pm
by medelec35
Hi Acestu,
when the Flowchart is 1st ran, the switch is down = i/p low (or 0V) that is when it reads PSU fault.
When the switch is up = input high (+5) psu is shown as OK
Default switch pos.png
(31.1 KiB) Downloaded 3063 times
If you do not want it as that way around it can be changed.

So if you want to show fault when input is less than 1V the Flowchart is correct way round.

A bit of advice, press F8 to single step and make sure the variables are added to the variables window.

Martin

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 7:27 pm
by acestu
Hi Martin,

What I have done is added an LED to the same port as the toggle switch and it appears that when the switch is down it is actually off and not on as you would think.
power_monitor 3.fcf
(17.5 KiB) Downloaded 230 times
thanks
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 7:49 pm
by acestu
Ok Martin,

I understand it now, in the options for the switch you can swap from active high to active low, I thought this meant that you could toggle the output of the switch between 1 or 0, right I have changed it around a bit and it is working ok now except for when you press the mute sounder button and then reapply the power the delay carries on so do i need to have an interupt in there somewhere ?
power_monitor 4.fcf
(17.5 KiB) Downloaded 227 times
thanks
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 8:12 pm
by medelec35
Edit was typing a reply when a post had be posted. So sorry if repeating?

LED Off when switch is down is correct.
You need to remember that switch is down = 0V = LED off
If switch is up = +5V = LED on

This would be the case if your sourcing LED.
To source LED the output from microcontroller goes via a current limiting resistor to the anode of LED. the cathode of LED is connected to 0V
With Sourcing if ( Active High you can change the switch to from active high to active low via external properties) o/p = +5V = logic1 then current will flow though LED so it will be illuminated.
if o/p = 0V (switch down) then 0v going into LED anode. Since cathode is connected to 0V as well there will be no current flow (anode and cathode are at the same potential) LED will be off.

If your sinking instead (active low) . Then anode of LED will be connected to +5V (via a current limiting resistor). Then if switch is down (0V) the cathode will be pulled down to 0V so LED will be on (there is a potential difference.)
If the switch is up (+5V) , then the cathode will be at the same potential as the anode (+5V) so LED will be off.

I am assuming your sourcing rather than sinking?

If so your flowchart is correct. Switch down = 0v on B0 = power failure.

The flowchart can be changed so if +5 at B0 then power failure is detected.

Martin

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 8:28 pm
by medelec35
Perhaps this will work better. if not, what would like me to change?
I have altered Flowchart so if you press mute after power has failed and alarm is on, then alarm will switch off.

So just to confirm.
Voltage at B0 i/p:
if +5V then alarm = on and power failure indicated.
If 0V then alarm = off and normal supply is indicated.

Martin

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 8:48 pm
by acestu
Hi Martin,

Sorry it is the other way round, when there is power at the pump there is +5volts at B0 and NO fault

When power goes down on the pump B0 is then 0 volts and an alarm is caused,

I wanted to mute the sounder for a set amount of time and keep coming back on as long as the alarm condition was still active, because people tend to just mute the alarm and it is forgotten about, is this possible by interrupting the delay and returning to the main part of the program ?

thanks
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 10:00 pm
by medelec35
Hi acestu,
I have altered flowchart so the mute seconds can be set from 0 to 65535.
When power is restored,delay is canceled.
Also if switch is up then that means power is detected on B0.
If switch is down then no power is detected on B0
Simulator is working just fine.

Martin

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 10:24 pm
by acestu
Hi Martin,

Sorry for being a pain but I can,t get this simulation to work, when you run the simulation you can toggle the switch as many times as you like and all is ok

But when you cause an alarm, press the mute button, then toggle the power back on and off again the sounder LED does not light, it sort of dosen't reset
after power is restored to B0.

thanks
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 10:37 pm
by medelec35
Ah sorry I though you meant power supply to microcontroller not B0
I have sorted that out for you as well.

I don't think your a pain at all!

I did say for you to mention if not working the way you would like it to, I would then modify flowchart.

Can you please try attached version.

Martin

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 10:55 pm
by acestu
Hi Martin,

I have just tried the new code and changed the mute time to 5 seconds for testing purposes but when I try it and press the mute button the sounder light goes off but it never comes back on again..sorry..


thanks
Acestu

Re: Help with Power Monitor Please !

Posted: Sun Feb 17, 2013 11:21 pm
by medelec35
Hi acestu,
Have you taken into account that simulation time for timer interrupts is much much slower than real time (its is dependent on PC speed as well)

Simulator is working for me. On my PC 5 seconds of simulation time takes 1 min & 42 seconds. Slower PC's will take longer.
My advice is change the simulation time to 1 second and see how long it takes for LED to light back up.
When uploaded to real hardware, MuteSeconds = 5 will only take 5 seconds (even though it took nearly 2 mins on the simulator).

Martin

Re: Help with Power Monitor Please !

Posted: Mon Feb 18, 2013 12:35 am
by acestu
Hi Martin,

Thanks for that, I thought about that but I didn't realize it took so long, i set to 5 seconds and counted to to about 130 seconds, I must of just missed it.

That's brilliant, I will try and figure out how you have done it now, it looks quite complicated...

cheers
Acestu :D

Re: Help with Power Monitor Please !

Posted: Mon Feb 18, 2013 8:54 am
by medelec35
Your welcome.
acestu wrote:I will try and figure out how you have done it now, it looks quite complicated...
I was struggling to concentrate as Mrs was talking to me at the same time :roll:
So there maybe a easier way of doing this?

Martin