Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

counting analog triggers with mx and C

Hello,

This should be a simple problem but I'm having a bit of trouble. I'm trying to strobe cameras (with a TTL pulse) at a specified phase offset from a cyclical (sine or TTL) input signal that might not be centered about 0. I've set up a dummy analog AI start trigger, then I can use DAQmxCreateCOPulseChanTime to set a timed pulse, and DAQmxCfgDigEdgeStartTrig to start the pulse on my specified voltage crossing. I can call this repeatedly and get perfectly timed TTL output pulses - no problem.

But now I need to be able to keep up with the frequency, and I'd rather not have to do analog analysis. There's a ton of stuff in the knowledgebase about routing the analog trigger to a counter input but I just can't make any of it work. If I could get the analog trigger signal on an external pin, I could even live with that, but I can't manage to - Using DAQmxConnectTerms gives me an error that Dev1/AnalogComparisonEvent is invalid (same for Dev1/ai0/StartTrigger).

Once I get the frequency, I can calculate the time in seconds to delay the output pulse, to achieve a certain phase offset in degrees.

Cliff notes: I need to count pulses or find the frequency of the digital 'analog trigger' signal. If I could get it to an output that would work too. Using DAQmx and .NET with a PCI-6040E (PCI-MIO-16E-4). This article says it can be done but I just can't make it work - any help would be greatly appreciated!
0 Kudos
Message 1 of 8
(6,535 Views)
micahsimonsen,

Thanks for contacting National Instruments.  The article you reference is an explanation of trigger types that are available for these cards and how the trigger logic looks depending on the analog signal, I don't see how that helps you find the frequency of the analog trigger.  The resulting trigger signal would be an internal signal that the driver uses and you won't be able to route it anywhere that I am aware of, can you tell me where the KB's are that you spoke of early in your post?  An analog trigger signal is simply connected to PFI0 and then the trigger is configured in software.  Are you simply trying to send a trigger to your counter operation or are you trying to do a re-triggerable operation?

I am still a bit unsure as to what it is you are trying to accomplish.  If you attempt to do a DAQmxConnectTerms to a counter input and you are doing a counter operation you shold get an error that the device is reserved, which would make sense since you are doing a counter operation.  If you want to specify a specific source or gate signal there are seperate functions for that, but they accept digital signals (TTL) not analog signals. An example would be the CounterInputTimebaseSource and Rate to specify a different source input for the counter operation.

Hope this helps, further clarification would be appreciated.

Regards,
Kenn North
Principal Product Manager - Search, Digital Analytics
http://ni.com/search
0 Kudos
Message 2 of 8
(6,521 Views)
Kenn,

Thanks for the info so far - maybe I am not looking at this the right way.

Specifically, I'm trying to get an accurate frequency for a cyclical, analog signal, that might not cross 0.

Right now, I've set up a dummy AI task, and an analog trigger. Then, I can count edges of the trigger with this code:

DAQmxCreateCICountEdgesChan(ct,"Dev1/ctr1","",DAQmx_Val_Rising,0,DAQmx_Val_CountUp);
DAQmxCfgSampClkTiming(ct,"AnalogComparisonEvent",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);

Then I can use DAQmxReadCounterU32 to count, say, 1000 edges, divide by the time it took (software timed), and get a rough frequency. But what I'd really like to do is use the AnalogComparisonEvent as the input for a DAQmxCreateCIFreqChan task, to get a more accurate frequency.

The articles that describes exactly what I want to do is:
Measuring Frequency of a Periodic Analog Signal Using Counters and Hardware Analog Triggers
But it uses Labview. This article:
Using the Analog Trigger Circuitry Output
Also seemed promising but I can't find a way to make this happen with mx.

Any help would be greatly appreciated - thanks again.
0 Kudos
Message 3 of 8
(6,512 Views)
Hi Micahsimo,

