02-15-2016 06:03 PM
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,
02-15-2016 06:59 PM
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.
02-15-2016 07:19 PM
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?
02-15-2016 07:24 PM
@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.
02-15-2016 07:38 PM
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.
02-15-2016 08:29 PM
@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.
02-16-2016 06:29 PM
@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?