AD: Can you spot what’s wrong with this RECIPE code?

piscis

Member
Join Date
May 2003
Posts
241
This PLC code can handle any number of recipes with any number of ingredients, limited only by the PLC memory. It allows the user to enter the recipe number to work with using a C-More panel.



It works just fine from PLC 05 to PLC 260. After performing quite a testing on the code I notice the following:





Once you enter 10 recipes, for example, and decide to go back to recipe #3 and change the values on each of the ingredient then and push “SAVE”, the next recipe that follows, in this case, recipe #4 all the ingredient values changes to “0”. I have no idea why it does that.



Can anyone see where the BUG in this code is?




Here is the code:

PLC 260
// Rung 1
// Address 0
#BEGIN COMMENT
""
"Recipe data area start: V10000"
"Notepad area start: V4000"
"Process variable area start: V3500"
""
""
#END
STR C1
OR X1
GTS K3
// Rung 2
// Address 4
STR C0
OR X0
GTS K1
// Rung 3
// Address 8
STR C2
OR X2
GTS K2
// Rung 4
// Address 12
END
// Rung 5
// Address 13
#BEGIN COMMENT
""
"Transfer data from Recipe area to Notepad"
""
#END
SBR K1
// Rung 6
// Address 15
#BEGIN COMMENT
"Load recipe area pointer and offset value"
"Initialize notepad pointer to beginning of area"
#END
STR SP1
LD V1402
SUBD K1
MUL V1401
BIN
OUT V1403
LDA O10000
ADDB V1403
OUT V1400
LDA O4000
OUT V1405
// Rung 7
// Address 27
STR SP1
FOR V1401
// Rung 8
// Address 30
STR SP1
LD P1400
OUT P1405
INCB V1400
INCB V1405
// Rung 9
// Address 37
NEXT
// Rung 10
// Address 38
RT
// Rung 11
// Address 39
#BEGIN COMMENT
""
"Transfer data from Recipe area to Process area"
""
#END
SBR K2
// Rung 12
// Address 41
#BEGIN COMMENT
"Load recipe area pointer and offset value"
"Initialize process area pointer to beginning of area"
#END
STR SP1
LD V1402
SUBD K1
MUL V1401
BIN
OUT V1403
LDA O10000
ADDB V1403
OUT V1400
LDA O3500
OUT V1406
// Rung 13
// Address 53
STR SP1
FOR V1401
// Rung 14
// Address 56
STR SP1
LD P1400
OUT P1406
INCB V1400
INCB V1406
// Rung 15
// Address 63
NEXT
// Rung 16
// Address 64
RT
// Rung 17
// Address 65
SBR K3
// Rung 18
// Address 67
#BEGIN COMMENT
""
"Write recipe from notepad to recipe data"
""
""
#END
STR SP1
LD V1402
SUBD K1
MUL V1401
BIN
OUT V1403
LDA O10000
OUT V1400
ADDB V1403
OUT V1400
LD Ka
LDA O4000
MOV P1400
// Rung 19
// Address 82
RT
// Rung 20
// Address 83
NOP

#BEGIN ELEMENT_DOC
"C0","Data to NPad","",""
"C1","NPad to Data","",""
"C2","Data to Process","RUN","RUN THIS RECIPE"
"C4","Clear","",""
"C777","DUMMY RELAY","",""
"V1400","Pointer Location","",""
"V1401","#RECIPE INGREDIE","","The number of ingredients in the recipes"
"V1402","RECIPE NUMBER","C-MORE","Selected Recipe Number to:Run, Create or Edit"
"V1403","Recipe Offset","",""
"V1405","NotePad Pointer","",""
"V3500","Process Recipe","",""
"V4000","R_BRAKE PSI","ANALOG OUTPUT","RECIPE:SIGNAL TO VFD TO CONTROL MOTOR FREQUENCY"
"V4001","R_WINDING SPEED","ANALOG OUTPUT","RECIPE:SIGNAL TO VFD TO CONTROL MOTOR FREQUENCY"
"V4002","R_WINDING TURNS","PROXIMITY","RECIPE:TURNS TO FINISH A WINDING JOB"
"V4003","R_CARRIAGE SPEED","STEP MOTOR","RECIPE:"
"V4004","R_CARRIAGE STROK","STEP MOTOR","RECIPE:"
"V4005","NotePad_7","",""
"V4006","NotePad_8","",""
"V4007","NotePad_9","",""
"V4010","NotePad_10","",""
"V5000","Notepad","",""
"V10000","Recipe Data Area","",""
#END

 
Your "Notepad to Recipe Area" subroutine uses a MOV instead of the For/Next you used in the other subroutines. I'd be curious why. Anyway, the other routines will transfer the number of items in V1401 whereas the subroutine K3 will transfer exactly 10 ('Ka') items regardless of the content of V1401. Could that be the problem? V1401 was not initialized to anything (other than 0) in your posted program section. Since you V4000 descriptions have 5 named ones and 5 spares I'm assuming that you have '5' in V1401. That would be a problem. You might want to replace the LD Ka with LD V1401, BIN
 
Last edited:
bernie_carlton:



You are definitely my new hero!!!!



I changed the Ka for a K5 and bingo!!!



Happy Holidays!!!!


THANKS A LOT
 
I don't speak that language but I felt compelled to comment.

If we gave awards for the best example of the power of the internet in general and this site specifically, I would nominate this thread. A detailed questioned answered promptly and acknowledged immediately. Bernie deserves the 'Hero' label and I wish we could award medals. If only a gold star to go with his avatar.

Just a thought,

Brian.
 
I also have had my questions answered very rapidly by the kind professionals who frequent this forum therefore returning the favor is only right. I happen to be on vacation, at home, right now, coffee in hand, but I can't but help going to this site (and the AutomationDirect one) to see if I can pick up any tips to help in my own programming or to help anyone with information I may have picked up (mainly by making every kind of mistake - and having to work them out, mainy in the days before these forums). Lot's of manual reading and re-reading.
 

Similar Topics

Hi. I have a smallish machine on which I want to add internal lighting. My problem is that the available space where I want the lighting is...
Replies
15
Views
5,919
So my company decided to kill Wifi on the shop floor because the mechanics were all watching YouTube or soccer/football games. The factory is...
Replies
15
Views
6,465
Looking for recommendations for a small portable WIFI / Wired Hotspot box thing that I can use when travelling, sort of thing that will allow it...
Replies
14
Views
4,897
hi everyone im using OPERATOR PANEL SPOT PLUS 150 35W 24VDC AUTOMATA ID42003 (as hmi system) and automata optispark controller to control and...
Replies
8
Views
2,408
I just had to replace a SLC 1746-NIO4I analog card that was doing something I have never seen before. Only 1 channel was used, and I tried the...
Replies
12
Views
3,515
Back
Top Bottom