
adccommunitymod (AutomationDirect) asked a question.
is there a way to do a LDR ADDR with a MOV
Created Date: March 11,2011
Created By: timjan2005
**** 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.****
Currently I do the following: LDR V1400 ADDR V2400 OUTD V4400 I'm having to do this for 24 different location every second. LD: v1400 v1402 v1404...ect ADDR: v2400 v2402 v2404...ect OUTD: v4400 v4402 v4404...ect Just wondering if there was a way to use the MOV instruction and move all 24 locations, with their ADDR, to their destinations in one rung?
Created Date: March 11,2011
Created by: bcarlton
A FOR/NEXT loop would have fewer instructions but take more time.
Three Pointers. Double increment each one after each pass through the loop.
LDA O1400
OUT V2000
LDA O2400
OUT V2001
LDA O4400
OUT V2002
FOR K24
LDR P2000
ADDR P2001
OUTD P2002
INCB V2000
INCB V2000
INCB V2001
INCB V2001
INCB V2002
INCB V2002
NEXT
Created Date: March 11,2011
Created by: Do-more PE
The easy way to do this is by using pointers.
A word of warning with using for/next loops; it is very easy to trip the watchdog timer if the loop is very big.
PLC 06
// Rung 1
// Address 0
#BEGIN COMMENT
"Initialize the pointers "
#END
STR SP1
LDA O1400
OUT V5000
LDA O2400
OUT V5001
LDA O4400
OUT V5002
// Rung 2
// Address 7
#BEGIN COMMENT
"Execute the loop 24 times. "
#END
STR SP1
FOR K24
// Rung 3
// Address 10
STR SP1
LDR P5000
ADDR P5001
OUTD P5002
// Rung 4
// Address 14
#BEGIN COMMENT
"Add 2 to every address to account for double word instructions. (LDR, ADDR, OUTD) "
#END
STR SP1
INCB V5000
INCB V5000
INCB V5001
INCB V5001
INCB V5002
INCB V5002
// Rung 5
// Address 27
NEXT
// Rung 6
// Address 28
END
// Rung 7
// Address 29
NOP
// Rung 8
// Address 30
NOP
#BEGIN ELEMENT_DOC
"V5000 ", " ", " ", "Pointer for LDR "
"V5001 ", " ", " ", "Pointer for ADDR "
"V5002 ", " ", " ", "Pointer for OUTD "
"P5000 ", " ", " ", "Pointer for LDR "
"P5001 ", " ", " ", "Pointer for ADDR "
"P5002 ", " ", " ", "Pointer for OUTD "
#END
Edit: And Bernie beats me to the punch yet again. :)
Created Date: March 11,2011
Created by: timjan2005
thanks guys.
I use a lot of pointers in my code so this shouldn't be a problem for me to set up. I hadn't thought of using pointers for this task.
And like what was said, i always put a rstwt inside my for/next loops.
thanks again
Created Date: March 11,2011
Created by: timjan2005
Currently I do the following:
LDR V1400
ADDR V2400
OUTD V4400
I'm having to do this for 24 different location every second.
LD:
v1400
v1402
v1404...ect
ADDR:
v2400
v2402
v2404...ect
OUTD:
v4400
v4402
v4404...ect
Just wondering if there was a way to use the MOV instruction and move
all 24 locations, with their ADDR, to their destinations in one rung?