Author Topic: Copy/Paste ladder rungs  (Read 8364 times)

cdenk

  • Full Member
  • Posts: 161
  • newbie
    • View Profile
Copy/Paste ladder rungs
« on: September 12, 2006, 10:58:14 AM »
Is there a way to copy paste ladder rungs to a word processor, this forum, etc. ?

Can files be attached to a message?

Can a JPG (or other graphics) file be embedded in message?

I have a file that sets several Outputs, then DM[] =  ADC(1) , does some scaling all in one Cust Fun. Then in a 2nd Cust Fun uses SETLCD to display the results. When the little file runs, it's OK, but when copy/paste to a larger file after debuggling, the values go goofy. Would like to post the little file, but it's more than I can do with a text editor and ASCII charaters, plus likelyhood of doing a typo.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Copy/Paste ladder rungs
« Reply #1 on: September 12, 2006, 11:44:08 AM »
Sorry, TRiLOGI grahic circuit cannot be cut and paste readily into this forum. However, if you press Alt-PrintSc keys you can capture the TRiLOGI windows as a graphic and paste into a word processor.

There is no option for uploading file here. However, if you store your file into some public webpage area (your could consider getting yourself some web space at yahoo.com) you can post a link to the file or graphics.

If the same two custom functions work on the small file but doesn't behave the same way on a bigger file, most likely somewhere else in the bigger program the data has been modified. Do a search for the text involving the function. To debug, place some pause statement after scaling conversion to look at the result, then release the pause to let the LCD display the data and see if it has changed and then you can better tracking down what's went wrong in the logic.

Email: support@triplc.com
Tel: 1-877-TRI-PLCS

cdenk

  • Full Member
  • Posts: 161
  • newbie
    • View Profile
Re:Copy/Paste ladder rungs
« Reply #2 on: September 12, 2006, 06:36:28 PM »
Played with "Pauses", and am thinking the CUSTFUN should execute top to bottom, stopping at the "Pause". Unpaused  several times to eliminate startup values. Here is a part of the CustFun, which is executed 0.1second:

SETIO OUT_41
CLRIO OUT_44
CtrPV[2] = 6
IF CtrPV[1] = 1
CLRIO OUT_42
CLRIO OUT_43
X = ADC(1)
X = ADC(1)
X = ADC(1)
X = ADC(1)
DM[3991] = ADC(1)
DM[3988] = DM[3991] * 3863/100000
ENDIF


IF CtrPV[1] = 2
'Set A0
SETIO OUT_42
'Set A1
CLRIO OUT_43
X = ADC(1)
X = ADC(1)
Y = ADC(1)
Z = ADC(1)
DM[3992] = ADC(1)
DM[3989] = DM[3992] *120/3150
IF DM[3989] > 10
SETLCD 4,1, STR$(DM[3989]) + " *********"
PAUSE
ENDIF
ENDIF

previously when CtrPV[1] = 1, ADC(1) = 3500, and is OK.

For this case the CtrPV[1] = 2, and ADC(1) should be near zero, and X, Y, Z, and DM[3989] are all around 3500. With the PLC Paused, measuring voltages with a volt meter, The Out_41 to Out_44 are as expected and ADC(1) input is zero. Have experimented with long delay loops (For I = 1 to 50000) and as seen here added dummy ADC()'s. The addresses are to a DG408 analog multiplex chip. The inputs are large lead acid batteries and 120 volt transformed to 9vac, rectified and resistor voltage divided to under 5 VDC. This worked for several weeks and quit working maybe about the time TRILOGI 6.1 came out, when I was working on other issues. The individual small program worked fine. Was there any changes in the code generated between 5.3 and 6.1 for these functions?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Copy/Paste ladder rungs
« Reply #3 on: September 13, 2006, 06:07:29 PM »
There are no changes in the compilation of the program in version 6.11. All the changes in version 6 are mostly in term of user interface and source file format (unicode instead of ASCII).

Remember that when you SETIO or CLRIO, the changes are only in the internal memory that represent the output. The physical output is only updated at the end of the ladder logic scan. Since you are using your outputs to switch the multiplexer to another ADC source, what happen after a SETIO the multiplexer is still still at the old position, and so reading the ADC several times or putting a large loop is not going to help in getting the new ADC value from another source.

