Please help me to rewrite the code

backendcode

Member
Join Date
Aug 2017
Location
brampton
Posts
249
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!
 
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?
 
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
 
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.
 
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:
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.
 
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 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
 
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.
 

Similar Topics

Please help me, I have solve many week but still not solve it. I found trouble of factory talk studio when I set tag by browse address of OPC...
Replies
0
Views
80
Hello Everyone, i Have im my Industry a Endress & Hauser Promag400 this has a screen that constantly have that error, it says to wait, somebody...
Replies
2
Views
427
After replacing the 70 with the 525, the PLC can read from the drive and recognizes it as online, but no commands are being listened to. PLC is...
Replies
1
Views
493
To quickly test a plc output which is wired to a relay do I dob a cable between the output and 24vdc+ source I.e something with 24vdc+ live such...
Replies
6
Views
629
"Hello, I am a beginner learning about PLC. Could you please give me some advice? I want to write PLC instructions as follows: When the sensor...
Replies
18
Views
3,233
Back
Top Bottom