loki1976

If Else or Similar

6 posts in this topic

Hi all, I have 3 values set that I want to show different lamps for

1 K2000

2 K2500

And data coming from a pressure transducer < this is the actual value to compare to.

Anything above 2500 should be green light

Anything between 2500 & 2000 should be amber light

Anything below 2000 should be a red light.

 

I have attached what I have so far, but I cant get my head around the above problem. I might add I am a newbie to plc but enjoying them so far. This site has helped me greatly so far so thought I would come and ask  my 1st question

MAIN.csv

Share this post


Link to post
Share on other sites

You need to do inline comparisons. LD <= D0 k1999 ----red Lamp

Then 2 inline compares. First equal or greater than K2000 then equal or less than K2499 ----amber lamp

Then of course equal or greater than K2500 ---- green lamp 

1 person likes this

Share this post


Link to post
Share on other sites

// Green light
IF wValue > 2499 THEN
    bGreen := TRUE;
    ELSE
    bGreen := FALSE;
END_IF;

// Amber light
IF wValue >= 2000 AND wValue <= 2499 THEN
    bAmber := TRUE;
    ELSE
    bAmber := FALSE;
END_IF;

// Red light
IF wValue < 2000 THEN
    bRed := TRUE;
    ELSE
    bRed := FALSE;
END_IF;

Edited by GreenMan

Share this post


Link to post
Share on other sites

bGreen := wValue > 2500;

bRed = wValue < 2000;

bAmber := NOT bGreen AND NOT bRed;

2 people like this

Share this post


Link to post
Share on other sites

Thank you for your replies, The sample above is ST correct?

 

 

Share this post


Link to post
Share on other sites

Hi

It is correct except Nightfly is missin a : in the second line. This fault will give an error.

My suggestion is not correct compared to your description. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now