Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Count two different pulse channels?

How can I count two different pulse channels on the same module? (cDAQ 9472)

Current Code:

        ' Pulse Counter
        If DIChannelCount > 0 Then
            Try
                Tasks(14) = New Task("Counter")
                For cnt = 0 To DIChannelCount - 1
                    With DIChannels(cnt)
                        Tasks(14).CIChannels.CreateCountEdgesChannel(.Device & "/" & .Channel, "Count Edges", _
                        edgeType, Convert.ToInt64(0), countDirection)
                    End With
                Next
                myCICounterReader(cnt) = New CounterReader(Tasks(14).Stream)
                Tasks(14).Start()
            Catch exception As DaqException
                MsgBox("Counters" & vbNewLine & exception.Message)
                'Tasks(15).Dispose()
            End Try
        End If



        ' WRONG
        If RM1Pointer.Found Then
            CTR1 = myCICounterReader(0).ReadSingleSampleUInt32()
            If CTR1 < lastCTR1 Then
                CTR1 = 4294967296 - lastCTR1 + CTR1
            Else
                CTR1 -= lastCTR1
            End If
            lastCTR1 = CTR1
            txtCount1.Text = CTR1 * DIChannels(RM1Pointer.Value).Linear
        End If

        If RM2Pointer.Found Then
            CTR2 = myCICounterReader(1).ReadSingleSampleUInt32()
            If CTR2 < lastCTR1 Then
                CTR2 = 4294967296 - lastctr2 + CTR2
            Else
                CTR2 -= lastctr2
            End If
            lastctr2 = CTR2
            txtCount2.Text = CTR2 * DIChannels(RM2Pointer.Value).Linear
        End If
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 10
(4,707 Views)
And on the same token, can I use digital outputs and a counter on the same module at the same time?
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 2 of 10
(4,705 Views)

Hi Michael,

 

 

Thanks for using NI forums. As you can see here, the NI 9472 is an output module, so you can only perform output operations. The counters are actually on the cDAQ chassis and are accessible with any input module in slots 5 or 6. You can use NI 9401 for input and output.

 

 

For your second post, yes you can, and you will need to be careful in not to use the digital lines that the counter is using. You can see this on the attached picture taken from DAQmx help file.

 

 

Regards,

 
Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 3 of 10
(4,693 Views)
OK, I mixed up the part numbers, but it is wired correctly and I am trying to use the correct modules.

What I need to do:

9472 - Output a PWM signal using one of the counters and use another channel as an on or off digital output.

9401 - Use two counters to count pulses.  I don't know the command to return the values from both counters.

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 4 of 10
(4,691 Views)
Hey Michael,

There is a great example on counting pulses in DotNET.  This example can be found on your computer in the following path:

C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\DAQmx\Counter\Count Digital Events\CountDigEvents

I have also attached the example to this post, I hope this helps

Regards,
Erik J.
0 Kudos
Message 5 of 10
(4,668 Views)
I based my program off of that example.  All I need to know is how to read TWO counters from the same board at the same time.  I guess I create one task and add two channels to it, but do I have to have counterReaders for both channels or can I read them both with one reader?  The code I pasted above is from that example.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 6 of 10
(4,660 Views)
Hello Michael,

Well, you would like to create a task for each counter you are using:

-          One for the PWM
-          One for counting one train
-          One for counting the other train

Now there is a problem, if you are using only one cDAQ chassis, then there is only two counters.
What options we have:

-          Count pulses in software
-          Do PWM in software (using digital lines)


Where are these counting signals come from? There might be something we can do to get them both.

The immediate response to your question is that you need to have a task for each counter measurement you would like to do.

Good luck,

Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 7 of 10
(4,651 Views)
That helps.  I didn't know that there were only two counters per chassis.  We have three chassis for this application, so I will move a module over to a different chassis. 

Now the question is, will DAQmx be OK with me setting up a task for each input counter even when they are on the same module?
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 8 of 10
(4,645 Views)
Hi Michael,

Sorry for that delay response.
Yes, you can use the same module and Yes, you use one task for each counter.
If you have MAX, you can create various task and run them at the same time, this can save you time prototyping before coding.
Hope this helps,
Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 9 of 10
(4,626 Views)
My digital output task was set as  one channel for all lines.  That means it was trying to update the PDC channel each time I updated a digital channel.  I need to change my code to one channel per line.

Thanks for all the help!
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 10 of 10
(4,614 Views)