Sign in to follow this  
Followers 0
cafein

How do you replicate a ladder FSC inst. in structured text for SFC application?

10 posts in this topic

Hi! I'm writing a program in RS Logix 5000 for a Contrologix in SFC and I'd like to use as much structured text as possible and keep ladder routines as low as I can. I have to look trough an array of DINT (40) for a specific number and return the position in the array where that number is. I know I can do it through a ladder routine with a FSC instruction but I would rather replicate the fonction in structured text in the SFC routine. Any tips appreciated :) -Olivier /Edit P.S. First Post Edited by cafein

Share this post


Link to post
Share on other sites
A couple of tips. 1. Review all of the ST Functions & commands and read how they work. 2. Verify that the ST functions you want to use work as you think they do, experiment. 3. Use ST as your "specific" or called routines that are used many times and keep LD as your main control program logic. (Those needing to troubleshoot your system will thank you.)

Share this post


Link to post
Share on other sites
Hi, thank you for your time. I am programming the entire process in Sequential Function Chart (SFC) so the logic is pretty straight forward and easy to troubleshoot. I love SFC for that. The sequence is pretty simple so it's easy to follow. Plus, I'm a serial commenter :)

Share this post


Link to post
Share on other sites
Hello, if I'm understand well, you can just create a loop with indirect addressing (DINT have to be in array) something like this: index:=0; i:=0; FOR i:=0 TO 39 BY 1 DO IF array[index]=inumber_to_compare THEN index:=target_pos ; END_IF; index:=index+1; END_FOR; For sure it's just a base and I am not programming in structure text very often so... test it.

Share this post


Link to post
Share on other sites
Hi RH-! That looks like it should work. Should I place an EXIT after line 7 or 8 if I want to return only the first one found? Guess I need to test it. Thank you very much sir.

Share this post


Link to post
Share on other sites
; Ok, if you want to finish, when you find your number, I think this will works fine: index:=0; i:=0; FOR i:=0 TO 39 BY 1 DO IF array[index]=number_to_compare THEN index:=target_pos ; i:=39 END_IF; index:=index+1; END_FOR; You are more than welcome, Radek

Share this post


Link to post
Share on other sites
Thanks again Radek. Let's say I wanted to repeat that function 6 times to 6 different arrays. Can I put a FOR loop inside a FOR loop? Also, will it scan array[0] Edited by cafein

Share this post


Link to post
Share on other sites
Hello, I don't know your all requests but, this will might works too, but you can, at the start, just copy it. I will avoid to have multiple loop at the start when your code is growing, because afterwards is sometimes problem to find your mistakes. (*Field search 1*) index:=0; i:=0; FOR i:=0 TO 39 BY 1 DO IF array1[index]=number_to_compare1 THEN index:=target1_pos ; i:=39; END_IF; index:=index+1; END_FOR; (*Field search 2*) index:=0; i:=0; FOR i:=0 TO 39 BY 1 DO IF array2[index]=number_to_compare2 THEN index:=target2_pos ; i:=39; END_IF; index:=index+1; END_FOR; (*Field search 3*) index:=0; i:=0; FOR i:=0 TO 39 BY 1 DO IF array3[index]=number_to_compare3 THEN index:=target3_pos ; i:=39; END_IF; index:=index+1; END_FOR; (*Field search 4*) index:=0; i:=0; FOR i:=0 TO 39 BY 1 DO IF array4[index]=number_to_compare4 THEN index:=target4_pos ; i:=39; END_IF; index:=index+1; END_FOR; I should browse array[0] as well because index is set to 0 at the start of function.

Share this post


Link to post
Share on other sites
Hi, I was wrong on last post. WHat I actually need to to is compare 6 different values to that same array. Those 6 values themselves are arranged in an array. Here's what I came up with. index1:=0; i1:=0; FOR i1:=0 TO 5 BY 1 DO index2:=0; i2:=0; FOR i2:=0 TO 39 BY 1 DO IF array[index2]=number_to_compare[index1] THEN index2:=target_pos[index1] ; i2:=39; END_IF; index2:=index2+1; END_FOR; index1=index1+1; END_FOR;

Share this post


Link to post
Share on other sites
Ah, OK, I think that this gonna work. Good. :o)

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