Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6251internal MHz timing

I have borrowed a USB-6251 DAQ to drive a stepper motor. The data sheet says that this DAQ is capable of MHz timing for digital IO. I have tried writing a simple programme (attached) to set the motor ENABLE and PULSE pins hi, and then send pulses to the PULSE pin using a "timed loop with frames" to set the PULSE pin hi and lo alternatively.

 

I would like to know:

 

1. How to setup a MHz timebase for the timed loop (both internal and external, and which of these options is recommended)

 

2. How to insert a wait function of microsecond order in the timed loop such that the pulse duration may be controlled (or any recommended alternative method)

 

[I am using LABVIEW 8.2]

 

Many thanks...

Jordi

0 Kudos
Message 1 of 22
(5,956 Views)

On the USB-6251 datasheet it says that digital IO timing may be performed at MHz speeds using software or hardware. However, I read here [http://digital.ni.com/public.nsf/allkb/0C0A6EE528F85A6486256F6700061790] that Windows is only capable of kHz timing. This would explain why I am unable to select the MHz timing option for the timed loop. However, I do not understand the above specification on the datasheet. Could someone please explain to me?

 

Also, it is essential that I am able to produce pulses at MHz speeds or, at the very least, count such pulses. Either way I require MHz loop iteration. Could you please advise me on how to do this? If this requires external timing, please also advise on how I should go about this, as I cannot find anything online...

 

Jordi

0 Kudos
Message 2 of 22
(5,939 Views)

Hi Jordi,

 

You are correct that the Windows clock is only capable of kHz timing--even then however it is non-deterministic and has very high jitter compared to a Real-Time OS.  The latency associated with USB makes the application non-deterministic even if you were on a RT system.

 

The solution is to use hardware-timing for your 6251.  You could use the digital I/O lines on the board to do what you need (the clock must come from another task or from an external source).  When using continuous generation in this way, data is written to a buffer and generated from there based off of a sample clock.  If you want to go this route, I suggest taking a look at the following example:

Performing Correlated Digital IO With an M Series Device in LabVIEW

 

Based off of what you have said so far, what I would actually recommend is to use one of the 6251's on-board counters.  There are 2 counters on the 6251, so you can count and generate 1 MHz pulses simultaneously if you require.  The LabVIEW shipping examples should be a good place to start, try navigating to the following:

Help >> Find Examples >> Hardware Input and Output >> DAQmx ...

From there, you can go to the following paths for generation and acquisition respectively:

Generating Digital Pulses >> Gen Dig Pulse Train-Continuous.vi

Counter Measurements >> Count Digital Events >> Count Digital Events.vi

I suggest you also take a look at the M Series User Manual (pdf link) which has alot of good information about the 6251 and how it functions.

 

 

-John
John Passiak
0 Kudos
Message 3 of 22
(5,924 Views)

From the examples you referred to i found "Gen Dig Pulse Train-Finite.vi" is particularly useful as it can generate a digital pulse train at a definable frequency for a definable number of pulses. This partially solves my problem.

 

The task is to build a pump with a definable flow waveform, much like the waveform that is produced when the heart pumps blood. I would therefore like to instruct the stepper motor to rotate at different speeds from 0 to 180 degrees (ejection phase), and then a constant fast speed from 180 to 360 degrees (intake phase).

 

Within the ejection phase i have discretised the speeds of rotation to 100 blocks, during each of which the motor will rotate  at a different constant speed such that the overall rotation follows a defined speed curve. Using the principles in the above example i can generate the exact frequency and number of pulses required in any ONE block, but I would like to be able to set all 100 of these parameters to satisfy the 100 blocks in each revolution.

 

A simple theorised solution would be to place the Finite Pulse Train VI in a loop and have the input parameters in an indexed array such that they change for each loop iteration. The complication is getting the loop to be able iterate fast enough such that the overall "concatenated" rotation is smooth rather than jerking at each loop iteration.

 

Any ideas?

0 Kudos
Message 4 of 22
(5,903 Views)

Hi Jordi,

 

You may adjust the parameters while the code is running, but you would lose the determinism associated with HW-timed signals (since the rates would be controlled by the loop).  Ideally you would want a "buffered" counter output, but unfortunately our current devices do not support this feature.

 

The following example uses an event structure to allow the user to change counter output frequency on the fly, it could be modified to use a for loop with indexed counter parameters to fit the needs of your application.  You could also include a wait function inside the loop to have some control of the update rate--this may or may not be acceptable depending on the required level of control (you are still subject to the non-determinism of Windows):

 

Update Counter Frequency and Duty Cycle on the Fly

 

 

If the above solution does not provide suitable determinism for your application, the other option would be to build an array of digital data and use the correlated digital I/O option mentioned in my first post.  I had originally recommended the counter since I didn't realize the full scope of the application--correlated digital I/O would give you the ability to specifically define a digital waveform to be generated based on a hardware-timed signal. 

 

If going with this method, you would provide a sample clock to use as a timebase for your digital output, so this would give you the flexibility to output any digital values you wish at the rate of your sample clock.  The catch is that you need to build the array to generate and provide the external sample clock (could be generated from one of the counters and routed internally).  I would look at the example I linked to earlier for a good starting point if this is the route you want to go.

 

 

-John

Message Edited by John P on 06-02-2009 04:29 PM
John Passiak
0 Kudos
Message 5 of 22
(5,889 Views)

Hi John

 

I have managed to build a (very long) array of digital data by concatenating 100 squarewaves of different frequencies. I have also managed to use the correlated digital I/O you suggested. I have made use of the internal 100kHz Timebase on the USB-6251.

 

I would like to be able to count the number of edges produced by the full array, preferably internally. Is this possible? I want to do this to ensure that the array only produces 1000 pulses for the stepper motor.

 

[The reason i feel the need to check is because the frequencies and number of steps of each squarewave results in partial pulses at the join between two concatenated squarewaves. Since the stepper motor only needs an edge to register a pulse, i'm afraid that it might register one or two extra steps than intended...]

0 Kudos
Message 6 of 22
(5,850 Views)

Hi Jordi,

 

I'm not sure about counting the correlated line internally, there aren't routes available from those lines to the on-board counters.  However, you should be able to connect the digital I/O line externally to one of the PFI lines and use one of the on-board counters to count the edges.  The example for basic edge counting can be found here:

 

Help >> Find Examples... >>  Hardware Input and Output >> DAQmx >> Counter Measurements >> Count Digital Events >> Count Digital Events.vi

 

 

-John

John Passiak
0 Kudos
Message 7 of 22
(5,837 Views)

Hi John

 

I have tried to route the digital I/O line externally to the PFI8 terminal on the USB-6251. As mentioned before, I was also using the internal 100kHz timebase as a clock. Unfortunately, I get an error saying that it cannot count the edges since the device is already in use by the timebase. So it looks like I need to explicitly produce a clock signal with one counter and count the edges with the other. In any case I would like to eventually be able to change the clock speed, so this suits me fine.

 

I have tried to find a good example to work from but I am still having problems setting up the clock signal & routing.

 

The way I see it is that I would need to do the following:

1. produce a 100 kHz pulse train using an (analogue?) output terminal

2. feed this into the first counter terminal as a clock input

3. use this clock to produce a digital output

4. feed the digital output into the 2nd counter terminal to count the edges

 

This seems long-winded and cumbersome. How would you recommend I go about this? Also, depending on how you'd recommend I produce the clock signal, could you please direct me to an example or something that'd help me set it up on the USB-6251?

 

My code is attached so you can see what I have tried (LabVIEW version 8.2)

0 Kudos
Message 8 of 22
(5,786 Views)

Hi DCT,

 

By looking at the Device Routes tab in Measurement and Automation Explorer, it seems that using the 100 kHz timebase as your DO Sample Clock reserves Ctr 0:

 

Device_Routes.PNG

 

 

You should just be able to change from Counter 0 to Counter 1 on the acquisition side of things to get the code to work (after wiring to the appropriate terminal of course).  If you have any problems with it please don't hesitate to post back.  Thanks!

 

 

-John

Message Edited by John P on 06-22-2009 12:47 PM
John Passiak
0 Kudos
Message 9 of 22
(5,781 Views)

Hi John,

 

I have similar problem about the Mhz timing. I have a device which give 16bit digital output at 5Mhz - 12 Mhz.

 

First, The device will give a SYNC signal which is connected to the DAQ port 0/line0 now

Second, afte the device gives the SYNC signal (rising) (~2.2 us), the device will have 9-12bit data ready which are connected to port0/line1:line12. we hope to use the DAQ card to readout these 9-12bit data after the SYNC each time.

 

I have a PCI-6259 card, I try to use the "Detection change" in labview, but it causes error as following,

 

"There was no more space in the buffer when new data was written. The oldest unread data in the buffer was lost as a result."

 

Is it bcause the digital in process not fast enough?

 

I would apprceite if you can give me some suggestions.

 

0 Kudos
Message 10 of 22
(5,023 Views)