LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FIFOs and Assembling Data

Solved!
Go to solution

Alright I need some advice on what you guys think would be the best way to assemble my data that I'm retrieving from a cRIO FPGA. Let me describe my setup and what I'm trying to accomplish.

 

I have a 360 count encoder and a pressure transducer, I'm collecting position and pressure together (this is attached to an engine so my values for the encoder will be from 0 to 719) because the pressure-at-position is very important for all of the calculations I will be doing. I used this tutorial to develop my FPGA and RT block diagram. Here's my FPGA:

FIFO_FPGA.PNG

And here's how I'm currently monitoring the FIFO output in my RT:

FIFO_RT.PNG

Here's how I used to process this data before using the FIFO:

current_procedure.PNG

(sorry for the broken lines, I took this section out before taking a screen shot)

 

The old method is fairly simple:

  1. Sync with TDC (0 Crank Angle Degrees, (CAD))
  2. Insert values in to array until reaching 719 CAD
  3. Repeat for desired number of cycles (Number of Cycles to Acquire)

Now there are a number of problems with this that I know of, the important ones being:

  1. It could miss CAD 719 and wrap back around
  2. The FPGA-to-RT communication can be too slow and I end up missing CAD (which I can observe - there are spikes where the data is missing and I've initialized the array to use the value 100 so I can pick them out because the regular values are between -1.5V and 0.5V)

Now, I want to accomplish this same thing with the FIFO but am not sure how. I need to acquire 720 samples in a row starting with 0 CAD (so I know all of the analog samples are from the same cycle). Any ideas?

 

Thanks!

Logan

0 Kudos
Message 1 of 38
(3,363 Views)

How fast is the data acquisition on the FPGA running? Depending on the rate it might not be possible to transfer all samples to the host.

With your current architecture this will not work. You always have the latest values on the "Input Data" indicator, there's no buffering or anything. So when you access the indicator from the host you will just get a snapshot, but you will most likely miss samples. During the 20ms wait in the outer loop you probably write hundreds of values to the indicator, but you will only get the last of these values.

You might want to use a FIFO between FPGA and host to send the data buffered.

 

 

0 Kudos
Message 2 of 38
(3,325 Views)

Unfortunately, despite the "Publish Date" of March 23 2012 on the linked tutorial, the actual content is horribly out of date, as you can see from the download to the linked code which is for LabVIEW 7.1 and 8.2. I highly recommend that you start over from a newer example that uses a DMA FIFO, which provides a much faster and simpler mechanism to stream data from an FPGA to a host VI. I'd start with the DMA examples from the LabVIEW example finder. In LabVIEW 2012 these are under Toolkits and Modules -> FPGA -> FPGA Fundamentals -> DMA. Similar examples should exist in other recent versions although they may not be in exactly the same place as some examples get rearranged between versions.

0 Kudos
Message 3 of 38
(3,296 Views)

Thanks for the tip, I've updated my FIFO code to use the DMA FIFO configuration. My FPGA now looks like:

DMA_FIFO_FPGA.PNG

And my RT:

DMA_FIFO_RT.PNG

However, this code is similar to my last in that it just displays the data rather than doing anything useful with it. I'm still not sure how I'm going to assemble the data in to sample sub-arrays storing the pressure data with indices 0 to 719. Any ideas?

 

Thanks!

0 Kudos
Message 4 of 38
(3,287 Views)

On a side note, this code is also in the FPGA:

DMA_FIFO_CRANK_FPGA.PNG

Which is what generates the CrankCount variable. Whenever I choose a value around 1000 or higher for Count(Ticks) the data for CrankCount becomes unstable, often producing 0s.

 

Also, my data appears to run backwards (instead of the CrankCount values going 0->720 they go 720->0) whenever my RPM goes below 600, not sure what that's about but assume it has something to do with the communication speed between the FPGA and RT device, the amount of data and I'm reading the the Count(Ticks).

0 Kudos
Message 5 of 38
(3,283 Views)

The 600 RPM actually makes perfect sense - I'm collecting samples at 50 kHz, at 600 RPM 360 degrees is 5000 samples so one full cycle (720 degrees) is 10000 samples exactly. So, when I drop below 600 rpm my data is coming in slower than I'm reading it.

 

I'm still not sure why when I exceed 1000 Count(Ticks) the single-cycle timed loop has issues.

0 Kudos
Message 6 of 38
(3,276 Views)

Somewhere along the way I've lost track of exactly what problem you need help solving. Are you still looking for assistance? If so, can you attach your code (not just a screenshot) along with a detailed explanation of what isn't working now, and what your final goal is?

0 Kudos
Message 7 of 38
(3,267 Views)

I will be able to post the full code tomorrow when I am school (where the computer is this that I'm developing this code, it's stored locally). I can give you the summary of what I'm looking for assistance on, though.

 

It's probably easier if I give you a better description of the system I'm working on. I have a test engine with a 360 count encoder (A and Z phase) and cam shaft encoder ("Cam Z") - this allows me to know not only crank position but 4-stroke cycle position:

  • So I'm interested in aligning my data to Crank Angle Degrees (CAD) from 0 to 719.
  • I have a in-cylinder pressure transducer which I measure the voltage of (after it's passed through a charge amp), the values of which range from approximately -1.5V to 0.5V.
  • This is all attached to a cRIO chassis which has an encoder card (I believe it's an NI 9411 but I'm not positive since I'm not there right now) and an NI 9215 analog input card.
  • The engine operates from roughly 500 RPM to 2000 RPM but will almost always run at 1000 RPM when data collection is happening.

What I'm interested in doing is collecting the pressure data in sync with the current CAD (so each CAD has a pressure reading with it - this is vital because the pressure produced at a known position is what we are measuring and using for our calculations). I want this data to be formatted in to 1D arrays of 720 elements, each element being the pressure at that CAD (the array indice is the CAD).

 

The Real Time (RT) loop is way too slow to synchronously collect and analyze data (this RT loop is also running spark and injection of this engine) which is why I've been developing this current code with a FIFO.

 

So, the real issue I'm running in to here is: how do I take the data from the FIFO and turn it in to a series of 720 element 1D arrays of pressure data?

 

Like I said, I will post the code tomorrow and hopefully be able to clarify any questions anyone has.

0 Kudos
Message 8 of 38
(3,253 Views)

Here is the code for my FPGA and RT as it is right now.

Download All
0 Kudos
Message 9 of 38
(3,240 Views)

nslogan wrote:

The Real Time (RT) loop is way too slow to synchronously collect and analyze data (this RT loop is also running spark and injection of this engine) which is why I've been developing this current code with a FIFO.


I have no idea what this sentence is supposed to mean. Depending on exactly what processing you need to do, the RT host can likely handle it fine. You might want to read from the DMA FIFO in a separate loop from the one doing engine control, if they're separate tasks. By Real-Time loop, you don't mean the FPGA, do you?


nslogan wrote: 

So, the real issue I'm running in to here is: how do I take the data from the FIFO and turn it in to a series of 720 element 1D arrays of pressure data?


What, exactly, is the desired data format? Post a picture of the cluster, array, array of clusters or whatever it is you're hoping to generate.

 

It sounds to me like you want an array of clusters, where each cluster contains two elements, angle and pressure. However, your FPGA code could return multiple pressure points for some angles, or no data at all for some angles if the engine spins fast enough relative to loop cycle time. If I'm correctly understanding what you want, I would restructure your FPGA code so that it checks for changes to the angle. Each time the angle changes, read the pressure, then write the angle and pressure combined (as you already do) to the DMA FIFO. On the RT side, read full cycles at a time out of the DMA buffer. If you need them to start from 0 up to 719, look at the angle of the first data point, then rotate the array the appropriate amount to put 0 first. Or, read one point out of the DMA buffer, see what angle it is, then read and discard enough points until you're back at 0 angle. From there, if you only read full cycles (and the engine is slow enough that the FPGA can catch every angle transition), each DMA read will start at 0 angle.

 

Does that sound like approximately what you want, or am I completely misunderstanding?

0 Kudos
Message 10 of 38
(3,218 Views)