FSC issues

Thanatos

Member
Join Date
Jan 2024
Location
Washington
Posts
6
I am trying to use the FSC to count how many numbers in my real array are less than a certain value but not sure why I cant for the life of me get it to work. I have the .IN actuating the counter and an unlatch on itself but it won't actually increment. any ideas?
 
Does it count the first number? If so, are you re-triggering the instruction after clearing .IN?

You'll likely get further if you post your actual logic (a pic of the rungs, for example) so we can see how you're trying to do it.
 
have to blur out some things for legal reasons but this is what I have so far going to eventualy put another bit with the test 9 bit to re run if it doesnt find a match.

********.jpg
 
basically I am going to end up triggering an alarm if more than x number of values are less than another value but I can never get it to actually increment my counter
 
A CTU (or CTD for that matter) needs to see a false-to-true transition on its input. Yours is not doing so -- .IN is true, then you reset it, but before the scan reaches that rung with .IN false the FSC sets it to true again. The counter never sees it false until the whole array has been scanned when it will stay false.

Put simply, unless you manipulate the counter's internal oneshot (.CU/.CD) you cannot trigger a counter more than once every two scans. Since the FSC finds the next match every scan this is a problem.

Simple solution: drop the CTU and replace with an ADD instruction that adds 1 to an integer.
 
Hey that worked like a charm thanks! I was thinking had something to do with scan time but was worried about the add not being as accurate.
 
final part of my puzzle can FSC do an OR statement I am trying to capture values that are greater than X+1 and less than X-1 but it doesnt like my expression
(TagArray[CompareForAlm.POS]<(TAVG-1)) OR (TagArray[CompareForAlm.POS]>(TAVG+1))
 
It should not matter, but try pre-calculating TAVG±1 and then
(TagArray[CompareForAlm.POS]<TAVGminus1) OR (TagArray[CompareForAlm.POS]>TAVGplus1)
Or use ABS(TagArray[CompareForAlm.POS]-TAVG)>1

?
 
Some quick experimentation seems to suggest that for whatever reason it will not let you use the output of a relational operator as an operand for the OR statement (or perhaps more for logical comparisons in general).

So eg '(x OR y) > z' is accepted, but 'x OR (y > z)' is no bueno.

I don't see anything in the FSC documentation about this, but it may be documented as a more general rule somewhere.
 
Some quick experimentation seems to suggest that for whatever reason it will not let you use the output of a relational operator as an operand for the OR statement (or perhaps more for logical comparisons in general).

So eg '(x OR y) > z' is accepted, but 'x OR (y > z)' is no bueno.

I don't see anything in the FSC documentation about this, but it may be documented as a more general rule somewhere.

Maybe the FSC expression parser casts comparison results to a binary number (1 for True and 0 for false), so the expression could be ((A = OptionIndex) * OptionValue) + ((A <> Option) * NonOptionValue), which would evaluate to either OptionValue or NonOptionValue.

I wonder if ((A>(TAVG+1)) + (B<(TAVG-1))) > 0 would work.
 
Once again, as always, I'm offering the advice to quit using difficult Allen Bradley looping functions like FSC and to write it in ST - a brand independent language that was made to loop. It's easier to understand, it may give you more control over data type conversions, it's more flexible, it's better documented, and it's less likely to have unexpected side-effects. And you don't have to worry about firing transitions on the input.
 

Similar Topics

Maybe this is just not possible, or maybe I am doing something wrong. Background; I have a data array of over 1500 products. For sorting I...
Replies
6
Views
765
I have a FSC instruction that won't enable. I check tags and data type and can't find the problem. I'm trying to pull index numbers for data...
Replies
4
Views
733
I received the following message via PM, and am posting here publicly to help others. ============================================ I had a...
Replies
10
Views
1,027
Good Morning, New poster here, i'm looking to get my FSC working for some reason it is only looking at the data in the 0 dint instead of the full...
Replies
10
Views
2,526
Received this question in my inbox and posting it here so that others can also chip in: It's been a while since I used the FSC now, but from...
Replies
7
Views
2,175
Back
Top Bottom