LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion of 16 bit unsigned to 32 bit float

Solved!
Go to solution

Remove the array to cluster function, the  cluster to array function, and everything in between including the pretty blue and orange wires.

 

Your thick blue array wire will go into my subVI, and the output of the subVI will be the thick orange wire that goes to your indicator.

 

You canrequest all the registers starting at 202 for a quantity of 74 (check my math).  Then use index array for the array that comes out of the subVI and pick off indices, 0, 1, 29, 30, 31, and 36.  (Again check the math).

 

The alternative is to read starting at 202 for a quantity of 4, then do a read starting at 260 for a quantity of 16 then use index array to pick off the ones of interest.

 

You could try both ways to see which is quicker.  Since you are looking at 76 registers all at once, (152 bytes + some header and checksum bytes, I'll round up to 160 total) it will all fit in one command and take about 170 msec for the return message.  That is probably more than quick enough.  Doing it in two messages will save some time in return bytes, but there is an extra read and write and turn around time that I would bet would take longer than the 80-90 msec you might save in raw data bytes.

0 Kudos
Message 11 of 19
(2,334 Views)

Hi Raven fans, after inserting yr vi and following your instructions, the values i obtained are incorrect. But it does the job of reading the registers correctly i think. I'm not exactly sure what your vi does, but it sure looks better than mine.

0 Kudos
Message 12 of 19
(2,316 Views)
Oh, it worked after i changed the starting address from 202 to 201 (minus 1) if i wanted to read registers 202,203.
0 Kudos
Message 13 of 19
(2,315 Views)
Oh ok i got it to work just the way i needed it. I switched the increment between the 2 index arrays. Thanks ravens fan, now my job is complete, i hope.
0 Kudos
Message 14 of 19
(2,312 Views)

J.R wrote:
Oh, it worked after i changed the starting address from 202 to 201 (minus 1) if i wanted to read registers 202,203.

 

That's because there is a slight disconnect in modbus between the way the register is numbered, and the value you give the drivers to access it.

 

For instance, the register might be named 30202.  The 30,000 gets dropped leaving you with 202, but that is based on 1 being the first register.  But the modbus command actual starts with address 0.

 

It's just one of those things that must be double checked when working with modbus.  And it also complicates the calculation from your address number, to the number to feed into the modbus command, to which value you index out of the array once you convert all the register pairs to an array of single precision numbers.

0 Kudos
Message 15 of 19
(2,299 Views)

RavensFan,

 

I used your vi (Modified) to conver 2 unsigned 16 bit to floating 32 and it worked great.  I am now trying to convert a double precision to 2  float(IEEE 754 floating point format).

 

THis is to write to the hi and lo registers

 

an exapmle would be 400 rpm =  lo=0

                                                     hi=17352

 

can you help me?

0 Kudos
Message 16 of 19
(1,977 Views)

If you have a value of 400 as a double, then use the conversion bullet to convert it to a single before typecasting it to a U16 array.

 

0 Kudos
Message 17 of 19
(1,970 Views)

Where do i get the unsigned array from?? Smiley LOL

0 Kudos
Message 18 of 19
(1,962 Views)

You create it yourself.

 

Drop an array container on the the block diagram.  Drop a numeric constant.  Change the representation to U16.  Drag it into the array container.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 19 of 19
(1,956 Views)