Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

external clock edge counting

I need to know which pins to connect to count pulses using an external trigger.  I am using a PCI-6602 and I need to use one counter on the board to trigger two other counters which are counting events.

Let's assume the following:

Dev1/Ctr1 counts pulses
Dev1/Ctr2 counts pulses
Dev1/Ctr3 generates a 1 Hz pulse for triggering purposes

Does this mean that CTR 3 OUT should be hooked up to CTR 1 GATE and CTR 2 GATE and the input clock signals should be hooked to CTR 1 SOURCE and CTR 2 SOURCE?

If this is the case, then will this code work?  (VB.NET)

        ' Pulse Counter
        If DIChannelCount > 0 Then
            Try
                For cnt = 0 To DIChannelCount - 1
                    Tasks(14 + cnt) = New Task("Counter" & cnt)
                    With DIChannels(cnt)
                        Tasks(14 + cnt).CIChannels.CreateCountEdgesChannel(.Device & "/" & .Channel, "Count Edges", _
                        CICountEdgesActiveEdge.Rising, Convert.ToInt64(0), CICountEdgesCountDirection.Up)
                        Tasks(14 + cnt).Timing.ConfigureSampleClock(.Trigger, 1, SampleClockActiveEdge.Rising, _
                                SampleQuantityMode.ContinuousSamples, 1000)
                    End With
                    runningTask(cnt) = Tasks(14 + cnt)
                    myCICounterReader(cnt) = New CounterReader(Tasks(14 + cnt).Stream)
                    myCICounterReader(cnt).SynchronizeCallbacks = True
                    myCICounterReader(cnt).BeginReadSingleSampleUInt32(CtrCallback, cnt)
                Next
            Catch exception As DaqException
                MsgBox("Counters" & vbNewLine & exception.Message)
                'Tasks(15).Dispose()
            End Try
        End If

    Public Sub CounterReadCallback(ByVal ar As IAsyncResult)
        Dim TaskNumber As Byte
        TaskNumber = CType(ar.AsyncState, Integer)

        Try
            If runningTask Is ar.AsyncState Then
                Select Case TaskNumber
                    Case Is = 0
                        CTR1 = myCICounterReader(TaskNumber).EndReadSingleSampleUInt32(ar)
                    Case Is = 1
                        CTR2 = myCICounterReader(TaskNumber).EndReadSingleSampleUInt32(ar)
                End Select

                myCICounterReader(TaskNumber).BeginReadSingleSampleUInt32(CtrCallback, TaskNumber)
            End If

        Catch exception As DaqException
            Tasks(14 + TaskNumber).Dispose()
            MessageBox.Show(exception.Message)
            runningTask(TaskNumber) = Nothing
        End Try
    End Sub

Thanks!

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 6
(4,407 Views)
Hi Michael,

Thank you for posting on the National Instruments forum.

I am not exactly sure what you are asking.  Are you trying to send a 1Hz signal into your gate so that the counters are sending out pulses for half a second every half second? 

How the gate works is that while it receives a high signal, the counter will count edges and when the gate signal goes low the counter will stop counting.  If that is what you are trying to do, then it sounds like you are setting up the counters correctly. 

Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 2 of 6
(4,393 Views)
I need to update the counter's value in some arbitrary variable at 1 Hz.  I sent a perfect 1 kHz signal to the counter and I'm reading it with my software but my 1 Hz software loop is returning errors up to 1%.  I need hardware timing.  There is an example called CountDigEventsBuffContinuous_ExtClk that I believe does this.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 3 of 6
(4,390 Views)
Hi Michael,

I don't understand what you mean by update the counter's value in some arbitrary variable at 1Hz.  I think this means that you want your loop to run at 1Hz, but does that mean that you want to grab the value of the counter every second?  Or are you sending a value for the counter to count down or up from every second?  Can you please clarify that part of what you want to do?
Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 4 of 6
(4,376 Views)
I need to count pulses per second and software timing is not good enough.
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 5 of 6
(4,370 Views)
Hi Michael,

To do what you want to do, you will need to have two counters. 

First you will have to setup a counter that generates a pulse at 1 Hz to be a clock for the other counter.  The other counter will be doing a buffered edge count and will grab the counts every second because of the 1 Hz clock.  

You will then have to subtract the count that you received with the count that you received on the last second.  One thing you have to be careful of is if the terminal count is reached, then you will have to add the terminal count number since you will have a large negative number if you pass the terminal count. 

Here is what it would look like in LabVIEW if you were to do it there.  I do not have a text based version of this, but you can see what’s going on.

Message Edited by Nick F on 07-26-2007 05:58 PM

Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 6 of 6
(4,356 Views)