
adccommunitymod (AutomationDirect) asked a question.
Created Date: April 27,2005
Created By: ahend
**** 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.****
Greetings, I have recently entered into the relm of PLC programming via DirectSoft and I'm having trouble with what seems to be a simple operation. I would like to take a value from the accumulator, which was constructed from a counter, and use it as a V memory location. Say for instance, the value 431 currently resides in the accumulator, I would like to write the value 1 or 0 to V431. So then, the counter I refered to is dictating what memory address I use. I 've looked at LDA and OUTX but those functions require a known offset, my offset will not be constant. I thought there may be some form of substitution notation, for example; V "V400 ", but that only seems to be valid using the VPRINT function. Any help is greatly appreciated.
Created Date: April 27,2005
Created by: ahend
Greetings,
I have recently entered into the relm of PLC programming via DirectSoft and I'm having trouble with what seems to be a simple operation.
I would like to take a value from the accumulator, which was constructed from a counter, and use it as a V memory location. Say for instance, the value 431 currently resides in the accumulator, I would like to write the value 1 or 0 to V431. So then, the counter I refered to is dictating what memory address I use.
I 've looked at LDA and OUTX but those functions require a known offset, my offset will not be constant. I thought there may be some form of substitution notation, for example; V "V400 ", but that only seems to be valid using the VPRINT function.
Any help is greatly appreciated.
Created Date: April 27,2005
Created by: Tech Guy
What you are looking for is refered to as 'pointers '.
With pointers, you use a hexadecimal (decimal) number to point to the memory address that you really wish to use.
For example, loading a Hex 400 into V4000 and then doing a LD P4000 (P, is used like the 'V ' but indicates that the contents of the address should be used as a pointer) will cause the PLC to go to address V2000 (400 hex = 2000 octal) and load the value stored there.
Please see the beginning of the Accumulator/Stack instruction section of chapter 5 for more info on using pointers.
Created Date: April 27,2005
Created by: franji1
If you are using a CTR as a source for a pointer "offset ", remember that pointers are HEX addresses, which require BINARY formatted values.
You should do your pointer arithmetic in BINARY format, so you should do the following. Store the "base " pointer value (say Octal 20000 to reference V2000) in a "base " pointer address on first scan, say V1400. This would be done using SP0 (First Scan designation), and the LDA (Load Octal Address) box:
SP0
--] // loads 400 hex into the accumulator
|
+-- // V1400 is now the "base " pointer for all pointer calculations, and is equal to 400 hex - this register should NEVER change - it's the BASE pointer, not the actual pointer
Say we want to generate a pointer based on the counter accumulator of CT1, which would be CTA1 (or V1001), and store that pointer value in V1401, then you would calculate it using the base pointer register (V2000) and the BINARY equivalent of CTA1 (which is BCD format), so do the following:
SP1 (always on)
--] // loads BCD format of our "offset " into accumulator
|
+-- // converts accumulator from BCD to Binary
|
+-- // adds the BASE address to the offset in BINARY format - note use ADDB, NOT ADD
|
+-- // write the calculated pointer to V1401
Now we have THE address we want to "dereference " in V1401. Now just use V1401 as a pointer:
This would do a BCD "square " to whatever we were pointing to and store the result to V2100. If the Counter Accumulator was equal to 10 (BCD), V1401 would contain Octal 2012 (because counters count base 10, but addresses are octal, so octal 2000 plus 10base10 equals 2012 octal), so V2100 would be equal to V2012 squared.