Typically the most efficent way is to change the multiplex and let the ladder logic continue until the next scan cycle then read the ADC. So put the ADC reading before the multiplexer change, not after.

Second method is to use the REFRESH statement to force an I/O refresh after a SETIO or CLRIO, but REFRESH takes 2ms to complete so it increases your program scan time.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

cdenk

  • Full Member
  • Posts: 161
  • newbie
    • View Profile
Re:Copy/Paste ladder rungs
« Reply #4 on: September 13, 2006, 07:02:06 PM »
I am under the impression that a Custfun is executed in it's entirety when it's rung is encountered. Maybe I'm not interpeting correctly, but 'Help 3.b.1" says:
"Hence if the CusFn modifies a certain I/O or variable, it is possible to affect the running of the remaining ladder program. "


When does the pause actually "Pause",
1: Stopped in the middle of the Cust Fun?
2: At the bottom of the ladder including setting the latches?

In this case the latches are actually set per the instructions just a couple of lines before the read the ADC and pause.

I didn't show previously, but the counter is incremented with a "UPCTR" directly below the Custfun on the same rung.

If I got this right, when the Custfun is executed:
1: The counter the SETIO's will have the values set at the bottom of the previous scan of the ladder. At the moment the SETIO's are before the ADC, and that seems to work in some cases during normal running, which supports the Custfun changing things immediately. But, I have previously had the SETIO's after the ADC and that seemed to work too, and will try that again.

The real issue is the code works fine in a small program, but when copy pasted to the large program values go goofy. I am using DM[]'s in the range 3988 - 4000 (that's about the only ones used) and have checked for variable modifications elsewhere. Seems almost like the address counter gets confused, off by 1 or 2. The IF DM[3989] > 10 is intended to catch goofy values, and sometimes will go maybe 20 cycles before being caught, then one value and back to normal. Will write a porgram tomorrow to exercise the DM[]'s to see if read/writing causes errors.  The big program is 74 circuits, 1531 total code size.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Copy/Paste ladder rungs
« Reply #5 on: September 13, 2006, 07:41:36 PM »
A Custom function call will complete executing all its statements before refurning back to the ladder scan. If a PAUSE statement is encountered it stops right there. PLC performs a physical input and output updates (called I/O scan) for all the digital I/O at the end of a ladder logic scan. Before the I/O scan all the I/O bits used in the program are just a copy of the I/O in memory, so even if you have triggered an output to ON, it will still only be updated at the end of the ladder logic scan.

It doesn't matter that the SETIO are a couple of lines before the read ADC command, the physcial output latches are not updated after the SETIO until this custom function exits and the ladder logic scan to the end and then the output is updated. That's how standard PLC works.
Please note that other than the digital I/Os, mostl other I/Os  are changed at the point of execution of CF e.g. ADC read, DAC write,  setPWM, etc.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

cdenk

  • Full Member
  • Posts: 161
  • newbie
    • View Profile
Re:Copy/Paste ladder rungs
« Reply #6 on: September 14, 2006, 09:16:15 AM »
I changed both the "CustFun"'s to "dCUSF"s for both where reading the ADC, and displaying with SETLCD. They both execute 0.1 second. Also moved the SETIO's to after the ADC's (probably mostly for readablity of the program) and the SETIO's are set for the next I/Oscan, and this works. The dCusf seems to been the cure. Apparently the delay between I/Oscans is sufficient time for the multiplex chip to settle, where previously for whatever reasons the PLC scans varied in time, and when a little shorter period, would catch the chip unsettled. I still have one dummy ADC read to get reliable numbers, but there are no delay loops. That doesn't quite fit with shorter program is OK, but it is working now, and that's what is important. Thanks for hanging in there with the help.  :) :)

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Copy/Paste ladder rungs
« Reply #7 on: September 14, 2006, 04:55:02 PM »
When you use non differentiated version of Custom Function {CusFn}, the CF is executed every scan of the ladder logic during the half cycle (0.05s) when the Clk:0.1s contact is ON. This defeat the purpose of using the 0.1s clock pulse.

{dCusF} on the other hand only run once every 0.1s, this means that there is a delay of 0.1s from the time you switch the multiplexer until you read it in the next scan at statements before the multiplexer statement. That 0.1s delay should be more than enough for the ADC reading to stabilize so you can read it correctly.
« Last Edit: September 14, 2006, 04:55:59 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS