Does anyone knows how to add 60 double words using Pointers?

piscis

Member
Join Date
May 2003
Posts
241
I have a 06 AD PLC and I need to add values which are greater than 9,999, so I’m using 60 double words starting at V4000. I did the code using the “ADDD” instruction 60 times but I thought there must be a beteer way. (the ibox instruction SUMBCD only works with 4 digits words, so I cannot use it)

Question:

Is there any other way to do this, perhaps with pointers, does anyone knows?

Thanks for your answers.
 
Your current method takes about 5 ms to complete. A pointer method would take about twice that time but use less program memory. Can the calculation be spread out over 60 scans? That would have less program iompact. Or do you need this every scan, or at least done in 1 scan?

Here's the 1 scan pointer method using a FOR/NEXT loop. V2000 holds the pointer.

LDA O4000
OUT V2000
LD K0
FOR K60
ADDD P2000
INCB V2000
INCB V2000
NEXT

At this point the accumulator holds the result ready to be stored.
 
Bernie:

Thanks a lot for your response. The calculation is actually needed to be done every Hour. I like the method you presented, but out of curiosity, what do you have in mind when you say “spread out over 60 scans”

Thanks
 
Instead of for next loop, just increment your pointer each scan. When it reaches the end, save the accumulated value, reset the value and the pointer.
 
You could try something like the following. It expands on Bernie's program. Like his, your values to add up should be stored starting at V4000. The pointer will live at V2000 and the totalized value will be stored as a Double at V2002. C0 should be turned on for one scan to start the process. C1 will indicate when the totalizing calculation is finished.

PLC 06
// Rung 1
// Address 0
#BEGIN COMMENT
"C0 should be turned on for one scan to start the process. This rung initializes the pointer "
"and performs the first addition (acutally it just moves the first value to the destination "
"address.)"
#END
STR C0
LDA O4000
OUT V2000
LDD P2000
OUTD V2002
// Rung 2
// Address 5
#BEGIN COMMENT
"If the pointer is still less than the final pointer position (V4166 or 876 in hex), it increments "
"the pointer twice (needed because we are adding doubles), LDDs the current total, "
"ADDDs the value that the pointer is pointing to and OUTDs it to the current total Vmem."
#END
STRN V2000 K876
INCB V2000
INCB V2000
LDD V2002
ADDD P2000
OUTD V2002
// Rung 3
// Address 14
#BEGIN COMMENT
"This rung turns on a bit to indicate that the calculation process is finished. You can use "
"this bit to avoid using a value that isn't fully totaled yet."
#END
STR V2000 K876
OUT C1
// Rung 4
// Address 17
NOP

#BEGIN ELEMENT_DOC
"C1","","","Calculation finished"
"V2000","","","Pointer"
"V2002","","","Total of values"
"P2000","","","Pointer"
#END
 

Similar Topics

Replies
8
Views
2,237
Does anyone knows if I can read this ONLINE, is there any archive somewhere? ================================================== ((((((( P L C...
Replies
2
Views
1,861
This a a Total Control HMI Screen. This error appear once in a while specially in very hot day temps.
Replies
11
Views
3,813
Does anyone knows what does the byte "30" at the end of a password byte array means? hi, i'm making a tool to write and read to the nais plc...
Replies
2
Views
4,787
They are installed in a control panel that was made in France and are intended for the termination of analog inputs. Each of the red capped...
Replies
4
Views
418
Back
Top Bottom