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.

New Here? Please read this important info!!!


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

Reply
 
Thread Tools Display Modes
Old June 4th, 2021, 02:24 AM   #1
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
Help writing plc code for a bag filling process

Hello,

i am currently trying to create a plc programme from my Tia portal v16 for a package filling machine. But i am kinda new to the plc stuff so i need aid. Here's the process. I have the logic made up on my mind but i am not really good at plc stuff.

Here are the Components,
Package sensor = S1
scale piston sensor= S2
valve piston sensor= S3
valve piston = P1
scale belt piston= P2
Package feeder line motor= M1
scale Motor = M2
Material feeder motor = M3
Loadcell Transmitter(Rs485 Modbus connection) with a loadcell connected to it = LCT

Firstly there is S1 which is package sensor(this will look for a package), if it is 0(doesnt see a package) plc will turn our P2(Scale belt piston),M2(Scale motor) and M1(Package feeder line motor) values to 1. That means if there is not package seen by the sensor we will start feeding system packages.

After we start feeding our system packages our S2(scale piston sensor) will have to be 1 because there is a package coming but if somehow it is 0 then we will give an error because it shouldnt be like that.(Just go with me on this one i know it has a lot of holes ) Now that our packages are coming our S1 should be 1 because it sees the package.

Now that our S1 is finally 1 we will look for the S2 and if its 0(which it shouldnt be) it will give us the same error. If its 1 then we will go on to our we will calibrate our scale(loadcell). After its done calibrating we will start our M3(feeder Motor) and P1(valve piston) will turn to 1(we can do a double check on S1(package sensor)here because if it doesnt see the package than whats it gonna drop on eh? and if its not 1 we can give an error). after our double check on S1 we can finally look at the scale.

Now if our scale is showing 0 after all that stuff we did it will turn back and open P1 and M3 again to fill and check again for S1 just in case. Now that our materiel is going in to the package and the scale is not 0 we will let it fill but when it comes to say %90 we will start to slow the motor according to the increase of weight, if the weight increases really fast than we will slow our motor really fast but if its filling slowly we will not get in the way since its not increasing to fast. We do this in order to get a solid set value. Usually it will be 10Kg but 10005 or 9995grams is fine aswell.

After we are done with filling process we will turn our P1 and M3 values to 0 since we are done with filling but we will check our S1 again just to make sure and if its 0 again we will give another error. If our S1 is still 1 then we will move our box by turning our P2, M2 and M1 1 again and it will go away. And then we will again lor our S1 and start the whole process over again.

This will be a loop. One box will be coming while other is going away. And whole process will start again.

Now i want to make completely customizable. I can change my set value for weight and all.I want to add in a manual and an automatic option. Now in Automatic option this whole process will be done by itself but in manual option i want to just put everything there and it will be like Start M1, Stop M1, Start M2, Stop M2, Start M3, Stop M3 and so on.

I want to make the programme self-learn on filling process. If its filling too fast than programme will just adjust itself to get more accurate values and slow the motor down. Something like that.

Can anyone help me out with this?

I am planning this for myself as a self-project kind of thing.

I am currently planning to use Tia Portal since thats what im kind of know my way around there.

What plc i will be using ? i do not know. But i would love your recommendations. My biggest issue rn is the code. It seems like i want a lot but i want to do this and i would really like your help. Since i am a newbie in these things i would like someone to hold my hand through this time. Thanks everso
  Reply With Quote
