From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Populate FPGA array with values

Solved!
Go to solution

I have a VI deployed on an FPGA that I want to populate an array on. See the example below, where an array of 20 SGL values is stored on the FPGA, then used in some sort of mathematical operation. This example is representative of the problem I am trying to solve. But in my real code, the array is much larger (100 + elements)

 

example.png

 

How can I populate the array without doing it by hand?

 

Here are some ways I have tried (or thought about using):

  1. Copy and paste from an excel sheet to the array. I don't think this is possible. 
  2. Use a text-based language to copy the array in. For example, in a non-FPGA environment, I could use a MATLAB script node to create an array (i.e. x=[1,2,3,4...n]) and copy it in. This is not available in the FPGA environment.
  3. I don't want to use FIFOs to clock all the data in as it will take a while and will need to be redone each time I run the code. Also, I think this will use up a lot of resources and in practice, the arrays I store will be bigger than the new data being clocked in. 
  4. I tried to set up a memory item (see below) that stores the data in the Block Memory and uses an initiation VI to load the memory. However, I can only load 1 data point per cycle so I have to wait for 100 cycles before my data can move on. So, I would really like to just insert values into the array constant.

example_2.png

 

This brings up the bonus question, does building an array by using the array constantly take clock cycles? For example, if I have an array constant of 100 values, are all 100 values available at the first clock cycle or do I have to wait for 100 clock cycles for them to become available (like the memory example). 

 

Thanks in advace, 

Austin 

 

0 Kudos
Message 1 of 3
(1,732 Views)
Solution
Accepted by Austin-Downey

Hi, you can always use scripting to set the value of the constant programmatically.

The difficult part is to get the reference of the desired constant in the block diagram.

 

Here is a script (LV2020) that can do that for any saved VI, within any target.

The constant can also be of any data type (not only array).

 

However, since you cannot set a pre-build VI for an FPGA bitfile, you will have to run the script manually before building.

At least you can set the value with a customizable initialization code...

 

I wish that NI would allow to add pre/post-build VIs also for FPGA, or even provide some sort of structure that would allow such initialization directly in the FPGA code, which would be pre-compiled on the PC before passing to the FPGA compiler... Let's dream 😄 !

Message 2 of 3
(1,630 Views)

Hi Austin,

 


@Austin-Downey wrote:
  1. Copy and paste from an excel sheet to the array. I don't think this is possible. 
  2. Use a text-based language to copy the array in. For example, in a non-FPGA environment, I could use a MATLAB script node to create an array (i.e. x=[1,2,3,4...n]) and copy it in. This is not available in the FPGA environment.
  3. I don't want to use FIFOs to clock all the data in as it will take a while and will need to be redone each time I run the code. Also, I think this will use up a lot of resources and in practice, the arrays I store will be bigger than the new data being clocked in. 
  4. I tried to set up a memory item (see below) that stores the data in the Block Memory and uses an initiation VI to load the memory. However, I can only load 1 data point per cycle so I have to wait for 100 cycles before my data can move on. So, I would really like to just insert values into the array constant.

5. Convert that array constant into a control, then you can set that control programmatically from your host…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 3
(1,591 Views)