ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#188 - 02/05/03 05:39 AM Use of BECOMES
Brian Raynor Offline
addict
*****

Registered: 01/09/03
Posts: 454
Loc: Columbia, SC
Quick question regarding the use of BECOMES in CMAX.

Consider the following code:

[CODE]IF Variable1 becomes NOT = 0
THEN Variable2 = 1
ELSE Variable2 = 0

IF X10-A1, ON Command Pair
THEN Variable1 = 1

IF Variable1 becomes NOT = 0
THEN Variable3 = 1
ELSE Variable3 = 0[/CODE]Assuming before the program ran that Variable2 and Variable3 were both equal to 0, then what is the value of Variable2 and Variable3 after A1 ON is received?

Question has to do with when is BECOMES evaluated? I would assume that a BECOMES is only evaluated based on what happened the previous loop. Thus, I would suspect that in this case the following would be the result:

Variable2 = 0
Variable3 = 1

Is this correct? If this is so then it is VERY important where you put your BECOMES in a program...

Another thought would be that both would come back set to 1, because CMAX might be smart enough to know that the first time I check the value of something after it changed (regardless of whether or not it was in the same program loop or the next) BECOMES would be true in this case.

How is this supposed to work? I'm about to try it in CMAX, but just wanted to make sure what the expected behavior is...

---

One other question... Consider the following

[CODE]IF Variable1 = 1
THEN Variable1 = 1

IF Variable1 becomes = 1
THEN Variable2 = 1
ELSE Variable2 = 0[/CODE]Worthless code I know... However, what would be the value of Variable2, assuming Variable1 = 1 when the program started??

Question goes to whether or not setting a variable to a value it is already set at actually triggers "becomes =".

My assumption is that Variable2 should be = 0. Just want to make sure... Will try this as well... In fact I hope this is the case... if not, it will break a lot of things and really makes becomes more or less useless in a lot of cases...

These type of things are very important when writing programs to know.

Thanks for your help!

Top
#189 - 02/05/03 06:08 AM Re: Use of BECOMES
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Ok, I'll bite. It seems to me that I remember something to the effect that a "becomes" is true for one entire loop, meaning that if the variable test becomes true at line 45 in your program, then it will remain true right through to the end of the program and then from the beginning right up until line 44. This is just a vague memory (or maybe a dream I had one stormy night) so it would have to be tested to be sure. If you do test it (as you indicate you will), your test program will very likely show variables 2 and 3 = 0 if you observe them with C-Max because the ELSE statements will be executed every time the "becomes" doesn't test true. You would be better off modifying it like this:

[CODE] IF Variable1 becomes NOT = 0
THEN Variable2 = 1
ELSE Variable2 = 0
IF X10-A1, ON Command Pair
THEN Variable1 = 1
IF Variable1 becomes NOT = 0
THEN Variable3 = 1
ELSE Variable3 = 0

IF Variable2 becomes >0
THEN Variable 4 = Variable 2
IF Variable3 becomes >0
THEN Variable 5 = Variable 3[/CODE]...and observe variables 4 and 5. That way you'll trap any non-zero result that occurs.

For your second question, the value actually has to change. Merely setting it to the same value will not make it "become" that value.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#190 - 02/05/03 02:54 PM Re: Use of BECOMES
dominicv Offline
junior


Registered: 02/01/03
Posts: 49
Loc: Pincourt, Quebec
Good evening guys,

Is there a document that describes C-Max 2.0* commands, and under which context to use them.

I.E. where does one use the commmand (BECOMES) instead (TURNS ON), etc.

Dominic

P.S. Love the forums new looks

Top
#191 - 02/05/03 03:06 PM Re: Use of BECOMES
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
TURNS ON is actually the equivalent of a "becomes" for an input device like a SECU16 input or an X-10 house/unit code. It means when the device, variable, timer, input, etc. goes from not being true to being true, creating a single event which won't trigger again unless it becomes false and then true again.

As we speak, there is not yet a manual describing all the C-Max 2.0 commands but almost all of the commands already existed in previous versions so any documentation describing those will pretty well apply to the 2.0 versions too.

It's a bit dated now but I had prepared this material explaining how many of the commands work and are used:

http://www.hometoys.com/htinews/apr00/articles/lavoie/lavoie.htm
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#192 - 02/05/03 04:05 PM Re: Use of BECOMES
dominicv Offline
junior


Registered: 02/01/03
Posts: 49
Loc: Pincourt, Quebec
Thanks Guy, I will review the article again.

Dominic