Old June 4th, 2021, 05:52 AM   #2
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 3,225
The best thing is to start & write some code & test it in a simulator.
I would suggest using a sequence so you have a sequence integer variable that when it is 0 the process is idle, write down the exact steps (bearing in mind some steps may overlap) what i mean is between steps 4 & 6 a particular operation will happen not just on step 4.
or you could use step flags (internal memory bits for each step).
I like using a sequence variable & each step is an increment of 10 (this allows for extra steps to be added if required). See attached for a simple traffic light program, although in this instance have used steps by 1 not 10 but is the same principle, it definitely makes sense to use increments of 10 plus so in the event of needing an extra step it can be added with little extra work.
The principle is simple a logic condition i.e. a bag entering the load area (photocell etc.) plus all other operations are in starting position moves a value say 10 into the sequence variable, the next rung checks what the next operation should be i.e. piston forward or a timer to allow something to happen, this then moves 20 into the sequence variable & so on.
The motors/valves/solenoids etc. are then driven off these values using compares (note some have multiple compares because they may operate on more than one step.
This was not done in TIA but as it is IEC FBD standard I'm sure you can work it out, you already have the sequence of events as you see them just tie them to values.
The first thing to do is assign inputs/outputs to the sensors/actuators (for trial purposes you could just use internal bits & words & also write an extra block of logic to simulate that way you do not use any actual inputs/outputs. then just re-map them when trying the plant.
What I often do is have a separate block of code that copies the inputs to internal bits & internal bits to outputs, do not call the blocks and just use the "mapped" bits in the code, create another block of code to simulate i.e. for the weight just increment the value in the weight variable when it is on the sequence number that does the weighing.
Example of mapping
I0.0-I0.7 is mapped to M0.0 to M0.7 so if for example I0.0 was sensor 1 then I would give it a comment (symbol) of PEC01_Bag_Pos_I the mapped bit used in the logic would have a symbol of PEC01_Bag_Pos_M this goes for the outputs as well but mapped in the opposite direction.
Example of mapping code:
I0.0
---| |-----------( ) M0.0

M10.0
---| |-----------( ) Q1.0

So in effect you have a number of blocks of code
Input & output mapping
Actual code
Simulation code
while simulating you disable the calls to the input & output mapping
and enable calls to actual code & simulation
On completion of testing you enable the input/output block(s)
and disable or remove the simulation block.
I prefer to use the plc code to do the simulation rather than rely on the simulator to do it as I find it's more flexible & most simulators do not simulate things like analog or special communication cards.
Just read your post again & it seems you will need an HMI to be able to set certain parameters like fill weight, in-flight (slow fill set point) & some manual controls.
Again quite simple to do, however, automatic adjustment can be a little trying, for example if the weight is outside your limits then auto adjustment must be limits to how much this adjustment will allow & then alarm if it goes outside.
Here is a simple sequence for example:
Step 0: Idle
Step 10: Start button pressed (if in auto), S1 is off so start feeding (P2,M2,M1), also if timeout i.e. not S2 then alarm etc., wait for s1 & s2 both on jump to step 20
Step 20: Calibrate scale, if calibrated (I assume you mean tare) then jump to step 30
...... and so on
Attached Files
File Type: pdf Traffic lights1.pdf (81.1 KB, 16 views)

Last edited by parky; June 4th, 2021 at 06:25 AM.
  Reply With Quote
Old June 4th, 2021, 06:09 AM   #3
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
i did write some code rn but i dont know how to send a pdf of it here, can you help me?
  Reply With Quote
Old June 4th, 2021, 06:42 AM   #4
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 3,225
You need a PDF writer (win10 has one) just print the code to the pdf (limit size is 300k) so it is best not to print out all the whole lot just the code sheets & if you look below the reply box press button to attach files & upload it
Attached Images
File Type: png posting files.png (276.6 KB, 188 views)
  Reply With Quote
Old June 4th, 2021, 08:12 AM   #5
Ken Moore
Lifetime Supporting Member
United States

Ken Moore is offline
 
Ken Moore's Avatar
 
Join Date: May 2004
Location: North, West, South Carolina
Posts: 3,099
TIA portal has SFC's, might be worth a look.
__________________
Certified Siemens Functional Safety Professional,
ID: SFSP17010238
https://azr.com/
  Reply With Quote
Old June 4th, 2021, 08:29 AM   #6
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 2,826
Quote:
Originally Posted by thewalkerist View Post
(Just go with me on this one i know it has a lot of holes )
We are fine with the holes; the process and PLC will most definitely not be fine with the holes.

The holes must be removed. For example:

S3 sensor

This is defined in the I/O list, but never mentioned in the process.

Step "10"


Quote:
Firstly there is S1 which is package sensor(this will look for a package), if it is 0(doesnt see a package) plc will turn our P2(Scale belt piston),M2(Scale motor) and M1(Package feeder line motor) values to 1. That means if there is not package seen by the sensor we will start feeding system packages.
My understanding, which is probably flawed, from this and the I/O list is that there are
  • a package sensor, S1, upstream of the scal belt piston
  • a package feeder, probably a belt conveyor, driven by output M1,
  • and a scale belt(?) piston, driven by P2, that pushes a package either onto the scale, or onto a belt that moves a package to the scale,
  • and a scale (belt?) motor, driven by M2, that is somehow involved with the scale.
However, the description says all three of these, including P2 the scale belt piston, should be running during the first step when S1 is 0 i.e. no package is sensed. The confusing part to me is that P2 is 1, activating the scale belt piston, when there is no package (S1 is 0). It seems to me that this is actually two steps:
  • The package feeder runs until S1 is 1, which means a package is in front of the scale belt piston
  • After S1 is 1, then P2 is assigned 1 to make the scale belt piston push that package onto or towards the scale.
This may not be a problem at all, and is most likely due to my misunderstanding the process.

Step "20"


Quote:
After we start feeding our system packages our S2(scale piston sensor) will have to be 1 because there is a package coming but if somehow it is 0 then we will give an error because it shouldnt be like that.(Just go with me on this one i know it has a lot of holes ) Now that our packages are coming our S1 should be 1 because it sees the package.
When I read this and other parts of the description, it sounds like whenever S1 is 1, then S2 should also be 1, with no delay, otherwise there is an error. But I would expect there to be some delay from when S1 changes from 0 to 1, to when S2 changes from 0 to 1. Again, this may be due to my misunderstanding the process, but even if that is true in the process, there could be brief delays between when each sensor become 1. Since the PLC program will operate at ms timescales, there could be a scan when S1 is 1 and S2 is 0.

Epilogue


It is most likely that I am misinterpreting the process. For example, perhaps package sensor (S1) is at the end of the scale belt piston (P2) throw, so S1 will not become 1 until after the scale piston sensor (S2) is 1.

Also, there are two times in the description where P2 is assigned a 1, but there is no description of when, in between those times, when it was assigned a 0.

Anyway, my point is that the process has to be nailed down in as much detail as possible; this will likely involve more steps than are in the existing description. Then code the PLC using @parky's approach (the traffic light PDF provides a simple but perfect example) with a few sections:
  • one section that deals with the transitions (step changes from 0, to 10, to 20, to 25, etc., based on sensor states
  • one section that handles states the outputs at each step
  • perhaps a special section that detects, and responds to, errors.
The Auto/Manual operation is straightforward: either put a test (contact) for Auto at the front of each rung that does a step transition, or simply set the step to 0 (Idle) if in Manual after all of the step transition rungs.
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old June 4th, 2021, 08:30 AM   #7
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 2,826
Quote:
Originally Posted by ken moore View Post
tia portal has sfc's, might be worth a look.

^^^ +1
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old June 4th, 2021, 11:04 AM   #8
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
ok so i am sorry, because it seems that i have caused some misunderstandings, I will try to explain more.

S3 Sensor

Now i am still thinking about this guy. So this is a bit problematic. We can just get rid of it. I've put that when i was thinking about it at first but now i am removing it. Maybe after i've put some more thought into it i will come up with a S3 sensor.


Step "10"

Quote:
a package sensor, S1, upstream of the scal belt piston
a package feeder, probably a belt conveyor, driven by output M1,
and a scale belt(?) piston, driven by P2, that pushes a package either onto the scale, or onto a belt that moves a package to the scale,
and a scale (belt?) motor, driven by M2, that is somehow involved with the scale.
These are correct assumptions.

Quote:
The package feeder runs until S1 is 1, which means a package is in front of the scale belt piston
After S1 is 1, then P2 is assigned 1 to make the scale belt piston push that package onto or towards the scale.
That is a quite correct assumption aswell i am sorry i wasnt able to explain more about this but you've got it all correct.

Step 20
Quote:
When I read this and other parts of the description, it sounds like whenever S1 is 1, then S2 should also be 1, with no delay, otherwise there is an error. But I would expect there to be some delay from when S1 changes from 0 to 1, to when S2 changes from 0 to 1. Again, this may be due to my misunderstanding the process, but even if that is true in the process, there could be brief delays between when each sensor become 1. Since the PLC program will operate at ms timescales, there could be a scan when S1 is 1 and S2 is 0.
You are correct here as well but to counter this problem i want to put in timers for example 10 seconds or something like that according to my preferences. If its not seeing them as 1 when the time comes then that means there is probably a problem. Instead of an error, maybe i can set up a notification that tells to the operator thats running the hmi "Hey, there hasnt been a package since 10 seconds, do something"This way i will hopefully counter any problems that this may cause. I am still in the thought process of this as well.

Quote:
Also, there are two times in the description where P2 is assigned a 1, but there is no description of when, in between those times, when it was assigned a 0.
Now this is completely my mistake. P2,M2 and M1 can be set to 0 after we see our package with our S1 sensor. That way we can solve the problem. Because you are right, if i dont put a stop command to these then these guys would be bringing boxes non-stop and whole process could be up in smokes.

I would like to apologize to all of you good people for not informing you all well. The reason for this is i am completely alone in this project(its a self managed project) i am a mechanical engineer who wants and tries to do these stuff. I am learning as i go along and you guys keep teaching me. I am making constant decision changes but your opinions here value too much to me, i will try to make myself more clear from now on.
  Reply With Quote
Old June 4th, 2021, 11:13 AM   #9
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
Biggest problem that i currently see in my head is that, how will i make the programme self-learn? or rather than self-learn i would like to ask you beautiful people how would i control the speed.

For example when my M3 drops materials from the conveyor belt my weighing values increases. Lets say my capacity is 10kgs.

When it comes to %95(9500g) my motor will slow down according to the increase of weight. For example if it increases slowly the motor will go faster but when it increases rapidly the motor will slow down.

How can i make that logic in my plc? Or can i even? I mean i can imagine other parts in code but i cant even imagine this one

Oh and btw i will drop my step code soon and we can discuss about it more than.

Thank you all for your help again.

Last edited by thewalkerist; June 4th, 2021 at 11:18 AM.
  Reply With Quote
Old June 4th, 2021, 11:15 AM   #10
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
Quote:
TIA portal has SFC's, might be worth a look.
i've dabbled with SFC's before, i really am not good there . Maybe in future when have more knowledge about SFC's and programming my plc i will try it but currently FBD seems like the best choice. I've tried it with LAD but its not really good for this process i think. It seems doable but it seems it is easier on FBD you know?

Thanks everso for your sweet comment .
  Reply With Quote
Old June 4th, 2021, 12:29 PM   #11
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
I've written down without a sequence. I wanted to do it but i dont know how to. If you guys help how to do it in Tia portal i can, its not the same in parky's light system
Attached Files
File Type: pdf Trial.pdf (237.4 KB, 18 views)
  Reply With Quote
Old June 4th, 2021, 12:37 PM   #12
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 2,826
Quote:
Originally Posted by thewalkerist View Post
I would like to apologize ...

No need to apologize! Communication is one of humankind's biggest problems, and this forum is perfect for making corrections and adjustments on the fly, always getting closer and closer to understanding each other and the process.


Writing, or more accurately, developing, the program will be much the same way. An "Agile" approach is fairly effective, where we start with things we know and code for them, and then in the act of doing that we find out more about the process, which informs us what to do next.


Quote:
... I am making constant decision changes ...

Perfect! That is the one of the keys to Agile!


This is a simple problem, but still interesting. I hope you will be able to upload the final result to the downloads area of this site so future users can benefit from the work.
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.

Last edited by drbitboy; June 4th, 2021 at 12:42 PM.
  Reply With Quote
Old June 4th, 2021, 12:50 PM   #13
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
Quote:
I hope you will be able to upload the final result to the downloads area of this site so future users can benefit from the work
If i could finish this i would definetly do it . With your help i will be able to finish this tho i think

Last edited by thewalkerist; June 4th, 2021 at 12:54 PM.
  Reply With Quote
Old June 4th, 2021, 01:18 PM   #14
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 2,826
Can you control the speed of the material feeder motor? I.e. is M3 a discrete output or an analog output (e.g. 0-10V or 4-20mA)?


If M3 a discrete output then you may have to pulse it. e.g. let it run until somewhat full (say 80% or90% of target weight). Then run for 3s at a time, weighing after each stop, until it is at 97% full. Then run it for 1s at a time. Etc. Or you could use PWM, although I don't know if that is good for the motor.


If M3 is an analog output, then you would want to run it at variable rates e.g.
  • 100% speed until somewhat full (e.g. 80% target weight)
  • Scale the speed from 100% to 0% (or minimum running) between somewhat (80%) and overfull (e.g. 102%)
  • Stop the motor and close the P1 valve when it hits full (e.g. 99.x% of target)
  • Those values "somewhat full," "overfull,", "full," would be found by trial and error. A lot would have to do with the dynamics of the scale measurement while filling, what accuracy is acceptable, how long is acceptable, etc. The percentages could be set from the HMI and vary by material. The reason overfull is more than 100% is otherwise it will take infinitely long fill to the target.
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
  Reply With Quote
Old June 4th, 2021, 01:34 PM   #15
thewalkerist
Member
Turkey

thewalkerist is offline
 
Join Date: May 2021
Location: Izmir
Posts: 42
M3 will have its own speed controller so it will be analog i believe.

Is there a way for me to scale the speed? like a scale block i use in weighing?

For example i use Norm_x and then Scale_X and put these guys in a function then call the function and put in my InputMin(4000) and InputMax(20000) values and then ScaledMin(0kg) and ScaledMax(100kg) and then just put a InputValue(Val1) and just get the weight info from there.

Lets say i did the same with my speed on my motor and scale my speed according to my weight value? is that possible? if so can you do me a favor and put up a mini logic pdf or png or something like that?
  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 01:41 PM
PC to PLC Protocol TheRixta LIVE PLC Questions And Answers 13 December 17th, 2008 01:56 PM
transfer data code from pc to omron plc ahmed yousri LIVE PLC Questions And Answers 0 March 13th, 2008 08:42 AM
Automatin Direct Changes Download ArikBY LIVE PLC Questions And Answers 53 May 12th, 2004 01:05 AM
Real World Problem Vietnam Bob LIVE PLC Questions And Answers 8 November 23rd, 2002 03:03 PM


All times are GMT -4. The time now is 12:52 AM.


.