VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to do calculations outside of FPGA target in VeriStand?

I am reading analog values from some C-modules through my FPGA target.  The reason why I want to do these calculations outside of the FPGA is because I need double precision accuracy. After I get the data it is not useful until performing some calculations (much like any gathered data) and so I would like to perform this calculations while VeriStand is running.

 

Through what I have found so far there are a couple ways I can do this.  One is I can create "Calculated Channels" in the definition file for each calcuation that I want to make, but the problem with this is that I have many channels to run calculations on.  It would take forever to make a calculated channel for each of these and it's not easily reproduced on other systems (i.e., you can't import/export like you can aliases).

 

The second way I think that it could be done is by creating a custom device that will perform the calculations.  Now this is the first project I've been working with VeriStand for and have never created a custom device before.  So I'm not sure if this is something feasible or even the right way to use them.

 

Maybe there is a third way that is easier or maybe someone already has created such a device that can do this.  That is why I'm posting this.  What is the easiest to perform calculations on multiple channels in VeriStand?

 

Thanks in advance!

0 Kudos
Message 1 of 13
(7,265 Views)

What are the nature of these calculations? Are they polynomials? Look-up tables?

Jarrod S.
National Instruments
0 Kudos
Message 2 of 13
(7,256 Views)

Nothing as complicated as polynomials (at least not for this part).  I'm not sure what will be in store later on in this project or others, but for now I just need to do basic calculations like multiplication, division, addition, subtraction.  I though initially I could do this on the FPGA, but I've been instructed that we need to have it be double precision level of accurary and since it doesn't support that I am looking into this route.  The numbers I need out will be as small as 10^-12.

0 Kudos
Message 3 of 13
(7,252 Views)

Are you using the built-in FPGA personality support in VeriStand? If so, you can define in your fpgaconfig file scaling and offset values to be applied automatically to your values after they are DMA'd up to the host. For example, the following value is multiplied by 10 and has 0 added to it after it is transmitted from the FPGA device.

 

<I16>
<Name>AI0</Name>
<Description>Analog input channel AI0 on connector 0.</Description>
<Category>Input\Analog</Category>
<Scale>10</Scale>
<Offset>0</Offset>
<Unit>Volts</Unit>
<Symbol>AI</Symbol>
</I16>

Jarrod S.
National Instruments
0 Kudos
Message 4 of 13
(7,245 Views)

Wow, that is a lot more simple than I thought.  I am using the personality support, but I guess I didn't think of - or realize - the usefulness of scaling for doing some calculations like that.  I may however still have a problem.  My FPGA connector is hooked to a C-series chassis with C-series modules in it.  So in my FPGA code, I am grabbing the module calibration values through a proprty node and putting them into the DMA.  The calculations I want to do use these calibration numbers along with the analog measurement.  From what I can see, I would have to already know the calibration values to put into the *.fpgaconfig file.  Is there some variation of this where I can still do it in the config file?

0 Kudos
Message 5 of 13
(7,240 Views)

Addition to the above post:

 

Also one ot the calculations I have to make follows this format:  ((Var1*Var2) - Var3)*Var4

 

Which I do not see as a possibility with this method either.

Message 6 of 13
(7,231 Views)

Hmmm.. Well, it was worth a try. That is good feedback regarding the scaling calculations you require. Thanks.

 

I think your best bet is calculated channels. We are aware of the usability issues you mentioned and are investigating ways to improve that for future releases. For now you might consider seeing if you can use the VeriStand System Definition API to programmatically create or duplicate calculated channels. Unless someone already has a calculated channel custom device they can share, that might be your best bet for now.

Jarrod S.
National Instruments
0 Kudos
Message 7 of 13
(7,205 Views)

With using the API for the calculated channels, would this be implemented within VeriStand the same as as a custom device?  I'll be honest - I've been reading about custom devices and with the material I've read I still feel a little in the dark about how to set them up.

 

For now I'll just look into the API and get a feel for how I can accomplish what I am trying to do with that.

0 Kudos
Message 8 of 13
(7,200 Views)

Using the API is different than a custom device. You would use the API to create some script that you could run to to create or modify the calculated channels in the system definition directly. For instance, you might write a script that adds calculated channels to a system definition based on the contents of a simple spreadsheet file.

Jarrod S.
National Instruments
0 Kudos
Message 9 of 13
(7,198 Views)

At the risk of sounding completely inexperienced...  I've never created a script or used any API before so I have no idea where to start.  Can you suggest a starting point or some useful examples to help me out?

 

...or maybe it is feasible to maintain precision by doing the calculations on the FPGA.  That would be ideal, but I'm realatively new to FPGA programming and am not sure how I can maintain a high level of precision.  It was previously done in floating point in the program that I am replacing, but since we are moving to VeriStand and the FPGA's some things will change.  As the rest of the post concerns it's not that easy to do a high level of calculations on channels in VeriStand so maybe the FPGA?


The two different calculations I need are below labeled by data type - and the question is... how can I make sure I am precise?

 

1)     (I16 * I32 * 10^-12) - (I32 * 10^-9)   -->  FXP  -->  U64 --> DMA to Host

 

2)     [(I16 * I32 * 10^-12) - (I32 * 10^-9)] * FXP   -->  FXP  -->  U64 --> DMA to Host

The FXP in this calcuation before the conversion consists of numbers from 0-5 with a precision out to 5 decimal places.

0 Kudos
Message 10 of 13
(7,195 Views)