Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read two counters simultaneously?

Solved!
Go to solution

I am using cDAQ 9174 and NI 9401 to access the counters.  I wrote a vi that successfully measured the period fo the tick marks on an encoder wheel.   The vi measures 15 periods, writes them to an array, and then finds the average value.

 

Now, I want to use TWO counters, and measure the average period of TWO encoders simulataneously, and then add some other calculations to control the drive motors etc.

 

So, I was advise to try Producer/Consumer architecture, and I developed the attached vi.

 

Here are a few questions for which I'd appreciate some feedback.

 

1.) I have THREE STOP functions on the front panel, one for each WHILE loop.  How do I consolidate these to become a single STOP for the whole vi?

2.) On the DAQmx Create Channel, I have selected "Low frequency with one counter" because originally, the vi was for only one counter. Is this OK when I have two counters operating in the same vi?

3.) Lastly, the way the averaging is done here, the values are averaged 0 through15, then 1through 16, then 2 through 17 etc.  I would prefer to average 0-15, and then 16-30, and then, 31-45 etc.  Can you tell me how to adjust the way the averages are calculated?  Maybe this has to do with the way we have the shift registers configured?  Or, should I use a FOR loop, and iterate 15 times?

 

Any other comments are more than welcome!!!

 

Thanks a lot for your help.

Dave

0 Kudos
Message 1 of 9
(8,839 Views)

Hi dav2010

 

In relation to your issue, I have some answers for your questions:

  1. To make all the Stop buttons to become just one signal, you need to have only one button and have local variables in the other loops.
  2. The two counters will operate independent from each other so  it is ok to set them the way you did.
  3. I think you should remove the shift registers, in that case each loop iteration you will get the max, min and mean for all the samples read in that loop, in the next loop you will have new values. You can auto index in the while loop all this values and have the final general results when the program ends.

I don’t think you need to have a producer/consumer format for this application, I would rather have only one while loop with both counter tasks in it.

 

Regards,

steve.bm
AE | NI
0 Kudos
Message 2 of 9
(8,826 Views)

Hi STeve,

 

Thanks for the input.  Can you add some details to the suggestion about  "you need to have only one button and have local variables in the other loops."  How does that work?  I don't understand what you mean by that?  Put local variables ...where and how??  When I eliminate any of the existing STOPs, I get this error:

 

"Th conditional terminal is not wired to anything and must be wired to a boolean data source such as a button or the result of a comparison."  Can you show me what you mean?  Which loop would the single STOP reside in, and how do you make a WHILE loop error free without a wired STOP in place?

 

If I put both counters in the same loop, will that work?  How do I understand the order of execution?  For example, I want the vi to period values simultaneously and independently, for two encoder wheels.  I want the vi to calculate an average value of the 15 periods, and then allow me to compare/calculate etc.

 

Thanks,

Dave

0 Kudos
Message 3 of 9
(8,824 Views)
Solution
Accepted by topic author dav2010

Hi!

 

This picture shows what I meant by using only one stop button and a local valiable linked to it.

 

Then, if you want separate measurements, so use one while loop to each counter, and forget that last advice from me Smiley Wink

 

Regards,

steve.bm
AE | NI
Message 4 of 9
(8,821 Views)

So, now that I was able to offer a little more clarity about my goal with the vi, do you agree that the producer/consumer architecture is a good choice?

 

Thanks,

Dave

0 Kudos
Message 5 of 9
(8,812 Views)

Hi Dav,

 

You can try to do it first without the producer consumer, I think you won’t need it, because it seems that you are not going really fast, if you do it without the producer consumer and you see that you are missing counts, you can go back to the original design, but I’ll say that you’ll be ok without it.

 

Regards,

steve.bm
AE | NI
0 Kudos
Message 6 of 9
(8,797 Views)

Thanks, Steve.  What I found out is that with my new encoder, 120 per revolution, the WHILE loop structure I was using cannot keep up; the previous encoder that I was using had only 4 ticks per revolution.  So, now, I want to count ticks in a fixed time interval, e.g. 100 ms repeatedly.  Is there a way to configure this so that I can get the ticks passed every 100ms, for example?  Alternatively, I could fix the number of ticks, e.g. 30 ticks, and ask the VI to output the time it took to do 30 ticks.  Can either of these be done conveniently?

 

Thanks,

Dave

0 Kudos
Message 7 of 9
(8,792 Views)

Hi dav,

 

I would like to recommend you to open this manual, and go to page 7-5, the method shown there (Buffered Edge Counting) is what you need.

 

You will find examples for this in the NI Example Finder installed in your computer.

 

 

Regards,

steve.bm
AE | NI
0 Kudos
Message 8 of 9
(8,782 Views)

Hi STeve, I'd like to revisit this manual that you recommended and look again at Buffered Edge Counting, but, the link no longer works.  Can you help me find this manual again?  This manual was very helpful to me a few months ago when you first suggested it.

Thanks,

Dave

0 Kudos
Message 9 of 9
(8,604 Views)