Help with simple FB

mehrab
2014-06-02
2024-10-22
  • mehrab - 2014-06-02

    This I'm thinking is supposed to be a simple Function Block but I can't seem to get it

    What I'm trying to do.

    If Input 1 = high then output = 5000
    if Input 2 = high then output = 5001

    VAR_INPUT
    IN1:BOOL;
    IN2:BOOL;
    END_VAR
    VAR_OUTPUT
    OUT: INT;
    END_VAR
    VAR

    The code I've written:

    ==============
    IF IN1 THEN;
    OUT := 5000;
    ELSE
    IN2 := TRUE THEN;
    OUT:= 5001;
    END_IF
    ==============

    I keep getting a Error 4024: Error1 (5) Expecting";" or ":=" before 'THEN'

    (I've highlighted the affected line in red)

    I've tried a few different things but it's still not compiling
    I know I'm writing it wrong, just need some help please.

    What I'm ultimately trying to do is write a value from 5000 to 5200 to a memory word (%QW441)
    My HMI then will read those codes and depending on what the value is will display a different fault on the screen.

    This is my first time using codesys so any help would be greatly appreciated.
    Thanks in advance

     
  • t.lundahl - 2014-06-02

    Hi!

    If you want the OUT:=5001 only if IN2 is TRUE and not everytime the IN1 in FALSE then
    use:

    Remove the (;) after THEN

    ELSIF IN2 THEN (:= TRUE, not needed)

    /TorbjΓΆrn

     
  • mehrab - 2014-06-02

    Hey
    Thanks for the reply,

    I'm realizing this might not be the best way to do this.

    What I'm trying to do is create fault messages.
    If an alarm is triggered it'll display a fault on the screen.

    All of my faults right now are grouped in 10's.. I was going to send a value to a word and have the HMI read the values and display its corresponding message.

    I'm realizing that's not working very well because if more then one fault from one group is generated, by the time the scan is complete, the word only has one value in it.. so the HMI misses the other faults.

    Is there a better way to do this?
    As of now I'm going to create a ladder program with individual alarms coiled to individual bits..

    I'm hoping to find a more effective way to do this.

    Thanks

     
  • t.lundahl - 2014-06-02

    Hi!

    What you can do, for each alarm:

    IF IN1 AND NOT Alarm1 THEN
    Alarm1 := TRUE;
    END_IF;

    IF Reset THEN
    Alarm1:=FALSE;
    END_IF;

     
  • mehrab - 2014-06-02

    t.lundahl hat geschrieben:
    Hi!
    What you can do, for each alarm:
    IF IN1 AND NOT Alarm1 THEN
    Alarm1 := TRUE;
    END_IF;
    IF Reset THEN
    Alarm1:=FALSE;
    END_IF;

    See if I do it this way, there will be values written to the word that might not get scanned

    let's say I have 4 inputs, IN1, IN2, IN3, IN4.
    My output is Alarm = INT
    Values are: 5000, 5001, 5002, 5003

    Here's what I'm afraid of.. say IN1, IN2, IN3 are on..
    the block will push values, 5000, 5001 and 5002 to the Alarm output
    during the scan, it'll only scan what's in the memory of that output.. in this case, the last value which is 5002.. so my HMI will only display the corresponding message.. and the user will not know that alarms 1 and 2 were even on..
    They may proceed to repair the third alarm, hit reset, then of course it'll scan again displaying the 2nd alarm, repair that and then repair alarm 1.. it's inefficient.

    I have a ladder logic now with all alarms going to single bits.. and the HMI reading those.. individually. Looking for ways to not do it that way.

     
  • t.lundahl - 2014-06-03

    Try this small change.

    IF IN1 AND NOT Alarm.1 THEN
    Alarm.1 := TRUE; (Secondbit in AlarmRegister)
    END_IF;

    Also make it as Functionblock to add to your ladder.

     
  • shooter - 2014-06-06

    mr lundahl does not explain what he does:

    You want to see each alarm, so each alarm has a unique code.
    alarm1 is 1
    alarm2 is 2
    alarm3 is 4
    alarm4 is 8 etc.
    example
    alarm2 and 3 are active.

    for a is alarm1 to alarmx
    hmicode is hmicode +2 sqr(a);
    this way you can put 16 alarms in one WORD.

    or
    hmicode=0
    if alarm1 then hmicode=hmicode+1;
    if alarm2 then hmicode=hmicode+2;
    etc.

     

Log in to post a comment.