PDA

View Full Version : COPY command


TimothyMoulder
June 7th, 2002, 10:10 AM
This is a gross over-simplification of my goal, but it makes the point...

1. I have registers N7:0 through N7:9 on a Micrologix 1200.

2. I wish to use the RSLogix500 COP (copy) command to copy the values from registers N7:0 - N7:8 into registers N7:1 - N7:9

Yep, it's a stack command, but the Indexing on the commands for this in RSLogix confuse me. So, as Terry would say, "I'm rollin' my own!"

Has anybody done something similiar, and is there a reason it wouldn't work? Verified okay, but I'm still dubious.

Thanks!

TM

Allen Nelson
June 7th, 2002, 10:20 AM
You can do it in one of two ways:

1) You can have the stack in REVERSE ORDER, and do [COP #N7:1 #N7:0]. Although executed in a single scan, it will move N7:1 into N7:0, and then N7:2 will replace N7:1, and so on.

2) You need to use an intermediate stack. [COP #N7:0 #N10:0] followed by [COP #N10:0 #N7:1] .

Trying to do it the way you are describing reinvents the FLL (file fill) command. N7:0 will copy into N7:1, which will then copy into N7:2, and so on.

TimothyMoulder
June 7th, 2002, 10:24 AM
That's what I needed to know.

Thanks!

TM

Alan Case
June 7th, 2002, 10:28 AM
Without putting a lot of thought into it I don't think it will work the way you intend. I presume the processor will work in the order detailed below.
N7:0 will first be copied into N7:1
then N7:1 will be copied into N7:2 etc etc
What will happen is that the value in N7:0 will end up in all the registers.
A quick solution would be 9 separate move commands starting at moving N7:8 into N7:9 and working backwards.
An interesting question, I might try it tomorrow on a ML1500 and see what happens. Regards Alan Case

TimothyMoulder
June 7th, 2002, 10:47 AM
I took Mr Nelson's suggestion and used an intermediary file, copying to it and then back again, one register lower. Fast, simple and one rung long :D

Thanks!

akreel
June 7th, 2002, 12:57 PM
Not comfortable with indirect addressing?

You can increment a register (ex: N8:1) by two through the sequence 0,2,4,6,8.

Add 1 to N8:1 and store that into N8:2.

Then, your copy command is: COP N7:[N8:1] N7:[N8:2]

I've got a routine like this working with a sequence of 50 registers (in groups of 5), using a 0-9 counter. Of course, all I'm doing is displaying this data so I don't need all 50 registers updated in the same scan.

AK

Allen Nelson
June 7th, 2002, 01:49 PM
That won't do what Mr. Moulder (- hey, call me 'Allen') wants.

He wants a continuous block of registers to move up the stack by one, when triggered.

On the first scan N7:0 goes to N7:1. The data that used to be in there, which should have moved into N7:2 is now lost for forever.
On the next, N7:2 goes to N7:3, again destroying data. Also, nothing ever fed N7:2 it's data.

Mr. Moulder - are you trying to build a sequencer, akin to the SQO? Doing it by FIFO is an interesting approach.

Usually I leave the "recipe" static and have a pointer to he current step (just as the SQO does). I never would of though of loading the recipe, and having that step fall off once it's been "used".

I'll have to think about that.....

akreel
June 7th, 2002, 04:00 PM
Originally posted by Allen Nelson
That won't do what Mr. Moulder (- hey, call me 'Allen') wants.

He wants a continuous block of registers to move up the stack by one, when triggered.

Indeed! I misread that one.

The indirect addressing can still be done, starting at N7:8 and moving down... I don't think the Micrologix supports a For-Next loop, but you could do it in one scan by creating one with jumps. I wouldn't recommend it though, jumps are bad mojo IMHO. Jumping backwards also has interesting effects on scan time. Better to do it the Nelson way. :)

AK

Gerry
June 7th, 2002, 09:16 PM
Allen Nelson:

1) You can have the stack in REVERSE ORDER, and do [COP #N7:1 #N7:0]. Although executed in a single scan, it will move N7:1 into N7:0, and then N7:2 will replace N7:1, and so on.

This is the more compact and efficient method of implementation. It is a word-oriented shift register, loaded at N7:8 and unloaded at N7:0. Ensure that N7:9 always contains zero or minus one or whatever code you wish for representing no data. I have used this technique numerous times.
Alan Case:

Without putting a lot of thought into it I don't think it will work the way you intend. I presume the processor will work in the order detailed below.
N7:0 will first be copied into N7:1
then N7:1 will be copied into N7:2 etc etc
What will happen is that the value in N7:0 will end up in all the registers.
Absolutely correct!

You can add auxiliary logic to turn the registers into a FIFO. Unloading is the same as shifting. To load, search for the first empty (0, -1, etc.) word and enter there. One big advantage to making a FIFO in this way is enabling the relatively simple removal of an item from the middle of the FIFO or queue. The last time I did this was on a PLC-3 which uses slightly different instructions and methods, however, the task is to search the file for the item to be removed and then modify the starting point (S:24) of the shift (COP) before doing the shift. Thus the tail of the queue moves up without affecting the head.
It's not impossible to accomplish that with FFL and FFU but it gets messy.

TimothyMoulder
June 10th, 2002, 07:05 AM
I used Allen's (:P))suggestion of an intermediary data table for the stack-add routine, then a straight copy up (9 registers to move, register 9 always null-value) to empty the stack. Works beautifully!

Thanks for the tips!

TM