Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Perform an Averaging Function with FPGA?

I have this project to the point where it compiles and runs.  The averaging function seems to work.  For example, if I change "N" constant from a 8 to some other value, the averaging is clearly functional depending on the "N" value given.  The problem I'm having with it however is that it does not always start correctly.  It sometimes displays a significantly different value (i.e. total load) upon start up. In other words it doesn't always start with the same value when the analog inputs had not changed.  It’s as if it does not always initialize correctly.
0 Kudos
Message 11 of 21
(2,142 Views)
when you say that it does not start with the correct value.  does the value become correct?  if you are running the vi multiple times, the fifo data probably needs to be reset you will need to add a reset function that will set the shift register to zero and clear the fifo and clear the iteration count check.
Stu
0 Kudos
Message 12 of 21
(2,131 Views)

It’s a little difficult to describe and what I said is probably misleading.  If the FPGA VI is started and stopped without changing the analog inputs, the value (i.e. Total Load) seems to always be correct.  However, if I stop the VI, change the input values and then restart the VI , the Total Load value will be incorrect basedon what is at the analog inputs.  It will then correct itself if I restart the VI without changing the analog input values. 

It’s unclear how to reset the FIFO at startup and why does the FIFO not clear itself out after a number (i.e. 256) of iterations?
0 Kudos
Message 13 of 21
(2,118 Views)
how about posting your current project and I will try to add the reset logic.
Stu
0 Kudos
Message 14 of 21
(2,114 Views)
Running your FPGA VI in Interactive Front Panel mode (i.e. just clicking the Run arrow) does not cause the FPGA to reset when execution is completed or aborted.  For more information see the LabVIEW 2009 and 2009 SP1 FPGA Module Known Issues, specifically issue 132032.  You can either add logic to clear the FIFO when you complete execution or redownload the FPGA bitfile before running again.  If you have a host interface to the FPGA VI, if you close the reference and reset the VI (the default operation for Close FPGA VI Reference), your FIFOs will be cleared and your average should be correct when you run the VI again.
Donovan
0 Kudos
Message 15 of 21
(2,110 Views)
Attached is the project that I have at this point.  The arithmetic functions are changed to high throughput because it would not compile.  Apparently there were timing problems when using the normal arithmetic functions.   I assume the FIFO is defined in the sub-vi as opposed to the project because of the re-entrant issue for the sub-vi.  Am I correct or are there other issues? Unrelated to the FIFO issue, why is the fixed point value set to <+,20,-5> as the data input to the AO module in Example.vi?  How do you know to set it to this?  I appreciate your willingness to help me with this.

 

0 Kudos
Message 16 of 21
(2,104 Views)

attached is revised code including reset and ititializaiton code. 

 

on the example that you provided, you recoded the math after the moving average and conversion to AO.  I replaced this with the code from my previous example.  I have found that it is better to be explicit about the number types being used rather than letting the number propogate to very large bit-widths.

 

good luck

Stu
0 Kudos
Message 17 of 21
(2,076 Views)
Why is the fixed point value set to <+,20,-5> as the data input to the AO module?  How did you know to set it to this? 
0 Kudos
Message 18 of 21
(2,069 Views)

do a "create constant" at the AO terminal to see the data type expected by the I/O node.  +20,-5 allows 0 to .0312 range.  enough for the 0-.020 mA range of module.

 

looking  at it again the final span and offset should have higher resolution to insure that the +20,-5 resolution is preserved.  set the output type of both mult and add to +20,-5.

Message Edited by stu@viewpointusa.com on 05-18-2010 10:38 AM
Stu
0 Kudos
Message 19 of 21
(2,065 Views)

Hi Stu,

Earlier you mentioned to use normal arithmetic functions as opposed to high throughput.  For reasons unknown to me it will not compile when using the normal functions because there are timing problems.  It’s unclear how to solve the timing problems so I reverted back to using the high throughput versions.  However, I’m having trouble with accuracy in the calculations.  In other words, it does not add and multiply correctly.  I don’t know if this has something to do with the high throughput or my lack of understanding how to work with FXP; or both.  It takes a full 2 hours to compile so I’m easily sidetracked, which makes it difficult to finish the project.

When is it appropriate to use high throughput versus the normal arithmetic functions?
0 Kudos
Message 20 of 21
(2,024 Views)