You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old October 12th, 2017, 07:04 AM   #1
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 155
Please help me to rewrite the code

Good Morning everyone,

I need your help to rewrite the code or better way to write the code because honestly I didn't like how the code is right now and I know there can be a better way to write this code.

Project, This is working conveyor project PLC code and link to the PLC code is below.

https://ibb.co/ent6Tw

there are three conveyors and each conveyor has motor and prox sensor on it and I want to turn on the motor in the following condition.

Conveyor 1 conveyor 2 conveyor 3 MOTOR ON

1 (Part present) 0 (No part) 1/0 (Part/NO part) Motor 1 ON

1 (Part present) 0 (No part) 1/0 (Part/NO part) Motor 2 ON

1/0 (Part/No part) 1 (No part) 0 (Part/NO part) Motor 2 ON

In other words, when part present on conveyor 1 and no part present on conveyor 2, motor 1 and 2 will ON and sensor 2 on conveyor 2 will turn off both motor. (move part from conveyor 1 to 2)

When part present on conveyor 2, no part present on conveyor 3, it will turn on motor 2 (move part from conveyor 2 to 3)

I would like to use equ and great than equal to instruction but I think bool data type is not allowed to compare the source value to a destination. is there any way I can do it?

Thank you!
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old October 12th, 2017, 07:14 AM   #2
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SE Michigan
Posts: 2,955
Link is no good, sorry.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen
  Reply With Quote
Old October 12th, 2017, 07:18 AM   #3
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 155
please see the attached image!

Thank you!
Attached Images
File Type: jpg test.jpg (36.5 KB, 163 views)
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old October 12th, 2017, 07:23 AM   #4
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 350
What don't you like about the current code? Is it functioning properly and you just don't like its organization? Or is it not working correctly?
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Old October 12th, 2017, 07:27 AM   #5
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 155
Quote:
Originally Posted by LoganB View Post
What don't you like about the current code? Is it functioning properly and you just don't like its organization? Or is it not working correctly?
It is working correctly but the code looks so messy and I want to write in a more organized way because if someone has to maintain it, it would be easy for the person and I am leaving this workplace very soon so whoever will maintain this code. I want to make his/her life easy!

You know what I mean!

Thanks
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old October 12th, 2017, 07:43 AM   #6
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SE Michigan
Posts: 2,955
Quote:
Originally Posted by backendcode View Post
It is working correctly but the code looks so messy and I want to write in a more organized way because if someone has to maintain it, it would be easy for the person and I am leaving this workplace very soon so whoever will maintain this code. I want to make his/her life easy!

You know what I mean!

Thanks
Looks organized, nice job! Except (and this is big for me). You need to fill in the descriptors on every tag and you need to comment all rungs of what the rung is trying to do.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen
  Reply With Quote
Old October 12th, 2017, 07:50 AM   #7
backendcode
Member
Canada

backendcode is offline
 
Join Date: Aug 2017
Location: brampton
Posts: 155
thank you but I am not satisfied :/

What do you think about the code i just rewrite. Pic attached!
Attached Images
File Type: jpg more_organized.jpg (34.1 KB, 152 views)
__________________
Junior Control Engineer
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
  Reply With Quote
Old October 12th, 2017, 07:52 AM   #8
PLCnovice61
Member
Australia

PLCnovice61 is offline
 
Join Date: Apr 2015
Location: home
Posts: 93
With only showing limited code.
Do you have an over riding stop circuit?
If you are worried about the next lot of people that are going to maintain it, wouldn't you, if you looked at the snippet, like to see some comments to assist other people to work out how it operates?
You just updated the pic while posting this, but what l say still stands

Last edited by PLCnovice61; October 12th, 2017 at 07:54 AM. Reason: reposted
  Reply With Quote
Old October 12th, 2017, 07:57 AM   #9
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 350
I can suggest a couple of things. You might want to add descriptions to some of those bits. For instance, "Line_2_Running_Bit", is this monitoring the MCR for the line? Or is it an Auto Mode flag? Try to make it so that people could understand exactly what each instruction is doing without seeing the machine the run.

The code itself isn't overly complex. If you clarify what everything is doing I think you'll be ok. Don't be afraid to document too much. Use rung comments and descriptions whenever you can.
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Old October 12th, 2017, 07:58 AM   #10
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 350
Haha they beat me to it.
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Old October 12th, 2017, 07:59 AM   #11
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SE Michigan
Posts: 2,955
Are you using a MOV instruction to write to an boolean? Its not equivalent to an OTE and it will confuse anyone following you later. Put it back and annotate as I suggested.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen
  Reply With Quote
Old October 12th, 2017, 08:00 AM   #12
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 350
You don't usually see people use MOV statements when dealing with boolean addresses, so that might confuse some people. No real reason to use a MOV when you have OTEs and OTL/OTUs
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Old October 12th, 2017, 08:00 AM   #13
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 350
too slow again
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Old October 12th, 2017, 08:01 AM   #14
jstolaruk
Member
United States

jstolaruk is offline
 
Join Date: Dec 2004
Location: Detroit, SE Michigan
Posts: 2,955
You're trying to get fancy and many new programmers fall victim to that desire. K. I. S. S. should be your motto.
__________________
"You can live to be a hundred if you give up all the things that make you want to live to be a hundred." Woody Allen
  Reply With Quote
Old October 12th, 2017, 08:40 AM   #15
Mispeld
Member
United States

Mispeld is offline
 
Join Date: Feb 2017
Location: VA
Posts: 164
Quote:
Originally Posted by jstolaruk View Post
You're trying to get fancy and many new programmers fall victim to that desire. K. I. S. S. should be your motto.
IMHO and experience, the original code is more mainstream with respect to starting and stopping conveyor motors.

That said, there seems to be redundancy with the timers and stop/start logic. For example, the stop bits may not need to be on both the timer and OTE instructions. I cannot say for sure without knowing whether the timer bits are used elsewhere in the program.

My advice would be to consider the purpose of the timer, and limit its precondition to just those aspects that you want to delay. For example, is it just sensor response time ("de-bounce"), or does it include startup/run time of a downstream conveyor? Then use that .DN bit, latched and unlatched as necessary, to energize the OTE. Again, in this example, the stop bit would unlatch the OTE, but not be part of the timer, unless the timer is used elsewhere.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
test the RSLogix500 code matches with PLC ?? leonlai LIVE PLC Questions And Answers 11 June 29th, 2011 12:41 PM
transfer data code from pc to omron plc ahmed yousri LIVE PLC Questions And Answers 0 March 13th, 2008 06:43 AM
Sub-routines - general question burnerman LIVE PLC Questions And Answers 25 March 2nd, 2006 09:56 PM
Protecting my code in Koyo products jimpad LIVE PLC Questions And Answers 12 September 4th, 2004 11:07 AM
How to simulate a FOR..NEXT loop? New2PLCs LIVE PLC Questions And Answers 26 May 9th, 2002 12:36 PM


All times are GMT -5. The time now is 09:47 AM.


.