News:

  • June 09, 2026, 03:30:47 AM

Login with username, password and session length

Author Topic: Program critique...  (Read 13255 times)

Al A

  • Newbie
  • *
  • Posts: 3
Program critique...
« on: October 30, 2008, 06:25:20 PM »
Hi all,
 Firstly, I realize this forum seems to focus on the DS software and what follows is more "general PLC" stuff. If this is inappropriate here, feel free to direct me to a more appropriate forum. (Thanks!)

 Anyhow, I am just getting into the whole PLC thing. I am doing a project at work that involves some automation, and this seems to be the best way to go about it. I have some time that I am using to get up to speed on all of this. I have some programming experitnce, but that was some time ago and mostly machine language on microcontrollers. I have some long-ago familarity with ladder logic, but that was with very simple (and old) systems, and was implemented using real relays, timers, etc.

 I will be using an AD DL06, which is a bit of overkill for the application, but not much and it will allow for future upgrades and the feature expansion that tends to happen on these sorts of projects. I have the PLC at my desk and have been fooling with it and the DS5 software for a bit. I am planning to use the stage programming approach and have been reading and studying a bit about that. In the AD manual for the DL06, there is a good tutorial on the subject. The example they use is a garage door opener (page 7-8 of volume 2 in the DL06 manual). I thought it might be a good mental exercise to try to work out a program to implement the same garage door functions using "regular" ladder logic  before delving into the whole Stage programming concept. Mostly to see if I could.

 I have exported the program and it is pasted below. It works as it should, which was pretty satisfying once I got that far. What I would appreciate is if any of you pros, gurus, and mavens could critique my program a bit. Maybe point out what could have been done better, easier, simpler, faster. What about my program might indicate that it was written by a beginner? Am I overlooking anything?
Comments or criticisms, please? Thanks for any insight!

-Al

*******************Program follows************************************************
PLC 06

// Rung 1
// Address 0
#BEGIN COMMENT
"Rung opens the door when the button is pushed, "
"assuming the door starts from a fully closed position."
"if the door is neither fully opened or closed, it opens"
"X3 is a photocell safety switch"
#END
STR X0
AND X2
STR X0
ANDN X2
ANDN X1
ORSTR
OR C0
ANDN X1
ANDN C1
STR X3
AND C1
ORSTR
OUT C0

// Rung 2
// Address 13
STR C0
OUT Y0

// Rung 3
// Address 15
#BEGIN COMMENT
"Rung lowers the door when the button is pushed, "
"assuming the door starts from a fully open position."
#END
STR X0
AND X1
OR C1
ANDN X2
ANDN C0
OUT C1

// Rung 4
// Address 21
#BEGIN COMMENT
"This rung keeps the light on for 15 seconds after the door opens or closes."
#END
STR C1
OUT Y1

// Rung 5
// Address 23
STRND C0
ORND C1
OR C2
ANDN T0
OUT C2
TMR T0 K150

// Rung 6
// Address 31
#BEGIN COMMENT
"rung turns on lamp when door is opening or closing, and To keeps it on for 15 seconds "
"after the door stops moving."
#END
STR C2
OR Y0
OR Y1
OUT Y7

// Rung 7
// Address 35
END

// Rung 8
// Address 36
NOP


#BEGIN ELEMENT_DOC
"UB0","x0","",""
"UB1","to","",""
"X0","Operator button","",""
"X1","Up limit sw","",""
"X2","Down limit sw","",""
"X3","Safety switch","",""
"Y0","RAISE DOOR","",""
"Y1","LOWER DOOR","",""
"Y7","LAMP","",""
"TA0","light","",""

#END


 

 

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Program critique...
« Reply #1 on: October 31, 2008, 09:20:30 AM »
You'll get some feedback here, but you should also post it on AutomationDirect's forum http://forum.automationdirect.com/, probably under General Applications category.

There is more traffic there, so more eyes, and more comments, will be had.

Al A

  • Newbie
  • *
  • Posts: 3
Re: Program critique...
« Reply #2 on: October 31, 2008, 02:51:45 PM »
Thanks, I appreciate the suggestion. I'll try that.
I appreciate your taking the time to reply.
Al

milldrone

  • Full Member
  • ***
  • Posts: 48
  • I'm changing my attitude to thumbs up
Re: Program critique...
« Reply #3 on: November 01, 2008, 09:05:47 AM »
Al,

I did not see a post over at the AD forum so I'll reply here.

I had a little trouble importing your program monics because of the
"UB0","x0","",""
"UB1","to","",""
in the documentation area.

I only saw two/three things that could be construed as a possible programming style vs correctness thing.
1. You could replace every instance of "C0" with "Y0", and delete rung #2
2. You could replace every instance of "C1" with "Y1", and delete rung #4
3. Most of the control people I have been in contact with would wire the door limits so they were on when the door was midway, and off when the door was at it's limits. The reason for this is: if there was a wire break the door would not go beyond it's limit. 

Other than these nit pickey things your program passed the most important test of all, it worked. 
Vaughn

Al A

  • Newbie
  • *
  • Posts: 3
Re: Program critique...
« Reply #4 on: November 01, 2008, 12:29:02 PM »
 Thanks for the reply. I had not gotten time to try posting this at the other forum yet, but will shortly.

 I'm not sure what is up with the monics, I am pretty sure they were just as DS5 exported them.

Thanks for those observations, not nitpicks at all.  That is precisely the sort of input I am looking for.
Wiring the limit switches to open at the limits is an excellent suggestion. Not that I am REALLY building a garage door opener,
you know, but that is a handy bit of design philosophy.

 I'll take a look at renaming the C0's and C1's and thus saving a couple of rungs. I "Might" have to look at what I was thinking
when I took that approach. I seemed to be over complicating things for some reason.

 Thanks again for taking tthe time to look this over and offer your suggestions. Most appreciated!

-Al

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Re: Program critique...
« Reply #5 on: November 02, 2008, 12:41:11 AM »
The strange entries are unassigned nicknames. Most troublesome is that X0 is defined as a nickname....which probably wasn't what you intended. Those will need to be assigned to actual image register locations.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO