11-03-2013 07:43 PM
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:
And here's how I'm currently monitoring the FIFO output in my RT:
Here's how I used to process this data before using the FIFO:
(sorry for the broken lines, I took this section out before taking a screen shot)
The old method is fairly simple:
Now there are a number of problems with this that I know of, the important ones being:
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
Solved! Go to Solution.
11-04-2013 04:36 AM
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.
11-04-2013 11:59 AM
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.
11-04-2013 01:50 PM
Thanks for the tip, I've updated my FIFO code to use the DMA FIFO configuration. My FPGA now looks like:
And my RT:
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!
11-04-2013 01:58 PM
On a side note, this code is also in the FPGA:
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).
11-04-2013 02:13 PM
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.
11-04-2013 03:30 PM
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?
11-04-2013 07:29 PM
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:
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.
11-05-2013 10:50 AM
Here is the code for my FPGA and RT as it is right now.
11-05-2013 04:34 PM
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?