Top
#193 - 03/08/03 02:08 PM Re: Use of BECOMES
John Warner Offline
old hand
*****

Registered: 01/09/03
Posts: 834
Loc: Port Perry, Ontario, Canada
Did the Becomes question (as to how long it stays true) ever get resolved?

I'm trying to debug a problem that depends on the answer:

I set a variable to signal my All OFF routine to do an All Off. The code looks like this:

[CODE]IF X10 M/1 OFF Command Palm Pad All Off
OR v18 Becomes = 1 All Off Signalled
THEN Transmit X10 M/All Lights OFF All Units Off
THEN Transmit X10 L/All Lights OFF All units Off
THEN Transmit X10 B/All Lights OFF All units off
THEN Transmit X10 C/All Lights OFF All Units Off

IF X10 M/1 OFF Command Palm Pad All Off
OR v18 Becomes = 1 All Off Signalled
AND v5 = 1 After Dusk?
THEN Transmit X10 K/10 Dim Hall Light
THEN Transmit X10 K/BRIGHT, 16 times Full Bright
THEN Transmit X10 K/DIM, 12 times Dim 12 of 16

IF X10 M/1 OFF Command Palm Pad All Off
OR v18 Becomes = 1 All Off Signalled
AND TimeOfDay < 2330 Before 11:30 PM
AND v5 = 1 After Dusk?
AND v1 = 0 Not gone to bed
THEN X10 Quick On M/2 Kitchen Swag
THEN X10 Quick On M/9 Garage Coach

IF v18 Becomes = 1 All Off signaled
THEN v18=0 Reset after one pass
[/CODE]The All Off (V18 set to 1) can be set from anywhere in the code and happens Both before and after the above code.

This seems to work fine MOST of the time but on two occasions now (after resetting the alarm when it had been tripped), I found V18 left = 1.

How is that possible (I'm on V1.7, so no Skips) if the Becomes remains active for a complete pass?

Top
#194 - 03/08/03 02:19 PM Re: Use of BECOMES
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
I know it lasts for a complete loop, but I don't know exactly how it's implemented. I've been wondering a bit about that because it's not obvious. Here's one theory, what if any program line with a "becomes" comparing a variable memorizes the value of the variable and always compares against that on the next pass, and then saves the current value for the pass after that, etc. then what would happen if during the course of a pass the value is set to 0 and then 1 again by the time it gets back to that line? It "unbacame" and then "became" again... Is that the only line that can set variable 18 to 0?
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#195 - 03/08/03 02:34 PM Re: Use of BECOMES
John Warner Offline
old hand
*****

Registered: 01/09/03
Posts: 834
Loc: Port Perry, Ontario, Canada
That's the only line that sets it to 0 (in an ALL OFF condition at least - the ALL ON condition uses the same variable set to 2 and then to 0).

It IS possible that it could be set to 1 more than once in the same pass - in fact, when I see this condition, it probably DOES get set to 1 at two different spots in the code following the code I showed you.

Something like this:

[CODE]IF v18 Becomes = 1 All Off signaled
THEN v18=0 Reset after one pass
code
code
Then v18 = 1
code
code
Then V18 = 1 [/CODE]Could that be confusing Cmax?

Top
#196 - 03/08/03 05:25 PM Re: Use of BECOMES
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
It could...depending on how they implemented the "becomes" functionality. If its done by always saving the current value and the previous value, and copying the present to the previous whenever it's set in the program (even if it's set to the same thing...) then maybe setting it twice in the same pass could cause a "becomes" that's not one full loop later to miss, since the previous and present value would be the same. Only Dan Smith could really tell us how its implemented.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#197 - 03/08/03 06:18 PM Re: Use of BECOMES
John Warner Offline
old hand
*****

Registered: 01/09/03
Posts: 834
Loc: Port Perry, Ontario, Canada
I did some testing...

This works as expected (V1 stays 0, V2 & V3 & V4 increment with each A/1 code):

[CODE]IF v1 Becomes = 1 (null)
THEN v2=v2+1 (null)
THEN v1=0 (null)

IF X10 A/1 ON Command (null)
THEN v3=v3+1 (null)
THEN v1=1 (null)

IF X10 A/1 ON Command (null)
THEN v4=v4+1 (null)
THEN v1=1 (null)
END OF PROGRAM (null) [/CODE]This does not (V1 and V2 become 1 and stay there, V3 & V4 increment with each A1 code):

[CODE]IF X10 A/1 ON Command (null)
THEN v3=v3+1 (null)
THEN v1=1 (null)

IF v1 Becomes = 1 (null)
THEN v2=v2+1 (null)
THEN v1=0 (null)

