LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to continously sample counter signal for quadrature linear encoder

Solved!
Go to solution

Dear all,

 

I am trying to continuously sample displacement value of Schneeberger quadrature linear encoder at certain frequency like 10Hz and output to text file. Whatever I choose in the external clock I cannot run the DAQ assistant. Does anyone know how to fix it? I am not sure which kind of clock can I use.

 

I have read some answers that ppl connect another sample clock in parallel with the counter channel. But I don't know what is the working principle of this method. 

 

I spent like 10hours on that already. Could any one tell me some related information?

 

Looking forwad to your help! Thank you very much!

 

Best regards,

George

0 Kudos
Message 1 of 10
(5,925 Views)

Ho Georgeyy,

 

Does your DAQ device have counter on it? If it does you should be able to do hardware timing. Otherwise you need to use software timing https://decibel.ni.com/content/docs/DOC-9640.  Also take a look at LabVIEW>>Help>>Find Examples>>Hardware Input and Output>>DAQmx>>Counter Input>>Counter-Read Counter.vi. 

National Instruments
Applications Engineer
0 Kudos
Message 2 of 10
(5,898 Views)

Hello Edna-S,

 

I am using NI 6212, there are 2 counters but I just can't choose the right one directly from the list. I was wondering what kind of special connection and subVI needed to be added.

 

Thank you very much.

 

George

0 Kudos
Message 3 of 10
(5,886 Views)
Solution
Accepted by topic author Georgeycw

Hi George,

 

You'll want to use the DAQmx API rather than the DAQ Assistant.

 

The encoder task by itself would look something like this.  You don't need to use any of the triggering options.

 

The catch is that you will need to generate a clock from some other source as the card can't generate counter sample clocks directly.  The easiest is probably to use the second counter.  Here is an example showing how to use a counter output as a sample clock (although the example shows analog input, just replace the analog input task with the encoder task shown in the previous example I linked).

 

So you would use a counter (say, ctr0) for the encoder task, then the other counter (ctr1) for the sample clock generation.  You would specify on your encoder task to use the InternalOutput of ctr1 as the sample clock (if the counter's internal output doesn't show up in the drop-down, right click the terminal and select I/O Name Filtering>>Include Advanced Terminals).  Start the encoder task before the output task (although since both are running continuously it doesn't really matter that much).

 

 

 

Alternatively, 10 Hz isn't too fast.  If exact timing isn't as important and the above seems a bit overwhelming, it might be easier for you to just run a software-timed 100 ms loop starting with an example like this.  Note that the exact loop time might will vary from cycle to cycle, so this method wouldn't be very good if you are using the sampled data to perform rate calculations.

 

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 10
(5,877 Views)

Hi John,

 

I really thank to you because I have solved the problem by your suggestion. To choose a right internal counter is difficult especially the one in advanced option. really thanks for your help!

 

I would like to ask do you know what is the relation of no. of samples to channel from the DAQmx read and sample clock to the acquisition frequency from the sample clock? Can I output the time stamp to record the time and output at the same time?

 

Furthermore do you know what is the function of Z-index in linear encoder? I only know that Z-index help recount pulse after one rotaion to reduce accumulatative error. But how does it work in linear encoder?

 

thank you very much!

 

Attachment is my encoder program for reference.

 

Cheers,

George

0 Kudos
Message 5 of 10
(5,846 Views)

You might be able to find some answers in the manuals section here http://sine.ni.com/nips/cds/view/p/lang/en/nid/207096. and here http://www.ni.com/white-paper/7109/en.

National Instruments
Applications Engineer
0 Kudos
Message 6 of 10
(5,822 Views)

Hi George,

 

The "samples per channel" input on the DAQmx Timing VIs is only used to increase the buffer size in continuous mode.  It isn't really too important in the vast majority of applications.  In finite mode however, this is what specifies how many samples you wish to acquire.

 

The "number of samples per channel" input on DAQmx Read specifies how many samples you want to read per iteration.  The default is -1; on a continuous task the read call will return whatever data is currently available.  I usually avoid -1, as this will return an empty array if there is no data available.  Instead, I usually specify the number of samples per channel to be some fraction of my sample clock rate (e.g., reading a number of samples equal to 1/5th of my sample clock rate would result in my loop running 5 times per second).

 

You could certainly log a timestamp to your file, but you won't be able to get it straight from the DAQmx Read call--you would have to build it yourself programmatically (should be easy enough--the dt is the inverse of the sample clock rate).

 

The Z index works the same way for a linear or an angular encoder--it resets the count to some pre-defined value.  It's probably more commonly used on an angular encoder, but if your linear actuator has a "home" position it might make sense to incorporate a Z index in this application as well.

 

 

 

Best Regards,

John Passiak
0 Kudos
Message 7 of 10
(5,814 Views)

Hi john,

 

Thank you very much for your answer. 

 

It sounds strange that only 1/5 of sample per chennel is read in an iteration. The rate sets the no. of read iteration per second, so further increase of number of samples per channel increase the no. of samples in an iteration?

 

That means I need to create another sample clock?

 

The manual said that the Z index can rectify missing counts of A and B signals due to long distance travel. It's an extra scale with 40um microns span. It sounds reasonable but sounds new to program.

 

I found that I only can operate the program when choose Counter DBL 1 sample, but not Counter DBL N samples. do you know about it?

 

Thank you very much!

 

Best regards,

George

0 Kudos
Message 8 of 10
(5,758 Views)

Hi George,

 

I'll go over each of your questions:

 

 

It sounds strange that only 1/5 of sample per chennel is read in an iteration. The rate sets the no. of read iteration per second, so further increase of number of samples per channel increase the no. of samples in an iteration?

 

I mean that for each iteration of your software loop, the read call will return a specific amount of samples corresponding to "number of samples per channel".  The data is still sampled off of the sample clock.  At high rates you have to read more than 1 sample per loop (for exampe, if you were clocking your sample clock at 100 kHz, the loop would not be able to keep up with the data coming in by reading only a single sample per loop).  You don't need another sample clock--by specifying a number of samples per channel, the loop will run at the required rate (in Hz: sample rate / number of samples per channel).

 

 

The manual said that the Z index can rectify missing counts of A and B signals due to long distance travel. It's an extra scale with 40um microns span. It sounds reasonable but sounds new to program.

 

So the Z index repeats every 40 um?  You can reset your count based on this signal if you wish, but is this useful for your application?

 

 

I found that I only can operate the program when choose Counter DBL 1 sample, but not Counter DBL N samples. do you know about it?

 

 

Well if you're reading -1 samples like you were in the .vi you linked earlier, this would result in empty arrays being returned from the read call unless data is available.  You didn't really specify what behavior you see when you're reading Counter DBL N Samples, but I suspect you aren't specifying the number of samples per channel input and you are getting empty arrays back.  Or... perhaps you are specifying too high of a samples per channel and you are getting timeouts?

 

 

Best Regards,

John Passiak
0 Kudos
Message 9 of 10
(5,733 Views)

(Duplicate Post)

 

Best Regards,

John Passiak
0 Kudos
Message 10 of 10
(5,732 Views)