01-05-2009 03:01 PM
I am attempting to convert an application in VB.Net from using Traditional DAQ to DAQmx. The last piece is to pass a trigger over the RTSI bus from the DAQ counter to a Frame Grabber. The code currently used to set up the DAQ is:
ctlCWDAQTools.RouteSignal(1, _
CWDAQControlsLib.CWRouteSignalPins.cwrsPinRTSI0, _
CWDAQControlsLib.CWRouteSignalSources.cwrsSourceGPCTR0Gate)
With ctlAxCWCounter
.Counter = 0
.CountDirection = CWDAQControlsLib.CWCtrCountDirModes.cwctrUpDir
.TimebaseSource = CWDAQControlsLib.CWCtrTimebaseSources.cwctrFrequencyTB
.TimebaseSignal = 100000
.GateSource = CWDAQControlsLib.CWCtrGateSources.cwctrCtrGateGS
.GateMode = CWDAQControlsLib.CWCtrGateModes.cwctrLowGate
.UseBuffering = True
.NMeasurements = 1
.Configure()
End With
What would the equivalent setup be to replace this using DAQmx?
Thanks,
Dave
01-06-2009 03:35 PM
mpu,
If I understand your question correctly, you use the DAQmxConnectTerms() function to route a signal from one device through a RTSI cable to another device. For more information, you may reference this function in the NI-DAQmx C Reference Help.
01-06-2009 03:55 PM
pBerg,
Thanks for the prompt response. I did find the DAQmxConnectTerms() function to replace RouteSignal. What I have not found is how to start (trigger) the counter using a signal tied to the Gate input of the counter. I am having difficulty finding equivalents of the low-level control I was using in Traditional DAQ in DAQmx. I want to set up and enable the counter, then have it start counting when the Gate input goes low (my input signal is normally high).
Hopeful,
mpu
01-06-2009 05:07 PM - edited 01-06-2009 05:14 PM
Hi Dave,
In the DAQmx .NET API, you can use the ExportSignals.ExportHardwareSignal method. Here is a screenshot from the DAQmx .NET Help:
You can also find more information about implementing the counter in the DAQmx .NET Help (should be located at Start >> All Programs >> National Instruments >> NI-DAQ >> DAQmx .NET Framework Help) Let me know how everything goes or if any issues come up implementing the code in DAQmx. Thanks and have a great day!
-John
01-07-2009 08:15 AM
I should also mention that when you install DAQmx .NET support, it should include shipping examples in the following directory:
C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples
There should be numerous counter examples included that should help you get started.
-John
01-08-2009 10:19 AM
Thanks for the responses.
Let me take a step back here, ignoring how I was approaching this using Traditional DAQ. My ultimate goal is to asynchronously create a camera trigger on a 1409 frame grabber using a signal on RTSI0 in response to a digital signal coming in to my 6025E on one of the DIO lines. Currently that DIO signal (active low) is physically connected to the Ctr0Gate terminal (pin 25 -> pin 48). When the system is "armed" to wait for a trigger, the desire is to trigger the frame grabber on the falling edge of the DIO signal.
Below is the code I currently am trying to use to accomplish this (error handling and app specific stuff removed). Questions:
o Will this accomplish my goal or is there another method I should be using?
o Why do I need to use StartTrigger.DigitalEdge.Source = "/Dev1/PFI9" instead of "/Dev1/Ctr0Gate" (which is where the DIO line is physically connected) as it throws a run-time error "An attempt has been made to perform a route when the source and destination are the same terminal"
o Is the CounterOutputEvent what I need to be exporting to RTSI0, or is there a different signal that should be routed?
o Do I need the mownDAQCounterTask.Timing.ConfigureImplicit() line in my code? If so, why?
Thanks for your patience with me on this issue,
Dave
Private WithEvents mownFrameGrabber As AxCWIMAQ
Private mownDAQCounterTask As Task
Public Sub New()
'
' Use 6025E DAQ counter to relay digital input wired to Ctr0 Gate to RTSI0.
' 1409 Frame Grabber then triggered from RTSI0
'
mownDAQCounterTask = New Task("CameraTrigger")
mownDAQCounterTask.COChannels.CreatePulseChannelFrequency("Dev1/ctr0", _
"PulseGenCameraTrigger", COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0.0, _
100000, _
0.5)
'
'CounterOutputEvent exported to RTSI0 as trigger for frame grabber...is this what I want????
'
mownDAQCounterTask.ExportSignals.ExportHardwareSignal(ExportSignal.CounterOutputEvent, "/Dev1/RTSI0")
'
' DAQ Counter to be triggered on falling edge of DIO line
'
mownDAQCounterTask.Triggers.StartTrigger.Type = StartTriggerType.DigitalEdge
mownDAQCounterTask.Triggers.StartTrigger.DigitalEdge.Edge = DigitalEdgeStartTriggerEdge.Falling
'Why does "Dev1/Ctr0Gate" generate a runtime error when used as StartTrigger.DigitalEdge.Source?
'That is where DIO line is physically connected (DIO0 pin 25 wired to Ctr0Gate pin 48)
mownDAQCounterTask.Triggers.StartTrigger.DigitalEdge.Source = "/Dev1/PFI9" 'Does not accept /Dev1/Ctr0Gate
'Not sure if this is necessary?
'''mownDAQCounterTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 1000)
'
' Initialize the frame grabber and grab an initial image
'
With mownFrameGrabber
.Interface = "img0"
.LoadInterfaceDefaults()
.StartCondition = CWIMAQStartConditionTypes.cwimaqImmediately
.StopCondition = CWIMAQStopConditionTypes.cwimaqOneShot
.AcquireImage()
End With
End Sub
''' <summary>
''' Enables asynchronous image acquisition.
''' </summary>
Public Sub ArmFrameGrabber()
'
'Set up to acquire one image asynchronously
'
mownDAQCounterTask.Start()
mownFrameGrabber.SetTrigger(CWIMAQTriggerLines.cwimaqTriggerLineRTSI0, _
CWIMAQTriggerActions.cwimaqTriggerCapture, _
CWIMAQTriggerPolarities.cwimaqTriggerActiveHigh)
mownFrameGrabber.StartCondition = CWIMAQStartConditionTypes.cwimaqHardwareTrigger
mownFrameGrabber.StopCondition = CWIMAQStopConditionTypes.cwimaqOneShot
mownFrameGrabber.FrameTimeout = &H7FFFFFFF
mownFrameGrabber.Start()
'
End Sub
01-08-2009 11:03 AM
Adding to my last post:
What I really want is to have the counter count when the DIO line is low and stop counting when it is high. I don't really want to trigger on the edge as my code indicates, but I don't see how to start and stop the counter as I would like. Perhaps StartTrigger is the wrong approach. I still need to signal RTSI0 when the counter does start.
Also, I want to use the internal clock as my clock source (equivalent to ctlDaqCounter.TimebaseSource = CWCtrTimebaseSources.cwctrFrequencyTB in my old code). I tried using Timing.ConfigureSampleClock() but it throws a runtime error showing a conflict with the trigger setup.
--Dave
01-08-2009 06:21 PM - edited 01-08-2009 06:24 PM
Hi Dave,
Thanks for the update and extra information. It
sounds like what you want to be using is a Pause Trigger (see the E
series manual, page 5-2). This will start and stop the counter as you described:
I do not believe there is a way to export an Arm Start Trigger. You could however use an external signal to trigger both the counter and the 1409. In .NET, you would use the following function to enable an Arm Start Trigger (the counter will not begin until it is armed):
Do you mean that you want to use the 20 MHz timebase as your source? This is the upper limit of what an E series can use as the source for a counter task. Our E series devices have 24-bit counters, so they can count up to 2^24 ~16 million. A 20 MHz source would hit this limit in about 0.8 seconds. That being said, you should still be able to do this in theory, what was the runtime error that you received?
-John
01-09-2009 08:26 AM
Thanks, John. I will try the Pause Trigger technique you mentioned.
Actually I am trying to use the 100KHzTimebase signal as my source clock. As I mentioned, in my old code I used the following to set that up:
ctlDaqCounter.TimebaseSource = CWDAQControlsLib.CWCtrTimebaseSources.cwctrFrequencyTB
ctlDaqCounter.TimebaseSignal = 100000
I haven't figured out what the equivalent DAQmx method is to perform that operation. Can you point me to the correct one?
When I tried Timing.ConfigureSampleClock("", 100000, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples)
I get the error "Sample Mode is set to a value other than Hardware Timed Single Point. This is the only value supported for the counter generations when Sample Timing Type is set to Sample Clock"
If I try Timing.ConfigureSampleClock("", 100000, SampleClockActiveEdge.Rising, SampleQuantityMode.HardwareTimedSinglePoint)
I get the error "Specified Start Trigger Type is not supported for counter output tasks when the Sample Mode is Hardware Timed Single Point on this type of device."
It appears that ConfigureSample Clock is not what I'm looking for to specify the internal 100KHz clock as my source. I don't know what the right way is, though.
I do realize that I could use the external signal directly to trigger the 1409, but I have additional conditions in my software that want to allow blocking the signal until it is OK to allow a capture. The external hardware that generates my DIO trigger is saying "I have a part in place...take a picture". If my software is busy (e.g. still processing the last image), I want to be able to keep the frame grabber from immediately taking a trigger directly from that signal. I am doing that by only passing it on when I have started the Counter task and using the counter, essentially, as a programmable relay. This has worked for us for 10 years on this system. If there is a better alternative to using the Counter to pass on the signal only when I allow it, I would love to hear it. I'm open to any better ways of doing things.
--Dave
01-09-2009 09:48 AM - edited 01-09-2009 09:49 AM
Hi Dave,
An important thing to note is the difference between Sample Clock and Source in DAQmx. The Source is the signal that you are counting. You should be able to set this to the 100kHz timebase using the CIChannel.CountEdgesTerminal property:
Sample Clock, on the other hand, refers to the clock that is used to sample the count register--it does not affect whether the count register increments or not, but rather how often you transfer data from the count register into your buffer. It doesn't sound like you should need to set this in your application, but if you ever needed to do this you would have to use an external sample clock with your hardware (regardless of which driver you are using).
The extra information about how you intend to use the external signal should be helpful in coming up with the best way to accomplish your goal. From your first post, it looks like you were originally routing the signal from the Gate to RTSI0. You should be able to do the same thing using the ConnectTerminals Method of the DaqSystem class: