Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Need Help! Modicon M340 w/Unity Pro XL v10 2

Status
Not open for further replies.

elfman

Mechanical
Oct 21, 2003
79
0
0
US
I am trying to convert an Allen Bradley RSL5k program and am stuck on an addressing issue. In AB I have a UDT with a DINT member. I step through the bits of the DINT programatically with the following code

UDT_NAME.MemberDINT.[StepVar] and then I simply cycle through the applicable bits of the DINT by incrementing StepVar.

I need to do the same thing in Unity Pro, but cannot figure out how. Is this possible, if so, how? Please, and thank you very much!

"To be or not to be, that is the question" - William Shakespeare via Hamlet
 
Replies continue below

Recommended for you

Can't really do that with a DINT. However you can do something similar with a type word. I believe that there are functions which can convert from DINT to WORD and then access the state of a given bit within the word type. A pain in the you know what but that is the price you pay for strong data typing.
 
djs. You are right - changed the type from a DINT to a WORD and if I write this: UDT_NAME.MemberDINT.1 where 1 could be 0-15 and Unity accepts it no problem. However, I need to step through the indexes programatically - and I cannot figure out how I do that based on the number contained in StepVar. Please, advise is much needed...?

"To be or not to be, that is the question" - William Shakespeare via Hamlet
 
The MUX instruction seems like it only selects between 2 inputs - I need 12, and possibly more in the future. Not only that, but I also, typically have 2-3 conditions that at least one is dependent on the index and others are simple logic. Thank you for the suggestion though. Maybe it will help.

"To be or not to be, that is the question" - William Shakespeare via Hamlet
 
If you have defined UDT_Name as type WORD, then you can access the individual bits with an integer variable Step_Var by using UDT_Name.Step_Var and Unity should resolve this OK.
Which is to say that it does in my code. I have arrays of words defined : Stationregs => ARRAY[1..3] of WORD, and address these with two integer indexes : Stationregs[Index1].Index2. Unity knows exactly what to do with these.
 
Paulusgnome: I have constructed an array of type WORD but am receiving still receiving the error shown in the attached graphic. What you are describing is exactly the functionality I really need - any help will be very much appreciated!

I am using Unity Pro version 10, but am happy to upgrade if a later version will get me said functionality...

"To be or not to be, that is the question" - William Shakespeare via Hamlet
 
 http://files.engineering.com/getfile.aspx?folder=43b5e225-54eb-4bad-bfa4-19d4524305fe&file=Prolem_Graphic_1.jpg
Oops, I fear I spoke too hastily. That bit index doesn't work, does it? Sorry about that.
I fear that you will have to write yourself a wee function block to do this. Translate your DINT into an array of bits which you will be able to index.
 
Attached is a screen shot of the use of the MUX instruction
Mux_dvs6mv.jpg
 
djs... That looks like it could work, but... I need it in reverse too. Is there such a creature, and can it work in Ladder with all 16 bits? This is getting close, but there are still some gaps and this last 'reversal' may be the trick. THANKS!!

"To be or not to be, that is the question" - William Shakespeare via Hamlet
 
Perhaps Paul has the right idea. Convert your input into an array of Booleans, work on it and then convert back to word etc. Look up conversion functions in the help.
 
Status
Not open for further replies.
Back
Top