LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger analog input in Labview FPGA

Solved!
Go to solution
Hello,

I'm quite fresh with LabVIEW, and I was recently thrown into a project without any education at all. I’m also the only one at the department, who is working with LabVIEW, so there’s no one to consult with when I get stuck.  

 

I’m using a CompactRIO with several different modules, but I’m concentrating on the NI9229 – which is an analog input module. The other modules are NI9219, NI9401 and a few, less relevant modules. The task that I’ve been given is to collect a specific signal (LIN BUS), which is generated from a “device”.  I need to gather one message frame, at 9.6 kbit/s, with the amplitude of 0-12V. I also need a Rising/Falling trigger, which needs to be adjustable in the host window. 

 

I’ve tried a bunch of different codes, and I basically used the Getting Started 9229 example and modified it to one single input with a trigger. But when I use the example, I just can’t seem to get the trigger working.  And I can’t get more than 4095 samples. The NI9229 reads 50kS/s, and I’m not quite sure if that is enough.  

 

It may appear that I’m unsure about quite a lot, and that is because I am. Since I’m operating as a kind of “consultant”, they left me in the dark without access to specifications and knowledge. Therefore, I hope that you guys can enlighten me. 

 

Best regards

Tim Jansson  

 

(I double posted this thread and I do apologize for that. I think I misplaced the other thread and I couldn't find a way to delete it)

Download All
0 Kudos
Message 1 of 17
(7,381 Views)

Hello,

There are two LIN modules available from a 3rd party vendor that can be worth checking out, see link below:

http://www.sea-gmbh.com/en/crio/cr1_index_e.php?page=lin_einleitung

http://www.sea-gmbh.com/pdf/cRIO_lin_daten_e.pdf

I also quickly looked at your code and I don't know how big DMA FIFO size you have since you didn't include the project. When you specify a size on the DMA FIFO on the FPGA the corresponding size on the RT portion will be dependent on the version of LabVIEW you make use of. Earlier versions defaulted to 2X the specified size and the 8.6 and 2009 has 10X if I remember correctly.

You need to change the code related to the trigger. You need to start the module beforehand so you can read data for your trigger condition. Why not have your trigger condition in the same loop as you acquisition? I.e. start module outside a loop structure, inside the loop check trigger and whenever that one is true you start streaming data to the host the number of samples you need.

See attached draft.

Regards,
Jimmie Adolph
Systems Engineering Manager, National Instruments Northern European Region

Message 2 of 17
(7,346 Views)

Thanks for your reply!
I've spending the last couple of days chasing down a computer with LabVIEW 2009. The LIN Modules seems like a good idea to purchase. But what are the pros and cons with a CRio versus a USB-LIN receiver? I've been working (very, very short period) with a USB DAQ and to me, it was a whole lot easier to deal with. 'Cause I found this USB Module: https://www.ni.com/en-us/support/model.usb-8476s.html 

 

 

To the DMA; what should I think about when I specify the DMA size (excuse my inexperience). In this particular project, I specified the size to 8192 elements, 16 bits word length, 16 bits integer word length and the Data type FXP.

 

Thank you for the code, I immediatly started to wonder why I hadn't been thinking of this before! It clarified a lot to me, and I'm grateful! But it doesn't start the acquistiton? When I test the code, I use a simple ext. sine generator with the amplitude 1V and Freq. 1kHz. Even though I put the trigger level to 9-10, it still prints out data on my waveform graph.

 

 

Best Regards,

Tim Jansson

Download All
0 Kudos
Message 3 of 17
(7,316 Views)

Hello Tim,

Well a cRIO based LIN module vs. a USB one will be completely dependent on what you would like to do otherwise in your application. If you would do a by point acquisition combined with a control algorithm of choice then cRIO would be perfect since you get the determinism you need and reliability. Do you want a standalone measurement device that can run independently from a host application (maybe a logging application where data is streamed to disk using DMA) with high reliability then cRIO is perfect. So it will all be dependent on what you would like to do otherwise.

Regarding DMA - you can easily specify it to have the normal length (1023 elements) but just make sure that the data type defined matches the data you get from your module. If you read FXP from multiple modules that have slightly different FXP data types then you can do it like this (see attached picture).

 FXP Conversion

 

What you need to do though is to set the DMA on the RT side of things and you can achieve it using the invoke nodes that are present (methods). Just add an "Invoke Node" from the FPGA Interface sub palette in your RT application and wire the FPGA Reference into the node. Now you should be able to right-click on the node and select Method and then your FIFO that you have defined and there you will see an option to configure it. Select that and specify the size on the RT side of things. Read the section in the LabVIEW help called "DMA, specifying FIFO depth (FPGA)" (just search for that term on the Index tab).

Finally regarding the issue you mentioned when you tested the code. I accidently used OR and not AND when checking Falling/Rising so when one change that it should work fine. See attached VI.

Regards,
Jimmie Adolph
Systems Engineering Manager, National Instruments Northern European Region

Message 4 of 17
(7,311 Views)

Hello again!

What are the advantages with USB then?

 

Okay, so if I got it right: If I don't specify the DMA Depth in the Host window, the elements will be defaulted to 10000?

 

Yes, after a closer look the code, I managed to find the problem on my own. But the thing is that I want it to run until it finds the trigger point. When it finds the trigger, the program writes the data to the graph and then it stops. This has been my major issue through the project. I have been able to create a working trigger before, but only when I'm generating a continuous signal. My project is to find a certain point.

 

Let me clarify the project:
I need a program that runs during a nondeterministic time. A signal is being sent from a device, but when is not known. The only thing we know, is within 10 min, a signal is going to fall (or rise) from (lets say) 0.6 volts to 0.13  volts. This drop is made during a very short period, and the important data is in this period. After the drop, the program needs to be aborted.

 

At the moment, the code samples the specified amount samples and when it's done, it aborts. It doesn't matter if the trigger level has been reached or not. I want it to START sample, when the trigger point has been reached.

 

 

Thanks,

 

Tim Jansson

 

 

 

 

Message Edited by MightyEKA on 11-04-2009 07:01 AM
0 Kudos
Message 5 of 17
(7,301 Views)

Hello Tim,

Well depending on how experienced one is a USB solution might be easier to program since you just program the application directly on Windows and you make use of a driver with a high abstraction. On cRIO you need to program the FPGA, RT and Windows if not using the scan model interface.

Regarding DMA depth you correct it will default to 10000 elements.

I am not sure I fully understand you - the code attached acquires data continuously and check if a trigger condition is met or not. When it trigger condition is met it will acquire the amount of data specified and the stop its execution. Isn't that exactly what you are requesting? As seen in the application we will look for the trigger condition as specified by falling/rising edge and the trigger level so we don't know how many iterations that will pass before this condition is met. When it is met we will start pushing in the data into the DMA FIFO and we have a small internal counter that counts up for every value read and when this value is equal to the number we want to read (specified by the "Samples to Read" control) it will stop.

See attached code that you can run on Windows without having to compile code on the FPGA. It is way easier to verify logic and such on Windows and when you are happy with the logic then you start adding the FPGA specific parts. Play around with the attached code, change falling/rising, see the iteration indicator how that one is updated.

Regards,

Jimmie A.

 

 

 

 

Regards,
Jimmie Adolph
Systems Engineering Manager, National Instruments Northern European Region

Message 6 of 17
(7,295 Views)

Good morning, 

 

The cRIO sounds more interesting, at the moment.

 

I apologize for confusing you, but it was my host code that wasn't working properly. I understood the FPGA code, but since the host code didn't work I thought it was the trigger's fault. But after a few test runs, I realized that it wasn't the FPGA code that did not run correct.

 

The project works fine now, but I believe I made the host code more complex than it needed to be. I think there is easier ways to make the host code run, until a trigger point has been reached. I used a Array Max & Min to compare with the triggering level. If the result is true, it aborts the While Loop, which aborts the program. Isn't there an easier way?

 

 

Regards,

Tim Jansson 

 

 

0 Kudos
Message 7 of 17
(7,270 Views)

Forgot to attach the VI. Sorry for double posting.

 

 

0 Kudos
Message 8 of 17
(7,268 Views)

Hello,

I put together this host application quickly. Just add the waveform creation based on your sample rate and # of samples. National Instruments Sweden will teach a course entitled “CompactRIO and LabVIEW course” on December 15th 2009 and you can read about the content in the course here:

http://digital.ni.com/worldwide/sweden.nsf/Web/All/3DF28A6E5222DE00802572ED001F4438?OpenDocument&node=167924_s 

It might be worth attending especially if you would like to do more projects based on cRIO. Hope this helps.

Regards,
Jimmie Adolph
Systems Engineering Manager, National Instruments Northern European Region

Message 9 of 17
(7,256 Views)
Solution
Accepted by topic author MightyEKA

Hello,

I hope to attend at the course. I thank you very much for helping me. It has given me insight and knowledge in cRIO!

 

Best regards,

Tim Jansson

0 Kudos
Message 10 of 17
(7,252 Views)