Hello,
I want to use a bit mask on a register in a IF to check some conditions.. Do you know if it is possible to do that in a TP program or should I need to call Karel ?
Hello,
I want to use a bit mask on a register in a IF to check some conditions.. Do you know if it is possible to do that in a TP program or should I need to call Karel ?
There is no bitwise functions that I am aware of in TP.
What is the purpose you you wanting to do this? We may be able to help you find a different solution.
You can do it in KAREL
What is the purpose you you wanting to do this? We may be able to help you find a different solution.
I have a register, R[200] in which I set alarms.
Then I use this register to find which alarms are activated.
When R[200] == 1, I want to call a sub-program to display a notification.
When R[200] == 2 (10), I want to stop the program
When R[200] == 3 (11), I want to stop the program
In my program I will write something like below:
I don't know if it's really clear..
If the previous code doesn't work I think it will be possible to use the operator DIV and MOD to check if a bit is set !
R[1] = R[200] DIV 2
R[1] = R[1] MOD 2
IF R[1] == 0 => bit 2 is equal to 0
IF R[1] == 1 => bit 2 is equal to 1
I am going to try that
Hi
Somewhere in your program you set R200 to a value, lets say R[200]=1
Then, somewhere else you ask the questions about the value of R200
IF R[200] = 1 , JMP LBL (30)
IF R[200] =2 , JMP LBL (33)
So, in LBL(33) you do something and from there you go home or jump back to other part of the program
If you want to stop the program you could
LBL 11
!Stop program
!Wait R111= 999
You program will wait forever until an arbitrary register = 999 or you can wait for an input that you will never use OR send an output to the PLC to stop you
Your program is only hard if the system can have multiple alarms at once. If this is the case then you could just do the following:
IF R[200] >= 8 THEN
R[200]=R[200]-8
CALL WORST_THING_POSSIBLE
END IF
IF R[200] >=4 THEN
R[200]=R[200]-4
CALL REALLY_BAD_THING
END IF
IF R[200] >= 2 THEN
R[200]=R[200]-2
CALL WORSE_THING
END IF
IF R[200] >= 1 THEN
R[200]=R[200]-1
CALL BAD_THING
END IF
Display More
At the start of your program you would need to set R[200]=0. Then when ever a new alarm is added it would be R[200]=R[200]+Current alarm number
A few other options to consider that may be easier for other people to read and troubleshoot your code.
Option 1: is to use Group Outputs. A group output creates an integer, up to 16 bits. You can map the same bits to DO's or Flags. Then you have the option to look at each bit or the total integer value.
Option 2: Forget using integers or registers. Instead just reserve a block of Flags or DO's (boolean IO type). Each flag represents 1 alarm and can be set or examined independently. If you wanted to scan through all of them you could do so with a For Loop, or an incrementing BG Logic program.
My honest opinion is that using individual Flags or DO's would be much easier for another programmer to make sense of then to come up with a complex round-a-bout bitmask operation.
Thank you for your feedback, I will consider these options