IF X10 A/1 ON Command (null)
THEN v4=v4+1 (null)
THEN v1=1 (null)
END OF PROGRAM (null) [/CODE]Becomes apparently behaves differently when the program wraps to the top of the ladder?

Top
#198 - 03/08/03 07:27 PM Re: Use of BECOMES
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Just be careful when you're watching a variable; if it's by using "debug variables and timers" in C-Max, you will get the value at any random point in the loop, so the results can vary from one repeat of the test to another. The same thing happens when a variable is displayed as an embedded variable in a screen text object on a Leopard screen. Test several times...
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#199 - 03/09/03 01:54 PM Re: Use of BECOMES
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Actually, now that I've had time to try it out, your example #2 does work correctly. You have to examine it carefully. Here it is again with line numbers:

0001 IF X10 A/1 ON Command
0002 THEN v3=v3+1
0003 THEN v1=1

0004 IF v1 Becomes = 1
0005 THEN v2=v2+1
0006 THEN v1=0

0007 IF X10 A/1 ON Command
0008 THEN v4=v4+1
0009 THEN v1=1

0010 END OF PROGRAM

When an A/1 On is first received, line 4 will test true and save the present "1" for comparing in the next pass (as I think it does for testing from pass to pass). Line 6 will then reset it to 0, but the A/1 On is still true when the program executes line 7 so line 9 will set it right back to 1. On the next pass line 4 will compare the last passes' "1" to the "1" that's again there now and will test false.

The flaw with this program is that it's the exact same condition (A/1 On) that sets variable# 1 to 1 on both sides of the "becomes", so line 4 can never get to see a "0" again. If you make line 7 look for a different trigger (ie: an A/2 On) then it works correctly.

Your first example didn't have that problem because the program was allowed to finish the loop and also loop several times after variable# 1 was reset to "0". You needed another, new A/1 On command to make it "1" again.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#200 - 03/09/03 02:09 PM Re: Use of BECOMES
John Warner Offline
old hand
*****

Registered: 01/09/03
Posts: 834
Loc: Port Perry, Ontario, Canada
Thanks Guy - nice to have a clear mind around to keep the cob-webs out of mine.

I still haven't figured out the problem that was leaving my All Off variable signal set to 1 but I've done a workaround so it should be ok now.

Interesting that setting a Variable = 1 twice in the same pass doesn't seem to mess up the Becomes = 1 test though. I guess you're correct in your assumption that the comparison is done from 1 pass to the next so even though I set it = 1 more than once in the same pass, it only matters what it was in the previous pass?

Top
#201 - 03/09/03 02:43 PM Re: Use of BECOMES
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
That's the way I see it, and that I find the most logical (ie: predictable). It's also easy on resources, only needing to memorize the value from one pass to the next for comparison.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#202 - 03/11/03 08:03 PM Re: Use of BECOMES
JC Offline
journeyman


Registered: 02/12/03
Posts: 67
Loc: Mascouche, Quebec, Canada
Look at the BECOMES = and the TURNS ON as leading edge single scan one-shot contacts, and the BECOMES NOT = and TURNS OFF as trailing edge single scan one-shot contacts.

In ladder logic, this would be programmed as follows;
[CODE]Leading edge single scan one-shot relay (OSR)

OSR R1
1--| |------------------------------------(U)--

IN1 R1
2--|/|------------------------------------(L)--

IN1 R1 OSR
3--| |----| | ----------------------------( )---

Program lines affected by OSR till end of program.
----
----
----
[/CODE]Following the above logic, when contact IN1 is OFF, R1 is latched at line 2. When contact IN1 is ON and R1 is ON then OSR is ON. When the program loops back to line 1, OSR being ON, resets the R1 latch which the resets OSR to OFF even if IN1 is still ON. OSR was ON for 1 scan only.

I hope this helps to understand the principle.
_________________________
Imagination is more important than knowledge. - Albert Einstein

Top
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 60 anonymous users online.
Recent Posts
Ocelot Battery
by ADI Tech Support
09/22/17 07:38 AM
Comms Retry Error
by HDTVPete
09/18/17 04:04 PM
Cmax Message: Failed to set data for a 'delay'
by HDTVPete
09/16/17 04:36 PM
Shout Box

Newest Members
brigiel, vevevie, zhutree, 416, saiqul
3003 Registered Users
Forum Stats
3003 Members
19 Forums
4002 Topics
23435 Posts

Max Online: 132 @ 11/13/16 10:07 AM
September
Su M Tu W Th F Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30