adccommunitymod (AutomationDirect) asked a question.

Passing Addresses to BASIC CoProcessor from Ladder Logic

Created Date: April 16,2007

Created By: AZRoger

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

I am having two separate problems with the BASIC CoProcessor. The first has to do with passing addresses into the processor from ladder logic. The second has to do with the STOP command. Let's cover STOP first. Line 19900 has a stop command so I can look at the variables and see what's happening. The line above it 19800 appears not to work. The target word is not filled in (data view does not see the change). If I copy that program line to the command line and run it, it does execute. So the question is, does STOP prevent asynchronous things like writing to the CPU memory from happening? This would be an odd behaviour, IMO, so it probably isn't what's causing the problem. But something is. The second question has to do with getting an address from the CPU and using it in a basic statement to set a specified word in the CPU memory. Line 19000 gets an address into variable AD1. Lines 19300, 19400 and 19500 try to use that address to put values in the PLC memory. These lines don't work. Similar line with math in the address part (Lines 20300-20600) work fine. I put a 0 (zero) at the front of the VH(expression) to see if the math would work then, it didn't. I need to have the Ladder tell the Basic CoPro where to put data. And I 've run out of ideas. 17900 REM Load all the Stages in one Pass 18000 BMOVE R,SG(1000),SG(1577) 18100 K5=0 : REM counter for words changed 18200 FOR I=0 TO 23 18300 K1=OLDSTATES(I).XOR.SHARED(I*2) 18400 IF K1=0 THEN GOTO 20000 : REM no change 18500 K2=K1.AND.SHARED(I*2) : REM See is changed bit is ON 18600 IF K2=0 THEN GOTO 20000 : REM it went off so don't count it 18650 OLDSTATES(I)=SHARED(I*2) : REM copy the new value 18700 K5=K5+1 : REM count the mismatch 18900 REM: K2 has the bit(s) that need to be set 19000 AD1=S205_VH(1476) : REM get address for first word to hold data 19100 AD2=S205_VH(1473) : REM get address of first force bit 19200 PRINT2 AD1; " ";AD2 19300 S205_VH(0+AD1)=MINUTEOFDAY : REM save the minute of day 19400 S205_VH(0+AD1+1)=AD2+I : REM point to the correct force bit word 19500 S205_VH(0+AD1+2)=K2 : REM save the bit(s) that is(are) to be forced 19600 AD1=AD1+3 : REM advance for next data 19700 IF AD1=S205_VH(1475) THEN AD1=S205_VH(1474):REM if last, start over 19800 S205_VH(1476)=AD1 : REM set address for next sample 19900 STOP 20000 NEXT I 20100 IF K5=0 THEN GOTO 20800 : REM skip the next part if no changes 20200 REM need to add to words changed and minutes that had changes 20300 K6=S205_VB(1460+THEDAY) : REM get current count 20400 S205_VB(1460+THEDAY)=K5+K6 20500 K7=S205_VB(1450+THEDAY) : REM get current count 20600 S205_VB(1450+THEDAY)=K7+1 20700 PRINT2 "At ";MINUTEOFDAY; " ";K5; " words changed K6,K7 ";K6; ", ";K7 20800 REM end of counter updating section Any help or pointers would be appreciated. Thanks. Roger


  • adccommunitymod (AutomationDirect)

    Created Date: April 16,2007

    Created by: FACTSTech

    >So the question is, does STOP prevent asynchronous things like writing to the CPU memory from happening?

    No. The BASIC Interpreter executes each statement to completion before going to the next statement.

    I don't see any reason why line 19800 would not execute. If there was a problem with the F2-CP128 backplane interface and the S205_ instruction could not execute then the interpreter would print an error out of the command port and the program would stop.

    What is the value of variable AD1 when line 19800 executes (add PRINT statement to see the value) and what value do you see in V1476 when the BASIC program stops?

    In order to use calculated addresses in the S205_ or BMOVE statement see page 2.3 and 2.13 in the F2-CP-M manual (http://www.facts-eng.com/manuals/f2cpm.pdf) under the 'Advanced ' heading.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: April 17,2007

    Created by: AZRoger

    FACTSTech,

    Thanks for the pointer to the pointer stuff. Page 2.13 is exactly what I needed. Odd about Hex 7 refering to VMem 6 ... but it works. The corrected lines are below.

    19300 S205_(AD1+1)=MINUTEOFDAY : REM save the minute of day

    19400 S205_(AD1+2)=AD2+I : REM point to the correct force bit word

    19500 S205_(AD1+3)=K2 : REM save the bit(s) that is(are) to be forced

    The other problem was in regular ladder logic and DS5. Aw I watched data view, the address sometimes changed to the expected new address, but was then reset to the first Vmem address. However, when the CoPro was stopped, the resets didn't happen.

    I check the BASIC program and there were only the two references to that address. One to pick up the current value and one to stuff the new one. The XREF view in the ladder logic had NO references to those addresses. Ugh.

    I think that problem was the result of my recovery from a DS5 crash. I had some initialization logic (LDA, OUT(box) sequences) as part of a long rung. I had deleted those rows from the rung. DS5 crashed during the SAVE to disk right after that. I didn't go through the "guaranteed " proceedure to recover. I just fired it up. It said the disk and PLC didn't match. I selected use disk and thought I was OK. However, it behaved like the graphical ladder and the functional ladder didn't match. The initialization logic was still running. I added a row to that long rung, put in a LDA, deleted the LDA and saved again. The problem went away.

    Moral of THAT story: Take backups often and be prepared to use them. http://forum1.automationdirect.com/board/smile.gif

    Thanks again for you help.

    Roger

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: April 16,2007

    Created by: AZRoger

    I am having two separate problems with the BASIC CoProcessor. The first has to do with passing addresses into the processor from ladder logic. The second has to do with the STOP command.

    Let's cover STOP first. Line 19900 has a stop command so I can look at the variables and see what's happening. The line above it 19800 appears not to work. The target word is not filled in (data view does not see the change). If I copy that program line to the command line and run it, it does execute. So the question is, does STOP prevent asynchronous things like writing to the CPU memory from happening? This would be an odd behaviour, IMO, so it probably isn't what's causing the problem. But something is.

    The second question has to do with getting an address from the CPU and using it in a basic statement to set a specified word in the CPU memory. Line 19000 gets an address into variable AD1. Lines 19300, 19400 and 19500 try to use that address to put values in the PLC memory. These lines don't work. Similar line with math in the address part (Lines 20300-20600) work fine. I put a 0 (zero) at the front of the VH(expression) to see if the math would work then, it didn't. I need to have the Ladder tell the Basic CoPro where to put data. And I 've run out of ideas.

    17900 REM Load all the Stages in one Pass

    18000 BMOVE R,SG(1000),SG(1577)

    18100 K5=0 : REM counter for words changed

    18200 FOR I=0 TO 23

    18300 K1=OLDSTATES(I).XOR.SHARED(I*2)

    18400 IF K1=0 THEN GOTO 20000 : REM no change

    18500 K2=K1.AND.SHARED(I*2) : REM See is changed bit is ON

    18600 IF K2=0 THEN GOTO 20000 : REM it went off so don't count it

    18650 OLDSTATES(I)=SHARED(I*2) : REM copy the new value

    18700 K5=K5+1 : REM count the mismatch

    18900 REM: K2 has the bit(s) that need to be set

    19000 AD1=S205_VH(1476) : REM get address for first word to hold data

    19100 AD2=S205_VH(1473) : REM get address of first force bit

    19200 PRINT2 AD1; " ";AD2

    19300 S205_VH(0+AD1)=MINUTEOFDAY : REM save the minute of day

    19400 S205_VH(0+AD1+1)=AD2+I : REM point to the correct force bit word

    19500 S205_VH(0+AD1+2)=K2 : REM save the bit(s) that is(are) to be forced

    19600 AD1=AD1+3 : REM advance for next data

    19700 IF AD1=S205_VH(1475) THEN AD1=S205_VH(1474):REM if last, start over

    19800 S205_VH(1476)=AD1 : REM set address for next sample

    19900 STOP

    20000 NEXT I

    20100 IF K5=0 THEN GOTO 20800 : REM skip the next part if no changes

    20200 REM need to add to words changed and minutes that had changes

    20300 K6=S205_VB(1460+THEDAY) : REM get current count

    20400 S205_VB(1460+THEDAY)=K5+K6

    20500 K7=S205_VB(1450+THEDAY) : REM get current count

    20600 S205_VB(1450+THEDAY)=K7+1

    20700 PRINT2 "At ";MINUTEOFDAY; " ";K5; " words changed K6,K7 ";K6; ", ";K7

    20800 REM end of counter updating section

    Any help or pointers would be appreciated. Thanks.

    Roger

    Expand Post