Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

6601/6602 Counters

Hello,
 
I recently downloaded an evaluation of MS 8.0.1 and some example code in VB.net and C# came with it.  I am petty new to this and am trying to use the counters, but have no idea how they work.  It says in the CountDigEventsContinuous_BufferedExtClk example that:
 
 "An external sample clock must be used.  Counters do not have an internal sample clock available.  You can use the GenDigPulseTrain_Continuous example to generate a pulse train on another counter and connect it to the sample clock source you are using in the CountDigEventsContinuous_BufferedExtClk example." 
 
1. How would you connect one counter to the next?  using the "DaqSystem.Local.ConnectTerminals()" method?

         a. If so, what is the syntax to use?

2. What would all the settings be?

         a. What would the Channel and Timing parameters be for CountDigEventsContinuous_BufferedExtClk?

3. Are there any other extra lines of code that need to be added and where?

4. What should the output look like if it is working correctly?

 

Thanks,

mtonsager

0 Kudos
Message 1 of 16
(5,521 Views)
Hi mtonsager,

There are two ways you can route the pulse train to the counter you are using for event counting.

1. The pulse train will be output to a PFI line. You can physically connect two PFI lines with a wire. Then select the second PFI line as the clock source for event counting.

2. You can use the DaqSystem.Local.ConnectTerminals and route the Ctr0InternalOutput or Ctr1InternalOutput (depending on which counter you are using to generate the pulse train) to a PFI line. This will internally connect the output of the counter to the PFI line of your choice. Then you can choose this PFI line as the source of your clock. However, you need to make sure that an internal route is possible. You can check that by opening the Measurement and Automation Explorer (MAX). Select your card under NI-DAQmx Devices. You will see a tab at the bottom on the right side that says Device Routes. Select that tab and you will see all possible internal connections that can be made.

Have a good one.

Malay Duggar
NI
0 Kudos
Message 2 of 16
(5,489 Views)

Thank you very much for the reply.

I was able to get everything to work through the DaqSystem.Local.ConnectTerminals.

My main goal is to simulate a count/digital signal that the 6601 card will be receiving from an optical device that sends the signal 6-10 times a second.

I am curious as to what the dutyCycle does.  Whenever I change the duty cycle I don't see any differences in the output.  So, what is the duty cycle used for and what are the value ranges for it?

Also, eventually I will have to be able to Filter out Noise from the signals.  What do I need to know?  What would be the best filter to use and how would I implement this using .NET and Measurement Studio 8.0?

Thank you much,

mtonsager

0 Kudos
Message 3 of 16
(5,484 Views)

Hi mtonsager,

The duty cycle is defined as the ratio of the duration (time) that a signal is 'on' to the total period of the signal. So a 50% duty cycle would be when the signal is high and low for equal amounts of time (which is generally the case).  Generally you have to set the duty cycle before you begin the generation.

There are certain digital filters available to you. The Help file for your device and go to TIO Series Help -> Counters -> Digital Filters has all the information. There is some additional information in the M Series DAQmx Help (M Series Help -> Counters -> Other Counter Features -> Filters).  There is also an example program which shows how to turn on the Filter using a property node.

Cheers
Malay

 
Message 4 of 16
(5,455 Views)
 

Hi Malay,

Thanks for the reply again.

I searched through the documentation, but I am not sure what I need to open up a .vi file because I only have .NET and MS 8.0.1. 

However, I did more testing to figure out how the filters work and I know I must be close, but am having no luck in filtering out by pulse width.

First, I connected the two counter terminals:

 

DaqSystem.Local.ConnectTerminals("/Dev1/Ctr0InternalOutput", "/Dev1/PFI33");

 

Second, I set up a Pulse train:

taskPulseTrain =

new Task("test");

 

taskPulseTrain.COChannels.CreatePulseChannelFrequency(

"Dev1/ctr0", "External", COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0, 100, .0002);

 

taskPulseTrain.Timing.ConfigureImplicit(

SampleQuantityMode.ContinuousSamples, 1000);

 

taskPulseTrain.Start();

Third, I set up the second Buffered task to read the filtered counts:

t =

new Task();

 

t.CIChannels.CreateCountEdgesChannel(counterComboBox.Text,

"COUNTIN", edgeType, Convert.ToInt64(initialCountTextBox.Text), countDirection);

 

t.Timing.ConfigureSampleClock(sampleClockTextBox.Text,

Convert.ToDouble(rateTextBox.Text), SampleClockActiveEdge.Rising,SampleQuantityMode.ContinuousSamples, 1000);

 

t.Control(

TaskAction.Verify);

 

t.CIChannels.All.CountEdgesDigitalFilterEnable =

true;

 

t.CIChannels.All.CountEdgesDigitalFilterMinimumPulseWidth = .008;

myCounterReader =

new CounterReader(t.Stream);

 

 

myCallBack =

new AsyncCallback(CounterReadCallback);

 

myCounterReader.SynchronizingObject =

this;

 

 

myCounterReader.BeginReadMultiSampleDouble(

Convert.ToInt32(sampleToReadTextBox.Text),myCallBack,null);

 

 

