LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

incorrect reading when negative value

Solved!
Go to solution

Hi to everyone,

 

 

this is about power meter device reading. actually, I already got the right value here but i create additional calculations. the situation is:

 

when power reading is positive value, i got correct reading.

when power reading is negative value, i got wrong reading (high very positive value). so i need to subtract this high value to 2 ^32 (or 4294967296).

 

is anyone there know the reason why it does need to happen?

Ivel R. | CLAD
0 Kudos
Message 1 of 14
(6,594 Views)

There could be many reasons, but you don't provide enough detail.

 

How are you reading the value from device? Can you show us some simplified code?

 

Most likely you are using the wrong representation (e.g. U32 instead of I32).

0 Kudos
Message 2 of 14
(6,582 Views)

Hi altenbach,

 

thanks for response, the attached pictures are the part of what i said. the Psum, Qsum, Ssum, and PF are the actual and correct reading i receive in power meter device. the "Psum (hi value)" is the wrong reading.

before, i have no problem reading this device because i always get positive powers, but this morning i got negative values in Psum & PF. so what happens is that in the power meter device, i read negative values. in my previous VI, i read very high positive values. you can see that in the "Psum (hi value)" below. 

so i just found out the when this high values are subtracted to 2^32 EXACTLY, i'll get the right negative values. i dont know why it doest happen. in the block diagram, i used the "double" number format because i need a decimal value in my front panel. do i clarify my situation now?

 

24292iE19A833D29B48FEC 

Ivel R. | CLAD
Download All
0 Kudos
Message 3 of 14
(6,572 Views)

Actual code would be better than an image, because many things cannot be determined from a picture alone. What happens in the subVI?

 

What is the datatype of the "registers" arrays?

 

Instead of "decimate+join", I would typecast to the desired signed integer datatype (i.e. twice as many bits as the original "registers" data) before dividing by 1000. See if this helps.

0 Kudos
Message 4 of 14
(6,560 Views)

hi there,

 

the datatype of the registers are floating point double. originally, in the document, the range of value is "signed integer". but because i need to have a decimal value as result in my front panel, i used the double floating point.

 

because this program is quite huge, i will only attached the subvi that the error in data was occured. please see attached vi files.

 

btw, thanks for the alternative suggestions, i'll try that one.

Ivel R. | CLAD
Download All
0 Kudos
Message 5 of 14
(6,548 Views)

btw,

 

the resulting register composes of hi & lo word (means two addresses).. thats why i used the decimate+join. to combine the hi&lo word.

 

i cannot figure out also how to use typecast with this kind of value, can you kindly specify how to do it?

 

thanks.

Ivel R. | CLAD
0 Kudos
Message 6 of 14
(6,544 Views)
Solution
Accepted by ivelson

OK, the "registers" are arrays of U16. so try to typecast to I32. How many elements are in the array?

 

Somehow you do everything with arrays, but you are only displaying a single element. It almost seems to me that everything past the "join numbers" primitive should be plain scalar data. There is also a lot of duplicate code. You could get away with one instance and a FOR loop, for example.

 

The data representations are a mess with a wild mix of datatypes and coercions. The Psum(High value) is I64 for no reason (coerced from a DBL division of two U32 values (???)). I don't understand the function of the subVI. Can you explain?

 

Can you place an indicator of one of the "registers" arrays, run the VI so it contains data, then turn the indicator into a diagram constant that contains typical data (right-click..change to constant). Save and attach the VI.

Message 7 of 14
(6,536 Views)

 


ivel wrote:

the resulting register composes of hi & lo word (means two addresses).. thats why i used the decimate+join. to combine the hi&lo word.

 

i cannot figure out also how to use typecast with this kind of value, can you kindly specify how to do it?


 

OK, so nothing should be an array past the join numbers (as I thought!).

 

To use typecast, wire the "registers" array to the input, a scalar diagram constant of I32 to the "type" input on top, and the output will be the desired scalare I32 value (assuming big endian byte order).

Message 8 of 14
(6,531 Views)

Hi altenbach,

 

you are right! the resulting registers are signed integer but i used floating point instead. here is the result image thats why i notice my problem.

 

1. the "Psum" value (-9.017) is the correct value based on the power meters.

2. the "hi.lo" is the very high value i cannot figure out before. i need to subtract it in 2^32 (thats the function of sub vi " + or - value") to obtain the right negative result.

3. the "hi.lo 2" is right value also, just need to divide to 1000 to get the kilowatt form.

 

item #2 is U32 format while item#3 is I32 format. just need to use the I32 format to acknowledge the negative sign. hihi... thanks for figuring out. without your help, I will keep this non-sense sub-vi that even me as a novice developer cannot really explain how it should be happening. whew.

 

thanks a lot.!

 

24304iAD38A3669946583B

Ivel R. | CLAD
0 Kudos
Message 9 of 14
(6,522 Views)

and for closure of this problem. thanks for the typecast function, it solves my problems 100%...! thats what i needed exactly to remove to many unnecessary array results. now i used scalar outputs for my results. thanks a lot.

Ivel R. | CLAD
0 Kudos
Message 10 of 14
(6,513 Views)