Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Finite cycles counter problem

Hello,

 

I am new to working with counters etc.  I have a PCI-MIO-16e4 (NI-PCI-6040E) board and am working in VB.net with Ni-DAQmx.  I am trying to send (sequentially) bytes of data to a device, sending a strobe signal (hi-lo transition) on a counter output line each time to notify the device that the byte is ready to be read.  Timing is important and fast.

This is the process:

(a)  Load byte to digital output lines

(b)  Set counter 1 output to Low

(c)  Hold low for 150 microseconds

(d)  Set counter output to High (minimum 5 microseconds)

(e)  Load next byte on digital output lines

(f)  Go back to step b

 

I thought I could easily do this using the following code:

 

        Dim writer As New DigitalSingleChannelWriter(ByteChannel.Stream)  'ByteChannel is a task for the digital output lines

       TransmitChannel = New Task

       TransmitChannel.COChannels.CreatePulseChannelTime("Dev1/ctr1", "Xmt", COPulseTimeUnits.Seconds, IdleHigh, 0, 0.00015, 0.000005)
       TransmitChannel.Timing.ConfigureImplicit(SampleQuantityMode.FiniteSamples, 1)
       
        For a = 0 To 63
            writer.WriteSingleSamplePort(True, Packets(a))  'place the next byte on the line
            TransmitChannel.Start()
            Do Until TransmitChannel.IsDone
                Application.DoEvents()
            Loop
            TransmitChannel.Stop()
        Next a

 

This gives me the low/high transition I need but the timing does not work - it takes much longer for each iteration to finish  (> 50 millseconds for a pulse train that should last about 200 microseconds) than the timing I set up above would suggest.  I have searched around but have not found anything online that helps me understand what I need to do to rectify this.  Does anyone have any suggestions of what I can change or a more elegant way to do this?

 

thank you

David

 

0 Kudos
Message 1 of 2
(5,760 Views)

What you're currently doing is starting and stopping 64 finite tasks.  Each iteration of the loop the task outputs 1 byte on your digital lines, and then stops, repeats the loop, starts the task with a new byte in memory, and then stops again.

 

This starting and stopping of the task takes a significant amount of time.

 

What you need to do instead is a buffered digital output task.  In a buffered digital output task you can specificy all 64 bytes, and then it will iterate through each one at the rate you specify and from some external clocking source.  You can see this done in the shipping example ContWriteDigPort_ExtClk (found if you go to the start menu and navigate to Programs»National Instruments»NI-DAQ»Text-Based Code Support».NET 3.5 Examples and then browse to \Digital\Generate Values\ContWriteDigPort_ExtClk\VB

 

However, one very important thing to note, is that E series devices (such as the PCI-6040E) only support software-timed, on-demand digital tasks.  This means they do not support hardware timed tasks, such as buffered digital generation.  

 

That means there is no way you will be able to get your 150 microsecond timing from this card when doing digital generation.  M series devices do support hardware timed, buffered digital generation with an external sample clock (such as your counter), and X series devices support buffered digital generation with either an external sample clock or an internal sample clock at a rate you specify, since they have a new digital timing engine on them as well.

 

 

 

You can still optimize your code however, by not starting and stopping the task each iteration, but rather start the task before the loop, and stop it after.  Inside the loop you will simply need to use the WriteSingleSamplePort command in the loop.  In fact, you pretty could do this I believe (note, I did not test this first):

 

 

  TransmitChannel.Start()

        For a = 0 To 63
            writer.WriteSingleSamplePort(True, Packets(a))  'place the next byte on the line

        Next a 

            Do Until TransmitChannel.IsDone
                Application.DoEvents()

            Loop 

TransmitChannel.Stop() 

Eric S.
AE Specialist | Global Support
National Instruments
0 Kudos
Message 2 of 2
(5,703 Views)