From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

External sample clock with encoder

Solved!
Go to solution

Hi everybody,

 

I have an external encoder wired to a 9423 module on a 9185 chassis, where i count the impulses of the encoder using channel A and B.

I also have some sensors connected to a 9205 analog Input module. Now I want to use the counter as a sample clock on the PFI on the 9205 module. So basically I have to route the counter signal to the PFI. At least I think that is the best approach. No idea how though. Probably easy with LabView, however I am not using it. Instead I am using Matlab or VS\C++.

 

If I connect one channel (A or B) ´from the encoder to PFI on the 9205,  I can set up the clock without a problem as an external clock connection. Then I wait until x-samples are gathered and execute some functions.

 

So basically my question is, if it is possible to use the counter from the digital input module (I have an output module too, it that helps) as a means of controlling the sampling rate of the analog module? Or am I looking at this wrong?

   

Here the basic set up in Matlab, if it will do any good.

s = daq.createSession('ni'); % Create session

ch1 = s.addAnalogInputChannel('cDAQ9185-1C7CD64Mod1','ai0', 'Voltage'); % analog Input channel

cc = addClockConnection (s,'External','cDAQ9185-1C7CD64Mod1/PFI0','ScanClock'); % set an external clock (e.g. channel A from the encoder)

 

Cheers

0 Kudos
Message 1 of 12
(5,664 Views)

I don't know that much about internal wiring options on the cDAQ, but you could always just parallel wire one of the A,B channels to both modules externally.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 12
(5,648 Views)

I could, and basically that is how it is set up right now. Using the PFI Input on the 9205. However I actually wanted to use the internal counter from the DI module as a trigger source. Not only as a start trigger, but as a continous trigger (like an external clock)

 

 

0 Kudos
Message 3 of 12
(5,624 Views)

Sure, you can generate a pulse train from another counter and use it as an AI sample clock in the other module.  I don't know if you can route the clock signal internally or whether you'll need to do physical wiring.

 

Often, using the pulse train as a sample clock is enough by itself.  Start triggering the AI task may not be necessary.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 12
(5,597 Views)

First of all thanks for your answers. I was out of office for quite some time, but now I should be able to focus on the task at hand. That for sure will require some patience, as I am still trying to figure out, what is possible and what is not. And also what the best solution in my case is.

Some things probably are easy to achive in LabView, however I am a bloody beginner on this topic. That's why I am using Matlab, as mentioned before.

 

What I can do so far:

  • Using a counter to measure the distance (encoder is connected to my DI module, shown in my sketch)
  • Routing channel A or B externally to the PFI0 on the analogue module. This works as my external clock on the 9205 module. As you mentioned, start triggering is not necessary.

If that is the best way to achieve my goal, so be it. Then the counter basically only is used for the distance measurement and there is no need for my DO module at all. My original idea was to convey the "ticks" of the counter (1,2,3,...) to the DO module (NI 9474) and from there link it with the 9205 module.

 

Well, of course I can set a pulse train on my DO module, however as I understand it, only with a given frequency. The impulses of my encoder come as they like. For experimental reasons, I tried it anyway. I then linked the blinking DO with the PFI0 of the analogue module (just like I did it with channel A from the Encoder), to no avail. I expected it to acquire analogue data with the set frequency.

 

I apologize if my post seems a bit confused to you. In fact I am. At the beginning the range of opportunities can be a bit overwhelming. Maybe I have to take a look into LabView, as internal routing seems straight forward there.   

Download All
0 Kudos
Message 5 of 12
(5,492 Views)

I made one slight modification. There was no need to physically connect a wire to the PFI0 on the analogue module.

My Destination of my clock Connection is already connected to the DI module, therefore I just use that. Pretty obvious in retrospect

 

For now, the system cannot distinguish between directions. It just Counts flanks. In order to achieve this I would need channel B too. Therefore the counter would come in handy.

 

In Matlab that looks as follows:

cc = addClockConnection (s,'External','cDAQ9185-1C7CD64Mod2/PFI0','ScanClock'); % Mod2 is the DI module

 

 

0 Kudos
Message 6 of 12
(5,489 Views)

I think I need a little more "big picture" description about your end goal.

 

What are the sensors you're measuring?  What do the measurements mean for you?  Are you also generating signals in response?  What important about the timing relationships among all the inputs and any outputs?

 

So far I gather that you have an encoder and an analog signal.  As you've found, you can use the digital encoder signals as an external sample clock for your analog task.  I don't follow what mean about "conveying ticks of the counter (1,2,3,...) to DI and AI modules".

 

The numerical count value is distinct from the TTL signals that the counter task uses to increment the count value.  The count value cannot be routed (conveyed) as though it were a hardware signal.  If you want to react at a specific count value, that would have to happen through software.  In order to get a faster response, you'd have to run a fast software loop that kept querying the count value and deciding what to do about it.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 7 of 12
(5,483 Views)

Your last paragraph explains quite a lot. A misconception was, that I can use the count value in order to generate signals (pulses) on the DO module and then use that as my sample clock.

 

I will try to answer your questions:

I have several laser distance sensors which continously send the measured analogue values to the NI module. The acquisiton of the data is controlled by a rotary encoder. So basically every sampled value of the laser sensors corresponds to a specific encoder position. It should sample only in one direction though.

I am not generating any signals in response.

The sensor values should be sampled simultaneously.  

 

The solution for me right now is acceptable. The direction issue I can solve through software using the counter value. I just wondered if it was possible using the DO module.

 

Cheers

0 Kudos
Message 8 of 12
(5,463 Views)
Solution
Accepted by topic author gagamehl

Since it sounds like you have a quadrature encoder (you referenced channels A & B), there's a neat trick that might work for you.

 

If you look carefully at a quadrature pattern, you'll find that for one direction of rotation, rising edges on A occur when B is low. For the other direction of rotation, rising edges on A occur when B is high.

 

So for your analog input task, you could use rising edges of channel A as a sample clock while using the digital state of channel B as a "Pause Trigger." With a Pause Trigger, sampling is enabled/disabled based on the digital state of the trigger signal.

 

 

- Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 9 of 12
(5,449 Views)

I indeed have a quadrature encoder and yes, your idea with the pause trigger works like a charm.

There doesn't seem to be a proper command for the pause trigger in Matlab, though. However it is really no problem to implement it in C++, for instance. As I only use Matlab for optimization it doesn't really concern me any further.

 

Big thanks for the input and I consider this topic as solved (for now ;)) 

 

0 Kudos
Message 10 of 12
(5,438 Views)