The basic principle to export signal in DAQmx is using the function ExportSignal. The signal you are looking for is called "start trigger".
Still, I am unsure how this will help you strobe your cameras with a delay in them. I wold use digital IO controlled with one of the clocks to make sure you output correctly the signal.
If you can provide details of the specific application might be helpful.
Thanks,
Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 4 of 8
(6,498 Views)
Thank you very much! This is good... I've exported the trigger event to a PFI and now I can get a very accurate frequency measurement with DAQmxCreateCIFreqChan.

To clarify, my software has two  jobs. The first is to detect edges on the input signal (accelerometer, tach, shake table drive, etc), and generate pulses a short time after that. These pulses are at a user-specified phase after the input signal, so if the user wants a 100 degree phase shift, I need to figure out exactly how many microseconds that is.

Anyway, thanks to the ExportSignal code I'm getting an accurate frequency and the results look good. The only remaining hurdle is that, when my 'dummy' AI event is running so that I get analog triggers, I can't do a DAQmxCreateCOPulseChanTime task - I get an error about the sample clock being in use by the AI event, so I have to start one and stop the other repeatedly. I'm sure I can conquer and/or live with this though. Thanks again for the help!
0 Kudos
Message 5 of 8
(6,487 Views)
Hi Micahsimo,

That's great news. About the only hurdle, I would suggest to list all task that you are doing and see if there would be any conflicts with the timing sources. Just as some counter task require both internal counters, there are two timing engines inside the card and some task require to use one or the other.
Good luck,
Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 6 of 8
(6,476 Views)
Thanks for the continued help - I still haven't solved this, but it's not worth losing sleep over, either:

I actually have to stop exporting the signal to get the trigger to work. To create and export, I do this:

  DAQmxCfgAnlgEdgeStartTrig(dummyAiTask, "Dev1/ai0", DAQmx_Val_RisingSlope, val);
  DAQmxSetAnlgEdgeStartTrigHyst(dummyAiTask, 0.1);
  DAQmxCfgSampClkTiming(dummyAiTask,"",1000.0,DAQmx_Val_Falling,DAQmx_Val_HWTimedSinglePoint ,1);
  DAQmxExportSignal( dummyAiTask, DAQmx_Val_StartTrigger, "PFI8");

But if I try my trigger code:

    (initially)
  DAQmxCreateCOPulseChanTime( counterTaskHandle,"Dev1/ctr0","",DAQmx_Val_Seconds ,DAQmx_Val_Low,_delay,0.001,0.001);
  DAQmxCfgDigEdgeStartTrig( counterTaskHandle, "AnalogComparisonEvent", DAQmx_Val_Rising );

    (every pulse)
  DAQmxStartTask( counterTaskHandle );
 
I get:

Specified route cannot be satisfied, because it requires resources that are currently in use by another route.
Property: DAQmx_CO_CtrTimebaseSrc
Property: DAQmx_CO_CtrTimebaseActiveEdge
Source Device: Dev1
Source Terminal: MasterTimebase

Required Resources in Use by
Task Name: DummyAITriggerTask
Source Device: Dev1
Source Terminal: ai/StartTrigger
Destination Device: Dev1
Destination Terminal: PFI8

Task Name: CT

Status Code: -89137

So I have to insert this before generating my pulse:

    DAQmxExportSignal( dummyAiTask, DAQmx_Val_StartTrigger, "");

And then everything works great. It sounds like there is something about the internal routing that's preventing this, and again, it's not a high priority because the above line executes really fast. But if it's an easy fix that would be great too.

Thanks again,
Micah

0 Kudos
Message 7 of 8
(6,468 Views)
Hey Micahsimo,

Have you try a different PFI line? Turns out that PFI8 is your Counter 0 Source and therefore is conflicting when you create the CO task to generate pulses.
This is why when you call "DAQmxExportSignal( dummyAiTask, DAQmx_Val_StartTrigger, "");" you actually disconnecting this signal.
Good news everything seems to work, hope your experience was positive!

Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 8 of 8
(6,456 Views)