Word changing... bit 3s up

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
How can I program this:

I have 16 alarms in a word. When a there is an alarm, I want to detect this, so I compare it with zero. When there is a second alarm coming up (I'm not interested in what alarm) I compare it with the previous value, but that's only 2 alarms,

What I need is: everytime there is a change in the alarmword, I need to set an alarm (horn) when hitting reset, the horns stops,but is active for other alarms...

what do u think ...
 
Make a tag for Previous Alarm.

If Current Alarm value is greater than Previous Alarm value then trigger horn and move Current Alarm to Previous Alarm. This will cover new alarms being triggered because each additional alarm will increase the value of the word

If Current Alarm value is less than Previous Alarm value then move Current Alarm to Previous Alarm. This will cover alarms being turned off and will ignore them

You didn't mention the PLC so can't give a specific example but this should work for pretty much any PLC
 
hey

s7-315-dp plc

This is what I have now, since we all speak code language
L #WZI_1
L 0
>I
= #AL_1

A #AL_1
FP #MEM_1
JCN X1_1
L #WZI_1
T #PREV_1
X1_1: A #AL_1
JCN X1_2
L #PREV_1
L #WZI_1

= #AL1_2
X1_2: JC ALA2
 
Last edited:
Code:
	  L	 MW	 0					// current alarm status
	  L	 MW	 2					// last alarm scan
	  XOW							   // find bits that changed
	  L	 MW	 0
	  T	 MW	 2
	  AW								// get only bits that are ON
	  T	 MW	 4					// New alarms

presuming S7 as previous
 
PeterW rules!

The code by PeterW is the way to go, just keep in mind that MW4 only holds its 'new alarm' value during 1 scan cycle. So, set an alarm bit (to drive the buzzer) whenever the value in MW4 is not zero, something like this:

L MW4
L 0
<> I
S #ALARM

Not quite sure, but I don't think you can use "> I" because b15 is also used as an alarm bit (1000 0000 0000 0000 equals -32768).
 
Combo said:
Can u explain a little more, because I don't understand Peter his code

The code is treating all 16 bits at one time and sparkz is correct the bits are only on for one scan.

If I have a bit of time later I will write the full code (I used it before for latching unacknowledged alarms, 16 bits at a time).

I will also write the single bit ladder equivalent.

I think if you can see the ladder (single bit) and understand that then the multiple operation will become self evident.

I'm a bit busy now, so hopefully I should be able to do it later, unless someone else does it first of course.
 
A couple of questions - do you want to detect a new event after an existing event has been evaluated ? and if so , are you holding these alarm words in a DB ? do have have space to add two more identical DB's or extend the existing DB ?
 
hi

ALA3: L MW 30 // current alarm status
L MW 2 // last alarm scan
XOW // find bits that changed
L MW 30
T MW 2
AW // get only bits that are ON
T MW 4 // New alarms

L MW 4
L 0
<>I
FP M 40.0
JCN res
S M 90.0

res: A I 0.0
R M 90.0

this works, but not for all bits ??
 
MW0 is the alarm word you wanted to check for changes.

MW2 is a 'previous scan' memory word, which holds the value the alarm word had during the previous scan cycle.

Both 'new alarm word' MW0 and 'previous alarm word' MW2 are pushed through an EXOR (exclusive OR) function. The result contains ALL changes (0 -> 1 but also 1 -> 0) in the alarm word since the previous scan. This result is later being compared (AND function) to the 'new alarm word' MW0 to filter out the newly activated alarm bits.

MW4 will hold these alarm bits that became active since the previous scan cycle, but only for 1 scan cycle.

Check for any change of MW4 to set an 'new active alarm' bit.


ALA3: L MW 30 // current alarm status
L MW 2 // last alarm scan
XOW // find bits that changed
L MW 30
T MW 2
AW // get only bits that are ON
T MW 4 // New alarms

L MW 4
L 0
<>I
S M 90.0 // No need for a FP function! MW4 will only hold its new value for just 1 scan cycle

res: A I 0.0 // M90.0 remains active until you reset it manually by I0.0
R M 90.0

Added: Yes, it does work for all 16 bits in the alarm word.

Added: Of course, you don't really need to store the new alarm bits. Just to save memory space, the 'T MW4' and the 'L MW4' commands can be removed.
 
Last edited:
Hey

The code works, but still have a problem understanding it..., damn, maybe I understand, let me explain it how I see it:

Exor:
0 0 = 0
1 0 = 1
0 1 = 1
1 1 = 0
So u Exor the bits of the previous cycle with MW30. MW2 is previous cycle data because u wrote the value of MW30 in it a bit further in this code, but the program flow sees the previous cycle of MW2. So after understanding that, the xor now:

Let us say MW30 is 0000_1001_1000_0000
And the previous cycle was 0000_1001_0000_0000
After the XOR we get --> 0000_0000_1000_0000

So there is one bit changed between the previous cycle and the current.

Now we transfer 0000_1001_1000_0000 to MW2 for detection in the next cycle.
Now we do And-Word of the Changed bits and the current word:

0000_0000_1000_0000
0000_1001_1000_0000

this gives us:

0000_0000_1000_0000

And it is indeed not zero for one CYCLE...





ALA3: L MW 30
L MW 2
XOW
L MW 30
T MW 2
AW
T MW 4
L 0
<>I
S M 90.0
res: A I 0.0
R M 90.0


I think I understood, great peace of code, thanks, is my thinking correct ?
 
Knew you could do it...

Yep, you got it!

But just to make sure, you can't use #TEMP variables (you know, values of temporary variables are undefined at beginning of every cycle...)
 

Similar Topics

Hi all, i have a panelview plus terminal 2711P-T12W22D9P terminal with different user names and passwords. Everyone seems to know the maintenance...
Replies
3
Views
805
I have been asked to find out if there is a way to change the different user passwords for the HMI through the PLC. We use FactoryTalk View Studio...
Replies
12
Views
3,577
Hello. I have not found any documentation on this matter. I want the user to be able to change their password back to a previously used...
Replies
3
Views
1,888
hi, Is there a way to choose with %MW you use depending on the value of %SW49? For example, i have 7 %MW: -%MW4 that needs to be active when %SW49...
Replies
0
Views
1,201
Hi, I am using FactoryTalk View v6.10 and I am updating from an old PV1000 (with panel builder 32) to a new PV Plus 1250. The old project had a...
Replies
3
Views
1,603
Back
Top Bottom