Sign in to follow this  
Followers 0
pklok

Structured Text Help

14 posts in this topic

I while make a funcionblock in Structured Text If i push the first time input 1 output1 = true next time output2 is also true to output 10 how do i write it ? please help

Share this post


Link to post
Share on other sites
Why complicate things, just use the SFT and shift a 1 in every time. Then use a MOV #0 to reset the word......two rungs of code...... I am sure old BobB has a smirk on his face.....

Share this post


Link to post
Share on other sites
I agree with sleepy. To write a Structured Text Function Block for your task you would be writing a lot of code, and possibly would still require ladder code to make it work. I will assume you have no VB / C / C++ / etc.. experience, so I think you will be spending a lot of extra time trying to get this to work that would be wasted. To get you started though, try something like this: Variables: input, bool (input) reset, bool (input) i, int, retained (internal) output1, bool, retained (output) output2, bool, retained (output) output3, bool, retained (output) output4, bool, retained (output) output5, bool, retained (output) output6, bool, retained (output) output7, bool, retained (output) output8, bool, retained (output) output9, bool, retained (output) output10, bool, retained (output) _________________________________ if reset = true then     i = 0; if input = true then     i = i+1; case i of 1: output1=true; 2: output2=true; 3: output3=true; 4: output4=true; 5: output5=true; 6: output6=true; 7: output7=true; 8: output8=true; 9: output9=true; 10: output10=true; (this code has not been tested)

Share this post


Link to post
Share on other sites
What would make you think that Sleepy? I may be using FB on a project I have just picked up. Lots of alarms all the same format, just different I/O. Finally found a project where I can use it. That will probably put a smirk on your face Sleepy.

Share this post


Link to post
Share on other sites
... FB's or not FB's .... FB's may be the way, don't forget though that ladder code using index/data registers and a for next loop can often handle this type of application nicely!! (and efficiently) FB's do make it easier to view the state of inputs and outputs when online. I recently used an ST FB to calculate the distance between two rotating and telescoping machines (anti collision), ST was great for the trig and math, and FB nesting was handy too!! ... have fun Bob... NIBROC

Share this post


Link to post
Share on other sites
i have make this now and it's working if reset = true then i := 0; output1 :=false; output2 :=false; output3 :=false; output4 :=false; output5 :=false; output6 :=false; output7 :=false; output8 :=false; output9 :=false; output10 :=false; END_IF ; if input = true then i := i+1; END_IF ; case i of 1: output1 :=true; 2: output2 :=true; 3: output3 :=true; 4: output4 :=true; 5: output5 :=true; 6: output6 :=true; 7: output7 :=true; 8: output8 :=true; 9: output9 :=true; 10: output10 :=true; END_CASE ; if i = 10 then i := 0; END_IF ; if i > 0 then y := 0; END_IF ; if reset = true then y := 0; END_IF ; if input2 = true then y :=y+1; END_IF ; case y of 1: output1 :=false; 2: output2 :=false; 3: output3 :=false; 4: output4 :=false; 5: output5 :=false; 6: output6 :=false; 7: output7 :=false; 8: output8 :=false; 9: output9 :=false; 10: output10 :=false; END_CASE ; if y = 10 then y := 0; END_IF ; if y > 0 then i := 0; END_IF ; thanks for help

Share this post


Link to post
Share on other sites
For the above..... In Mneumonics LD P_On @LD 0.01 LD 0.00 SFT (010) 10 10 Or see screen grab below... Now what was simpler.... It took me way longer to write this response then it did to code this in ladder ....!!!!!

Share this post


Link to post
Share on other sites
Ladder, in this case, saves a lot of typing does it not Sleepy? Horses for courses. A simple reset on the shift register would do. Use them all the time. Edited by BobB

Share this post


Link to post
Share on other sites
I am looking at your code pklok, and I am concerned about this: if i = 10 then i := 0; END_IF; Does your output 10 turn on?

Share this post


Link to post
Share on other sites
But does a ST FB work like normal programming code or like PLC ladder? Normal programs complete everything from line one before moving to line two. PLC Ladder reads Line one, then reads line two, then executes the combined changes simultaneously.

Share this post


Link to post
Share on other sites
Not quite sure what you are saying here Chris, I always thought that the Ladder would scan line 1 (Rung 1 - whatever), and then perform any action therein. Then it would move to the next rung, resolve the ladder and again perform any required actions. e.g. LD 0.00 OUT 0.01 at this point in the scan, if 0.00 is true, then 0.01 will be on LD 0.02 OUT 0.01 at this point in the scan, if 0.02 is true, then 0.01 will be off END Once all of the rungs have been scanned / resolved and actioned, then would come the IO refresh. This being the actual physical IO points. Anywhoo, the ST is compiled into exactly the same PLC object code (pretty much) that is generated when ladder is compiled. Hope this is sort of clear Regards anonymous

Share this post


Link to post
Share on other sites
I love this forum.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0