03-13-2013 06:48 PM
I have a PCIe-6351 and I am trying to read the position from a linear encoder referenced to a digital trigger. The digital trigger occurs in the middle of the motion that I am interested in, so I would like to capture a fixed number of pre-trigger and post-trigger encoder samples. The graph below illustrates what I'm trying to get:
I have previously used the ReferenceTrigger with success on my AI channels to aquire analog data pre/post-trigger, but when I attempt to do the same with my LinearEncoderChannel I get "Error -200452: Specified property is not supported by the device or is not applicable to the task."
Am I doing something wrong? Or is the ReferenceTrigger feature not available for the LinearEncoderChannel? If it is not available, can you suggest an alternative method to acquire my pre-trigger position data?
I am developing in VB .NET 3.5. My non-functioning code is as follows. It throws the Error -200452 exception on the call to "myEncoderTask.Triggers.ReferenceTrigger.ConfigureDigitalEdgeTrigger":
Public Sub RunTest()
Dim myEncoderTask As Task = Nothing
Dim myClockTask As Task = Nothing
Try
'Create new Tasks
myEncoderTask = New Task()
myClockTask = New Task()
'Initialize Local Variables
Dim PreSamples As Integer = 5000
Dim TotalSamples As Integer = PreSamples + 20000
'Create the linear encoder counter input channel
myEncoderTask.CIChannels.CreateLinearEncoderChannel("PCIe6351/ctr0", "Encoder", CIEncoderDecodingType.X4, _
False, 0, CIEncoderZIndexPhase.AHighBHigh, 4, 0, _
CILinearEncoderUnits.Meters)
'Create the clock output channel
myClockTask.COChannels.CreatePulseChannelFrequency("PCIe6351/freqout", "Clock", COPulseFrequencyUnits.Hertz, _
COPulseIdleState.Low, 0, 6250, 0.5)
'Configure Clock Timing Specs
myEncoderTask.Timing.ConfigureSampleClock("/PCIE6351/PFI2", 6250, SampleClockActiveEdge.Rising, _
SampleQuantityMode.ContinuousSamples, TotalSamples)
myClockTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, TotalSamples)
' Configure Reference Trigger
myEncoderTask.Triggers.ReferenceTrigger.ConfigureDigitalEdgeTrigger("/PCIE6351/PFI1", _
DigitalEdgeReferenceTriggerEdge.Rising, PreSamples)
' Verify the Tasks
myEncoderTask.Control(TaskAction.Verify)
myClockTask.Control(TaskAction.Verify)
myClockTask.Start()
'Read the data
Dim myReader As New CounterReader(myEncoderTask.Stream)
Dim data() As Double = myReader.ReadMultiSampleDouble(TotalSamples)
Catch ex As Exception
Finally
myEncoderTask.Dispose()
myClockTask.Stop()
myClockTask.Dispose()
End Try
End Sub
Any help would be greatly appreciated.
Thanks,
Eric
03-14-2013 12:03 PM
Eric,
Unfortunately a referenced trigger cannot be used for counter tasks. Would it be possible for you to change the point at which the trigger occurs?
03-14-2013 12:47 PM
Hi James,
Thanks for your reply!
No, unfortunately I cannot change the point at which the trigger occurs. That trigger is generated by a physical event that must occur in the flat "bottom" of my position trace.
My challenge is that this motion is a repetitive one. I'm trying to repeat the motion many times to generate statistics. I was hoping to avoid capturing many iterations with one long trace and then manually cutting up the trace piecewise and aligning the time bases after the fact.
Can I synchronize my counter task to a digital channel task? I'm thinking I might simultaneously log the trigger while capturing several motion iterations, then I could at least write some post-processing software to do all the subdividing and time base alignment for me. Can I modify the "SyncAI_ReadDigChan" example from the documentation, using a counter task instead of an AI task? Or will I run into similar problems as I did when I tried to use the referenced trigger with the counter task?
Do you have any other suggestions I might try?
Thanks,
Eric
03-15-2013 02:13 PM
Eric,
You may be able to use a 'dummy task' to synchronize the counter and digital task, as in the following link:
https://decibel.ni.com/content/docs/DOC-11755
Also, what is your sampling rate/number of samples you are recording?