I found this equation here  duty cycle = 100*(pulse width/period)  where period = 1/Frequency OR  pulse width = period*(duty cycle/100)

Given this equation I figure the pulse width of my taskPulseTrain is (1/100Hz)*(.0002/100) = .00000002

So, when I set up the minimum pulse width to be .008 it should filter out all the pulses in the taskPulseTrain because all of the pulse widths are too short, right?

I am not sure why I keep getting the same results when I change either my minimum pulse width on the filter or my duty cycle in the pulse train.

Thanks,

Mtonsager

0 Kudos
Message 5 of 16
(5,436 Views)

Hi again,

After reading my last post it became clear that I should explain a bit more.

Basically, I am just trying to filter out certain pulses based on the equation I gave above and it does not seem to be working.

My thoughts are that either this is not the equation I should use, or there is something I am still missing in my code to get the filter to work.

Thanks,

Mtonsager

 

0 Kudos
Message 6 of 16
(5,424 Views)
Hi Mtonsager,

Your understanding of pulse width and duty cycle are correct. I just quickly tried some frequency measurement examples and the filter does seem to work. Apparently there are 4 valid values that you can set for the filter pulse width:

You Can Select:  0.000000,  2.560000e-3,  6.425000e-6,  125.0e-9

Try these values. If you can, try connecting the counters externally to make sure the filters work. Also make sure you are using PFI 33 as the source of your second task (I did not see that in the code).

Let me know if this works for you.

Cheers
Malay
NI

Message Edited by 50ohmTerminator on 11-21-2006 04:31 PM

0 Kudos
Message 7 of 16
(5,417 Views)

Hi Malay,

Thanks for your help.

I am still unable to get the filter to work and I don't have the equipment to connect the terminals externally.  I am using a 6601 card in my pc.  Yes, I am using PFI 33 for my clock source on my second task.  I tried these four values in the filter (0.000000, 2.560000e-3,  6.425000e-6,  125.0e-9), but when I tried 0.000000 it gave me an exception that said:

Request is not a supported value for this property

valid values begin with:  100.000000e-9

valid values end with:  Inf

Then I tried 125.0e-9 and I received this error:

Desired minimum pulse width could not be produced

Minimum pulse width is affected by the digital filter timebase source and the digital Filter timebase rate...

Supported values:  100.000000e-9, 400.000000e-9 to 171.797692e3

I am unsure of what values you are using for your pulse train to test these filter settings.  Would you still have the code that you used to test these settings?

Also, since I am using a buffered counter with the asynchronous methodology, when the signal is filtered out it will not fire off the asynchronous method, right?

Thanks Malay,

Mtonsager

 

0 Kudos
Message 8 of 16
(5,399 Views)
 

Hi Mntonsager,

How will you be connecting your external signal?  For now you are simulating the input by creating a signal on the counter output.  Will you be getting a terminal block to make your final connections? The same terminal block could be used to connect the two PFI lines. For now the internal connection should work.

Enabling the Digital Filters for Counter/Timer Devices in NI-DAQmx outlines the calls to make for setting the filters.  According to the TIO help linked in the above post, the valid settings for the filter are 100ns, 500ns, 1us and 5us if the default timebase is used.  Does a value of 100e-9 work?  Other values can be used if an external clock is supplied for the filter timebase.

Once the signal is filtered, pulses which did not meet the minimum pulse width will no longer be present and should not cause your count to increment.  The filter is implemented in hardware and it will not matter that you are doing buffered measurement.  Note that there will be a finite delay between your original and filtered signal.  For the TIO board this will be 2 filter clock time periods.  For more information, search the NI-DAQmx C Reference Help for "digital filter clock".  This will bring up useful information under the heading "Digital Filtering Considerations for TIO-Based Devices".

Regards,

Jennifer O.

0 Kudos
Message 9 of 16
(5,346 Views)

Thanks for the information Jennifer.

Basically, the only thing I want to do right now is to test the filter settings to see if they work.

In the documentation for the 6601/6602 counter device manual it says you can use defined filter settings to remove noise/glitches narrower than 2.5us, 500ns, 250ns, and 50ns.

Is this how I would implement the filter for 2.5us in .NET and MS 8.0.1?

 t.Control(TaskAction.Verify);

t.CIChannels.All.CountEdgesDigitalFilterEnable = true;

t.CIChannels.All.CountEdgesDigitalFilterMinimumPulseWidth = 5.0e-6;// This guaranteed to pass 5micorsecond pulse, guaranteed to block 2.5microsecond spikes/pulses

 

If I do the "TaskAction.Verify" above I think it just uses the 20MHz timebase, right?  Is this the timebase I should use?

So, now for my other counter (pulse train) this is connected to, what would my frequency and my dutycycle be to see if it does, in fact, filter out these pulses?

Or, perhaps, there is another way to test these filter settings.  Would you know how to test them?

Thank you much Jennifer!

Mtonsager

 

0 Kudos
Message 10 of 16
(5,333 Views)