Definitely a newbie question

TJF1960

Active Member
Hello All,
 
When programming outputs to turn on in PLC is it better to arrange the code so the output(s) turn on or off just once and not just repeditively. In other words, as an example:
 
START
SET OPx 1
END
 
Or
 
START
TSTEQ OPx 0
SET OPx 1
END
 
Or does it really matter? Is there a performance hit by doing it either way?
 
Thanks,
Tim
 
That is a very good question. I was under the impression that there was not a problem setting an op repeatedly, but I never asked that question. I would also like to know what CAI_SUPPORT has to say about that.
 
Tim,
 
If you do not turn on and off repeatedly, in both ways, your relay will not see any difference.  To WebControl itself, you can turn on and off or repeated turn on all the time, there is no harm.  Only thing could harm WebControl is constantly save configuration for 100,000 times -- that is the write cycle limitation for EEPROM chip.  Normal operation on VAR/RAM and I/O register will operate forever with no limit.
 
The thing needs to watch out is when you turn relay on and off repeatedly.  Most mechinical relay has life span for how many times it can switch, be it million times or 10 million times.  Most motors do not like being on and off too freqent either.  You can avoid that by set a range, so that when temperature goes below 68 degree, turn on heater, when temperature goes beyond 75 degrees turn off heater,  In stead of turn on T < 72, turn off when T > 72.  Of course, the temp range is just my imagination, you pick your range based on your need.
 
Hope this helps.
 
You are welcome. If there is any question, please don't hesitate to post here.  Questions can be WebControl related or just about electronics implementation. 
 
I could use some help. I am adding 1 last function to one of my w/b (fw 3.02.16c). The basic scenario is this:

When VAR8 is 5 OP1 turns On, 1 second later OP’s 3,4,5,6 turn On
When VAR8 is 15 OP1,2 turns On, 1 second later “   “    “   “    “
When VAR8 is 6 OP1 turns On, 1 second later OP’s 3,4,5 turn On
When VAR8 is 16 OP1,2 turns On, 1 second later “   “   “    “    “
When VAR8 is 7 OP1 turns On, 1 second later OP’s 3,4 turn On
When VAR8 is 17 OP1,2 turns On, “     “     “     “     “      “       “   “
When VAR8 is 8 OP1 turns On, 1 second later OP3 turns On
When VAR8 is 18 OP1,2 turns On,  “   “    “     “    “     “     “    “
 
One minute after all the OP’s turning On I want OP’s 3,4,5,6 to all turn off, then 1 second later OP’s 1,2 need to turn Off.

Also, VAR8 should reset to 0 right after the OP’s are all turned on because, and here’s the catch - Anytime during that 1 minute period when the OP’s are on, if VAR8 is set to 5,15,6,16… the length of time all of the OP’s are on needs to extend another minute.

On and Off times are not critical. The turn on/off sequence as stated above is critical though.

This program will only get called 5 or 10 times throughout the day.

Non-Blocking delay would be a favored as there is other code that runs continuously.
 
Also, pretty much all VAR's and RAM is being used up.

I did spend the last 3 days coding and recoding this (over 200 lines of code), and I have tried to simplify it but just haven’t been able to.  I could post if need be (would have but didn’t want anyone laughing at me!).

Any suggestions would be welcome.

Thanks,
Tim
 
I completely scraped all the code and started fresh. This is the first phase. It is working but seems very cumbersome and well, elementary
Any tips on making it easier/cleaner?
 
START   
 DELAY 5000
 SET OP1 0 
 SET OP2 0 
 SET OP3 0 
 SET OP4 0 
 SET OP5 0 
 SET OP6 0 
 SET OP7 0 
 SET OP8 0 
 SET VAR1 0 
 SET VAR2 0 
 SET VAR3 0 
 SET VAR4 0 
 SET VAR5 0 
 SET VAR6 0 
 SET VAR7 0 
 SET VAR8 0 
 SET RAM1 0 
 SET RAM2 0 
 SET RAM3 0 
 SET RAM4 0 
 SET RAM5 0 
 SET RAM6 0 
 SET RAM7 0 
 SET RAM8 0 
LOOP:
 TSTEQ VAR8 5
 CALLSUB PWR
 TSTEQ VAR8 5
 CALLSUB ALL
 TSTEQ VAR8 15
 CALLSUB PWR
 TSTEQ VAR8 15
 CALLSUB ALL
 TSTEQ OP1[7000] 1
 CALLSUB OFF
 GOTO LOOP
 END 
PWR:
 TSTEQ OP1 1
 RET
 SET OP1 1
 TSTGE VAR8 10
 SET OP2 1
 NOP
 RET
ALL:
 TSTEQ OP3 1
 RET
 TSTEQ OP1[1000] 1
 SET OP3 1
 TSTEQ OP1[1000] 1
 SET OP4 1
 TSTEQ OP1[1000] 1
 SET OP5 1
 TSTEQ OP1[1000] 1
 SET OP6 1
 TSTEQ OP3 1
 SET VAR8 0
 NOP
 RET
OFF:
 SET OP3 0
 SET OP4 0
 SET OP5 0
 SET OP6 0
 TSTEQ OP3[1000] 0
 SET OP1 0
 TSTEQ OP3[1000] 0
 SET OP2 0
 NOP
 RET
 
Thanks,
Tim
 
Tim,
 
When board first power up, all TTL output, all VAR and RAM should be zero, with one exception, if you changed TTL output value in the TTL output screen and clicked on save button, that TTL output value will be stored and load back during power up.
 
To avoice mistake, you could set all TTL output to zero when power up, that is a good practice. However, you may want to move that before the 5 second delay.  You don't have need to set VAR and RAM to zero during power up, they always initialized to zero by firmware during power up.
 
