LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sampling continuously, peak/threshold detection on samples, acting upon results.

Hi everybody, I've been stuck with this problem for two days straight and don't seem any nearer to a solution. I would thoroughly appreciate any help any of you could give me.

As part of the test system I'm trying to set up, I have an analog input signal (50Hz sine, +/-8V, differential inputs) and several digital output signals. By setting one of these digital signals high, a relay (in hardware) is switched on, something goes open circuit, which means the analog input signal goes to zero. So, as long as the digital signal is low, I can read in this sine wave, but when set the digital signal high, the sine wave disappears.

I'd like to set up a way of setting this digital signal high when the sine wave reaches it's peak (or really, any value above 7.5 is fine) - to achieve, in essence, a cut-off sine wave. Later, the digital signal will be set low again, the sine wave will appear again, and I'll repeat the test later.

I am having a nightmare trying to get this working. I've experimented with peak detection and threshold detection VI's - the problem is: You can't really 'react' to the peaks because you don't get any information about peaks until the detection VI has finished it's execution. I've tried setting up a while loop with a simple "1 channel, 1 sample" read system (based on the DAQmx Create Channel, Start Task, Read, Clear Task VI's) , and then comparing the single sampled value to a threshold - the problem is, each iteration of the loop seems to take 8ms, which is far too long.

Since max sampling rates according to specs of the NI-6224 card are 250kS/s, is there no way that there can be a simultaneous 'read-in'/'read-out' system, where I could sample at 1kHz, but keep doing a compare on the value being read in, in real-ish time?

0 Kudos
Message 1 of 7
(3,140 Views)

Hi Chris,

      I'm sure this can be done easily, I just don't know the best way.  One way (not necessarily the best) would be to use an analog edge to trigger a "counter" (TTL) OUTput.  Start with the "Gen Dig Pulse-Dig Start" Example and modify it to trigger on an analog edge.  If the analog-trigger needs a 0-5V value, just use a couple of identical resistors to divide your voltage-in.  You'll have to learn some details in order to control the Counter's OUT state (high or low) post-trigger.

But don't do that! Smiley Wink  Better (simpler) would be to use an analog-edge to trigger a digital-output (not a Counter) - I'm just not familier enough with the NI-6224 to know this is possible - still, try to make THIS work first!

Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 2 of 7
(3,138 Views)
Hi tbd -

Unfortunately, you can't directly trigger a Counter task using an Analog edge.  You can only use a Digital Edge.  But there is a workaround.  Essentially, you need to set up an analog task that uses the Analog Edge trigger from an APFI pin.  Setting up any kind of trigger with this type of source will arm a comparator that fires the AnalogComparison Event every time the condition is met (even after the trigger has been used up).  You can use this event to trigger your pulse generation.  (You can generate the line voltage using either Counter Output or Correlated Digital Output.)

This post (by one of our best DAQ supporters) provides a good starting point.
David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 3 of 7
(3,118 Views)
Chris,

This line in the original post: "I've tried setting up a while loop with a simple "1 channel, 1 sample" read system (based on the DAQmx Create Channel, Start Task, Read, Clear Task VI's)..." sounds like an issue. Move everything except the read outside the loop. No need to create the task over and over again. A continuous acquisition with the data read in small chunks (according to your timing needs) might work as well.

Second, this sounds like a good place for parallel loops. The analog data acquisition is in one loop. Pass the data via queues or smart global VIs to a processing loop which looks for signal to exceed the threshold and writes to the DO line(s). Again the configuration of the digital port would be outside the loop.

I did something similar to this for a neuroscience experiment (in LV5). The speeds were slower since we were looking for a 3-8 Hz signal, but we were doing Fourier transforms and comparisons on different frequency bands. I think it could be speeded up to work at 50 Hz, especially with simple comparisons.

Lynn
0 Kudos
Message 4 of 7
(3,106 Views)

Hi David,

      Thanks for straightening me out on this.  I've used the level-triggering - for an analog task - and thought that all trigger-events were routable - so could be used by the counter too.  Do you know where this subject is documented? (not that I don't trust you. Smiley Wink - )

Cheers.

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 5 of 7
(3,098 Views)
Hello,
 
I found this in the DAQmx help when I searched for ARM Start Trigger.

"When you configure an Arm Start Trigger, a counter task does not respond to any Start Triggers until after the Arm Start Trigger occurs. You can configure this trigger to occur on a digital edge. The Arm Start Trigger is separate from a Start Trigger and is typically used in advanced counter/timer applications. You might use an Arm Start Trigger to synchronize multiple tasks, such as counting edges and pulse generation. The Start Trigger then would be used to start the acquisition or generation."

As mentioned above the trigger can be configured only for digital edges.

As far as using the Analog Comparison Event to know when the device receives and analog trigger, here is an article that talks about that.

Where is ATCOUT in NI-DAQmx? How Do I Know When My DAQ Device Receives an Analog Trigger?

Regards,

Raajit L

Message Edited by Raajit L on 02-12-2007 08:01 PM

Raajit L
National Instruments
Message 6 of 7
(3,068 Views)

Hi David, Raajit,

      Raajit, this: "When you configure an Arm Start Trigger, a counter" applies to triggering multiple counters simultaneously - we don't need to do that here. Smiley Surprised

This link suggests it is possible to use an analog start-trigger together with a counter.

Specifically: "If your board supports analog hardware triggering, there is an internal signal that is high whenever the signal on the trigger channel meets the trigger conditions. This signal can be routed to the counter to control it. Smiley Happy

As I said, I haven't done it, but this states it's possible! Smiley Wink

Cheers.

Message Edited by tbd on 02-12-2007 10:28 PM

Message Edited by tbd on 02-12-2007 10:30 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 7 of 7
(3,061 Views)