Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Linear encoder sample clock source on PCI-6602 using C functions

Hi,

 

I'm trying to measure linear position with a quadrature encoder using a PCI-6602 device. I'm not using LabView but the NI-DAQmx C functions. I don't know how to set up the sample clock source for the linear encoder task. From https://decibel.ni.com/content/docs/DOC-14202 I understand that I should create a pulse train on a second counter channel, and use this as sample clock source for the linear encoder task.

I tried to do that in the following way:

- create a pulse train on 'dev1/ctr1' using DAQmxCreateCOPulseChanFreq

- create a linear encoder input task on 'dev1/ctr0' using DAQmxCreateCILinEncoderChan

- set the sample clock source terminal for the linear encoder task to '/dev1/Ctr1Out' using DAQmxCfgSampClkTiming

This resulted in the error -89120 when starting the linear encoder task (InvalidRoutingSourceTerminalName_Routing)

Then I tried the same using a second device (PCI-6052, RTSI cable between the two devices) to create the pulse train (pulse train channel = 'dev2/ctr0' and clock source terminal for encoder task = '/dev1/Ctr0Out') Now the encoder task started correctly, but the pulse train task returned an error -50103 (PALResourceReserved). However, the linear encoder task seems to receive pulses at 1kHz and works correctly, but since I can't start the pulse train I am not able to use a different sample frequency.

 

Am I doing something wrong in specifying the source terminal for the sample clock? Or am I forgetting something else?

0 Kudos
Message 1 of 2
(5,488 Views)

I think I found the answer already, so sorry for posting. It seems to work OK if I specify 'Ctr<x>InternalOutput' on the 6602 or 'Ctr<x>Out' on the other device as clock source. However, since I use 'continuous samples' for the pulse train, the pulse train continues even after I stop and clear the corresponding task, so that's why I get the -50103 error if I run my script for the second time. I could use 'finite samples' for the pulse train but I don't like that since I don't know on forehand how long I need to measure. If anyone knows a solution to this, I'd like to know.

0 Kudos
Message 2 of 2
(5,485 Views)