Thank you for the tip!
However I have other LAN devices setting VARx and OPx and I wanted all to reset to 0 after the 5 second start period, right before LOOP commence. Does that make sense?
 
What sets the values in the vars? Can you change the numbers into bits and store multiple values in 1 var?
What would be nice is if each output were actually 1 bit in a word. Now to manipulate the outputs I simply ANDB a mask to the output word and change all 8 at once. If I wanted OP 8,7,5,3,1, on I could ORB 213 with the OP word and done. ANDB 42 would turn 8,7,5,3,1 off and leave the others at their previous state. It would also free up 7 more vars.
 In your case this could be a huge savings in your code. As Ross has discovered, each output can also be used as a var but the upper value does have a limit for some peculiar reason.
On a dedicated PLC controller an input card typically has a full word reserved for it. If the card only has 8 inputs the other 8 bits aren't used so using them has no ill effect.
Each output on the W/C only uses the 1st bit (LSB). Except for 32 (MSB), the rest do what??????
 
I have my ISY994 send basic numbers (currently 1-20) to VAR8. If I understand what you are saying is have the ISY send bit values to VAR8..for instance in your example if I wanted OP8,7,5,3,1 all on then set VAR8 value to 213 which the w/c would convert to 11010101? (Hopefully I have at least this much right!).
Could I impose on you a little more? Could you possibly give me an example of the code which would turn OP1,3 on then 1 second later turn on OP5,7,8. Then 5 seconds later turn off OP5,7,8 
 
I do remember reading and trying to grasp Rossw's thread about the OPx storing bits but I am afraid its still out of my league so far. But I think if I had an example I could relate to it would be easier for me to grasp.
 
Thanks,
Tim
 
 As of yet, the outputs aren't bits in 1 word so we can't use a simple mask to manipulate all at once.The bit masks remark was more directed at CAI as a nudge to see if it was possible to do this. It would be beneficial in a case like yours. Maybe 3.2.18 will have this? 
What Ross was saying is that you can store even numbers in an output, all numbers if the output isn't used as an output. for example if output 1 is on, it would look like ......0001 in binary. All but the right most and leftmost bit is a freebie. If you ORB the number 8 (ORB OP1 8 OP1) with the output it would now look like .....1001. To cancel you need to flip the bits and ANDB. To cancel 8 and not change the output or 2's or 4's place .....0111 (ANDB OP1 7 OP1). Ross can do the binary conversions in his head while sleeping. I can't so I made a spreadsheet to help me.
http://cocoontech.com/forums/topic/22429-spreadsheet-to-help-calc-bitwise-operations/#entry183242.
Ross and Lou are the Guru's on programming these boards.
It might be easier for you if you draw up a flow chart first. Ross has posted some examples of his flow charts that might give you a direction if you need one.
 
As far as an example of setting the outputs... For your start I would simply place a 0 in a var and then in a subroutine or step I would simply ANDB var1 to all the outputs. To turn on the outputs 1,3,5,7,8 after 5 seconds you could take the cts and add 5 to it. test it to see if it = CTS. repeat test until it does then place the mask in var1.
 
Below isn't exactly how to do it but may give you some ideas to work with.
 
Start
set var1 0     initialize all outputs to off
gosub outputs
Do whatever
tstgt cts var2    if cts is greater than var2 then the timer expired. 
Goto timer
Timer:
set var2 cts      sets var2 to the current total seconds      
add var3 cts var2 add var3 to current total seconds and place the new value in var2- var 3 will be the value determined along with the output mask
tsteq var2 cts   when var2 is equal to cts your timer is done.
 tsteq var8 16
goto mask16
tsteq var8 5
goto mask5

Mask5:
set var1 1   op1 on 
gosub outputs 
set var3 1
run timer
set var1 61   this will be op1,3,4,5,6 on and op2,7,8 off
gosub outputs
...
...
...
Mask16:
set var1 3  op1 2 on
gosub outputs     
set var3 1  use 1 for seconds timer
run timer
set var1 61   this will be op1,3,4,5,6 on and op2,7,8 off
gosub outputs
1 minute timer
set var 1 3      set all but op1 2 to off
gosub outputs
1 second timer
set var1 0    set all op to off
gosub outputs

outputs:
ANDB 1 var1 op1
ANDB 2 var1 op2
ANDB 4 var1 op3
ANDB 8 var1 op4
ANDB 16 var1 op5
ANDB 32 var1 op6
ANDB 64 var1 op7
ANDB 128 var1 op8 
ret
 
todster,
 
Thank you very much for the explaination and example. I am beginning to get it I think. I will play with it some more.
 
Thanks again,
Tim
 
You might be able to use var1 to also apply masks for a timer as well. Just an idea, the logic hasn't come to me yet. On my Allen Bradley PLC I use a free running timer as a flipflop. It goes to 32767 and resets itself back to zero and counts again. The weight of the bit position determines the duration of time. Bit 0 is on off on off on... bit 1 is off off on on off off.... bit 2 is on on on on off off off off on on on on off off off off. In otherwords bit 1 changes state 1x for every 2x of bit 0. Bit 2 is 4x of bit 0. If only we could do the same on the WebControl. There is a probably a similar way but I can't think of it. The fact that you can use a delay in milliseconds indicates that there is most likely a free running timmer where you could compare a particular bit for on and off and use that for the seconds. It wouldn't be precise but it would be predictable.
As the timer counts, its accumulator would look like below. You simply chose the bit that corresponds to your time duration. If the timer base is .01 seconds then bit 3 would yield .08 seconds on .08 off. Bit 7= 1.28 seconds. You could increment a var each scan but that would be unpredictable.
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
 
Back
Top