Crimson 3 binary function

OkiePC

Lifetime Supporting Member
Join Date
Mar 2005
Location
ENE of Nowhere Oklahoma
Posts
11,787
It seems that I recall there is a function to find the first bit set in a tag in Crimson. I am reading a fault word from a VFD and converting it to a value which is formatted as multiple states. The states of the tag have the fault text copied from the Yaskawa manual. Multiple bits can be set at any given time, but I will be satisfied to just return a value representing the first bit set in a word.

Right now I am using complex code to do this:
if (FaultWord.0) return 1;
if (FaultWord.1) return 2;
if (FaultWord.2) return 3;
if (FaultWord.3) return 4;
if (FaultWord.4) return 5;
if (FaultWord.5) return 6;
if (FaultWord.6) return 7;
if (FaultWord.7) return 8;
if (FaultWord.8) return 9;
if (FaultWord.9) return 10;
if (FaultWord.10) return 11;
if (FaultWord.11) return 12;
if (FaultWord.12) return 13;
if (FaultWord.13) return 14;
if (FaultWord.14) return 15;
if (FaultWord.15) return 16;
return 0;

The advantage to this is that I could re-order the bit checking to better match the fault bits I may want to prioritize, but I am quite sure there is a simple function to do about the same thing.

Any thoughts?
 
Last edited:
Instead of using the Complex feature, make a function, take what you have there and create a program.
 
Instead of using the Complex feature, make a function, take what you have there and create a program.

There are only two instances of this and they each have a different tag folder so by simply duplicating the tag and moving it to the other folder it works fine and should be plenty efficient. If I had more than two or three of them I would probably do as you said and make it into a function.

I had thought I had read about a system function or math operation (without bit twiddling hacks) that would do the same thing more simply. I have nothing against bit diddling hacks, but in this case, being the source of a tag, what I am doing is probably just as efficient.

I could put a condition to return zero if the FaultWord==0 as the first line...that would be an improvement when there are no errors which should be > 99.9% of the time.
 
Not quite what you were asking for, but this works for most significant bit:
return Find(IntToText(AlarmMSB,2,16),'1',0);


- converts your AlarmMSB tag into binary text
- searches for the first 1, starting at the left (MSB)
- returns the position of the set bit; starting at 0 and the MSB

If there are no bits set, then you would get -1.
 
Not quite what you were asking for, but this works for most significant bit:
return Find(IntToText(AlarmMSB,2,16),'1',0);


- converts your AlarmMSB tag into binary text
- searches for the first 1, starting at the left (MSB)
- returns the position of the set bit; starting at 0 and the MSB

If there are no bits set, then you would get -1.

That may be the ticket. I will have to test it tomorrow. Thanks!
 

Similar Topics

Hey guys, hoping someone here could give me a little advice. I'm working with a CR1000-04000 in Crimson 3.1 and I was interested in adding the...
Replies
4
Views
114
Hi, I'm having an issue in crimson 3.0 when I create a programme using a case statement referencing a fault word that each bit needs to change the...
Replies
4
Views
151
How do you install update on Red Lion Crimson ver 3.1. Do I just need to run the exe file on the host server?
Replies
1
Views
103
Has anyone found a way to convert/replace/update the firmware on old Parker TS80xx series HMIs (i.e. TS8010, TS8006, etc) to accept Crimson...
Replies
0
Views
89
Has anyone setup communications with Red Lion 3.0 MODBUS to Baker Hughes Centrilift GCS VFD? Thanks
Replies
0
Views
89
Back
Top Bottom