LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Numeric Conversions (scaling, really) on the FPGA

I am using a 9208 (+/- 21.5mA current input module) to handle the reading of 4-20mA transducers. Currently, for my target-to-host DMA, I am unifying everything into a U32 array and sending it across the FIFO. The other modules I'm using are DI's and DO's and are pretty easily handled in this regard (?1:0 block, then u32 conversion.) My realtime host implementation thus far in handling the data coming across is to take it as a U16, simply because I'm used to working with it and scaling 0-65535 to engineering units. I use a U32 container, however, because I am doing some high speed counting on the usec level in the FPGA and need to be able to count samples. If I could just get the AI module data as U16 (into a U32 structure) that would be ideal; however I know doing an inline conversion using the block functions isn't a solution because it's not a true scaling VI. Is there a way to take this I32 (raw configuration), discard the negative half and bring the positive side in as a U16?

 

As a side note, to scale a I16 to a U16, I typically do the following:

i16->i32

add 32768 (i32)

i32->u16

 

In that regard, do I...

i32->i64

add 2147483647 (i64)

i64->u32

then just assume the upper half of that range is the only valid range?

 

Am I overthinking this?

 

Thanks,

 

0 Kudos
Message 1 of 7
(4,142 Views)

I would make your FIFO an I32.  Then you can just use Floating Point To Integer to write to your FIFO.  You can then do your scalig on the RT side using the I32 data type.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(4,112 Views)

The I32 FIFO mostly to facilitate the counter? Are you saying you'd configure the AI module as calibrated (FXP) then convert that to I32? Does that mean multiply the FXP by 100 on the FPGA side then deal with accordingly?

 

0 Kudos
Message 3 of 7
(4,102 Views)

@dest2ko wrote:

The I32 FIFO mostly to facilitate the counter? Are you saying you'd configure the AI module as calibrated (FXP) then convert that to I32? Does that mean multiply the FXP by 100 on the FPGA side then deal with accordingly?


You can take the fixed point number straight from the read IO and use Floating Point To Integer.  This will give you an I32.  It will do all of the legwork for you.  I am recommending to just shove that I32 into the DMA FIFO.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(4,098 Views)

You're probably right, but my misunderstanding seems to be at the FP to Integer, which yields me a rounded value, i.e., 0.085 yielding 0. 

0 Kudos
Message 5 of 7
(4,089 Views)

@dest2ko wrote:

You're probably right, but my misunderstanding seems to be at the FP to Integer, which yields me a rounded value, i.e., 0.085 yielding 0. 


0.085 is outside of the range of the fixed point value you can get from your module.  Or are you referring to 0.085mA, which would be 0.000085?  If so, I get 22817 when converted to an I32.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(4,073 Views)

@dest2ko wrote:

As a side note, to scale a I16 to a U16, I typically do the following:

i16->i32

add 32768 (i32)

i32->u16


There's no need for a 32-bit value. You'll get the same result from converting the I16 to U16, then adding 32768 (as a U16). Or, add -32768, then convert to U16. The I16->U16 conversion keeps the bits the same and reinterprets them as signed rather than unsigned, and then rollover makes the math work.


@dest2ko wrote:

If I could just get the AI module data as U16 (into a U32 structure) that would be ideal; however I know doing an inline conversion using the block functions isn't a solution because it's not a true scaling VI. Is there a way to take this I32 (raw configuration), discard the negative half and bring the positive side in as a U16?


I cannot figure out what you mean here. Discarding half of an I32 (or even half a 24-bit value, since that's the resolution of the 9208) doesn't get you to 16 bits. What are you trying to do?

0 Kudos
Message 7 of 7
(4,021 Views)