Pointers and For..Next loops in Ladder Logic

bluffit

Member
Join Date
Apr 2011
Location
Western Southland
Posts
33
From memory in C I would have done something like this:

char * a = (char*) malloc(1024 * sizeof(char));
char * b = (char*) malloc(1024 * sizeof(char));
int i=0;

// set some values up in *a.
// apply a function and assign to *b

while( i++ < 1024){
b = foo(a)
}


The question is, how would I do this in Ladder logic with Vxxxx addresses?

Something like this?

FOR (k=100) -------------------------------->
LD V2000 + (k-1) // I see that k = 1 on iteration 1.
// Do something with the accumulator value
OUT V2100 + (k-1)
NEXT <---------------------------------------

Thanks, hopefully this is a simple one. Am using DirectSoft5.
 
Last edited:
Directsoft has pointers.

The address, your 'i', is initially assigned as a hex value to a chosen V register.

LD V2000 K0 - the value in V2000 can now be used to 'point' to V0.

But many times you wish to point to some other register. Let's say we want the pointer initialized with the address of V3000. Remember that the addressing is in octal. You can either convert it on paper or use the supplied conversion command...

LDA O3000 - that is the letter 'O' followed by 3000
OUT V2000 - now V2000 can be used to 'point' to V3000

Let's store a value in V3000 using this pointer

LD K50
OUT P2000 - we use the letter 'P' with the address of the 'pointer'

But since the pointer is a hex value any manipulation of it must be done using the 'binary' form of the various math operators. ADDB, SUBB, MULB etc.

Read the various tables in the manual for the address of various named values. The 'bit' values (X, Y, C etc) are grouped in 16, each having a single 'V' address so can be addressed by pointers. The DL06 and the DL260 at least have 'Pointer Bit Of Word' addressing.

STR PB2000.5 loads the state of bit '5' of the group of 16 bits pointed to by V2000. Unfortunately the 'bit' designation can't be varied at run time. It's fixed in the particular instruction.

You can't use the current value in the accumulator as a pointer though the LDX and other type instructions come close.

We use pointers in moving recipe data blocks to/from a large memory area.
 
This is great, thanks.

Is there a simple way to programatacically manipulate the "O3000" value in LDA O3000. Can I replace with a variable/iterator from a FOR loop?
 
But since the pointer is a hex value any manipulation of it must be done using the 'binary' form of the various math operators. ADDB, SUBB, MULB etc.

Let's review

LDA O3000 - that is the letter 'O' followed by 3000
OUT V2000 - now V2000 can be used to 'point' to V3000

Let's store a value in V3000 using this pointer

LD K50
OUT P2000 - we use the letter 'P' with the address of the 'pointer'

Now the following operation

INCB V2000 - remember to use 'binary' math operations

Makes the pointer in V2000 point to V3001

As long as the pointer 'points' to a valid address (review all the charts of the 'V' equivalents in the DL CPU manual) you can use it.


A FOR/NEXT loop would initialize any pointers before the loop

LDA O3000
OUT V2000
LDA O4000
OUT V2001

now V2000 and V2001 are pointing to the beginning of memory areas starting with V3000 and V4000 respectively

inside the FOR/NEXT loop

LD P2000
OUT P3000
INCB V2000
INCB V2001

'NEXT'

obviously does a brute copy, one at a time (more easily done with MOV) from the V3000 areas to the V4000 areas.

You will probably work out better things to do inside the loop. Just don't overrun valid memory areas. And use 'binary' math when manipulating the pointers.

Also be aware that FOR/NEXT loops can take a lot of time! Be careful.
 
Last edited:

Similar Topics

Hi I am starting to look into S7 pointers I have 3 data blocks in which i wish to compare bits. Below (ladder logic made to source file) is a...
Replies
8
Views
4,605
Hello, I've just came out of a call where a program that was modified two weeks ago threw the processor into fault. The program has been done...
Replies
9
Views
3,463
I'm trying to get a 5069-L306er to talk to a Automation Direct ProSence Controller by using RA's AOI for modbus client but its stuck not getting a...
Replies
9
Views
1,878
The last time I did anything with Wonderware was just after the dot com bust. Boy, I feel old. Anyway, it looks like I will get the chance to...
Replies
3
Views
1,511
Hi guys, Some pointers needed: Having PC with WIN7 pro X64 and Amsamotion clone of 6ES7 972-0CB20-0XA0 cable and need to backup VIPA cpu...
Replies
14
Views
3,112
Back
Top Bottom