DWORD to DINT

jwall

Member
Join Date
May 2005
Posts
43
I know this is simple, just wondering if anyone had a good counter for the int to word conversion, in Protool/Pro

I have a 32 bit array slave[0..31] which holds information on if the slave is missing or not. If only slave 1 is missing then slave[1]=1

I bring in the 32 bits of slave[] as a DINT in protool, and then would like to use it as a attribute, and mask for the bit, so that bit = 1 will controll the element with slave[] as the multiplexed tag.

Currently if slave[] = 2
0000 0000 0000 0000 0000 0000 0000 0010
The register shifts it around in word form, and slave[] in protool appear to be
0100 0000 0000 0000 0000 0000 0000 0000

What is the best way to counter it, so than the masking is simple and implicit in protool. I don't want to have to remember the re-assingment of 32 bits, as the get switched around due to serial LSB MSB rules.
 
Try to use the "attributes" when you open up the Properties for a text or some other object.
You can assign colors and flashing/not flashing to animate the object.
Steady green color for OK, and flashing red for trouble could be a good way of indicating the status.
There are several ways to trigger the different attribute-states. I think that you can select "bit in tag" in stead of the normal "decimal value".
I dont know if it allows you to get 32 bits from a DINT, but I am fairly sure you can get 16 bits from an INT tag.

edit:
The way to do it is to assign normal colors to the object itself (steady green). Then add only one state in the attributes with red flashing set. Let the relevant bit trigger the state.
 
Last edited:
Hi Jesper.

This is what I have done, except in order to use slave[2] (second slave, second bit) I have to use BIT 25 to get the appropriate change on the item. I just want to have it more implicit, so that the second slave is masked by BIT 2, as intended, so configuring and troubleshooting is quicker.
 
It's a bit difficult to be sure from your description, but this sounds as though it might be something where the CAW/CAD instruction could solve your problem. This command swaps the Bytes in the accumulator so that the LSByte (and therefore also the LSBit) is at the right hand side of the word. In other if you load DWORD 10 into the accumulator, initially you have the Bytes in the order:

Byte 10, Byte 11, Byte 12, Byte 13

after the CAD command, the Bytes are now arranged:

Byte 13, Byte 12, Byte 11, Byte 10.

I use this setup a lot as I have 21 functionally identical modules in my project and I have many of the DBs arranged to that data relating to the modules is arranged in order of the module number. As you say it makes troubleshooting and following the logic a lot easier. It also makes it much easier when working with the multiplex addressing in ProTool.
 
Last edited:
Aha, now I understand what the problem is. Its the popular "story of the swapped bytes in S7".

What appears in this sequence in S7: Byte 3, Byte 2, Byte 1, Byte 0.
Appears in this sequence in Protool: Byte 2, Byte 3, Byte 0, Byte 1.
(forgive me for putting the least significant byte to the right, but I find it better that way - then it follows the order of significance together with the bits).

Roy, are you sure that you must use CAD to fix it ?
I would think that you must use CAW twice to reorder things like this:
S7: Byte 2, Byte 3, Byte 0, Byte 1.
Protool: Byte 3, Byte 2, Byte 1, Byte 0.

Using CAD once will only confuse matters even more (I think):
S7: Byte 0, Byte 1, Byte 2, Byte 3.
Protool: Byte 1, Byte 0, Byte 3, Byte 2.

If you are allready using CAD and it works for you, then it must be right. But I just dont understand why.
 
OK ok, now I REALLY understand what is going on.
You are both using FB125 or FC125 to get Profibus diagnostics.
And then you get the peculiar sequence of the bytes.
And then CAD is the right instruction to reorder the bytes so you get the right sequnce of the bits.

I use the preconfigured Protool screens where all the work is done for me. So I dont have to know the particular details.
Ihey are very easy to import.
Just work a little with the graphics and it looks nice. It took me 2-3 hours from start to a fully functioning Profibus Diagnostics page in my HMI.
 
Roy, are you sure that you must use CAD to fix it ?
I would think that you must use CAW twice to reorder things like this:
S7: Byte 2, Byte 3, Byte 0, Byte 1.
Protool: Byte 3, Byte 2, Byte 1, Byte 0.



I must admit I wasn't really thinking of ProTool. As you guessed, I'm using CAD to map my FC125 results to the Enable Bits in a DB which control whether or not the operator can select a Module.

If the Bytes are organised in ProTool as you say they are, (he says, wondering why he hasn't fallen over this problem somewhere along the line!) then using CAW twice, is indeed the solution.
 
No no, I was going in the wrong direction there.

If you want to look at the bits by taking an INT or DINT and then displaying with an output field with "binary" display mode, then you must use CAW once/twice.

But if you specify the bit number in a list of states, then normally you dont have to do anything special.

On the other hand, when using the FB125 or FC125 to get a list of bits in a DINT variable to indicate profibus nodes with errors, then you have to swap all the bytes with CAD.
It works for you, therefore it is correct to use CAD.
 
Hi guys, thanks for the response. I am not using fb125 or fc125 anymore....
I have made my own diagnostic suite, thanks to RMA's help a few months ago, and it works well on SFC's and logic.

I think you both understand my problem. What I did was make a FC, that would take in 32 bits, and return 32 bits in swapped order. Just a simple set of normally open gates attached to the offseting coil. When its sent out to the HMI, slave[2] is now attached to the second bit of the tag, and slave[2] is assigned properly in the step 7 code as well.
 

Similar Topics

Hello, I am provided with PLC tags with PLC_UDT datatype via symbolic connection. The structure of PLC_UDT (DI_hmi) is: DI_hmi.stat (UDINT)...
Replies
4
Views
1,352
I'm trying to set alarm as DWord where each bit is individual alarm. So far I have tryed with DWord.0, DWord.1, DWord.2, etc. DWord.L0...
Replies
8
Views
814
Hello, I am using Omron PLC: NX1P2 Software:-Sysmac Studio Plc in which I have to read data from an energy meter over Modbus RTU The data that I...
Replies
3
Views
840
This feels like a simple, elementary question, but I am a Siemens novice and know there are experts here. My S7-1500 project (TIA Portal v17) has...
Replies
10
Views
2,608
I am needing to convert the low DWORD of a timestamp into a LREAL. The DWORD is a 32bit unsigned number. In TwinCat2, I keep getting a negative...
Replies
3
Views
1,648
Back
Top Bottom