Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

500 MicroSecond Pulse

Hello everyone,

I am using NI usb-6003 and C# programming. I need to activate two digital line (p0/line0 and P0/line1) synchronously, and remain active 500 microsecond for the first one and 12 second for the other one. I couldn't do that with software because of the accuracy. I was wondering if anyone know how I can do it with the hardware using C#.

0 Kudos
Message 1 of 16
(3,900 Views)

Hi,

 

I want to make sure we're on the same page. If you're using LabVIEW ("software"), you are still able to enforce hardware timing, where the timing is enforced on the USB 6003 instead of on the software.

 

There isn't any reason that text-based should run faster. It might seem like because LabVIEW is a graphical programming language, and C# is text-based, that text-based would be faster, but that is not the case.

 

If you are running into limitations with the USB 6003 with LabVIEW, the same limitations will exist in LabWindows CVI. But we can make sure you're using the hardware as optimally as possible, by exploring your code.

 

Are you using a LabVIEW example? You can get to the example finder from within LabVIEW by going to Help -> Find Examples, and I would look in the Hardware Input and Output folder on the Browse tab.

 

Hope this helps! Keep us posted!

 

Timothy D.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 16
(3,853 Views)

Dear Timothy D.,

Thank you for the response.

I don`t use LabVIEW software. I am developing a software using C# programming. In this case, I compared the windows form application timer with the hardware one. The windows timer is not able to do a task in microsecond. The only thing I need is to design a button on a form. When the button is pressed each time, I need to write true on p0/line0 for 500 microsecond duration and on p0/line1 for 2 second duration. I do not know how I can use the internal timer to do this. I would appreciate your help.

Best,

E.

0 Kudos
Message 3 of 16
(3,845 Views)

E,

 

If you look at Text Based NI-DAQmx Data Acquisition Examples, you can see what examples we have provided by our DAQmx drivers.

 

You would need the DAQmx drivers, the newest of which are here. Make sure you do a custom installation so you can choose to include the DotNET options which are not included by default.


I hope this helps! But, let me know!

 

Thanks,

Timothy D.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 16
(3,836 Views)

Thanks for the answer, 


@TimothyDug wrote:

E,

 

If you look at Text Based NI-DAQmx Data Acquisition Examples, you can see what examples we have provided by our DAQmx drivers.

 

You would need the DAQmx drivers, the newest of which are here. Make sure you do a custom installation so you can choose to include the DotNET options which are not included by default.


I hope this helps! But, let me know!

 

Thanks,



@TimothyDug wrote:

E,

 

If you look at Text Based NI-DAQmx Data Acquisition Examples, you can see what examples we have provided by our DAQmx drivers.

 

You would need the DAQmx drivers, the newest of which are here. Make sure you do a custom installation so you can choose to include the DotNET options which are not included by default.


I hope this helps! But, let me know!

 

Thanks,


 

 

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

Thank you for the answer,

I already installed the driver. I looked at the examples but I couldn't find the right answer.

I have written this code to use stopwatch timer of windows but it doesn't work properly in 500 microsecond.         

 

 

            DigitalSingleChannelWriter write0 = new DigitalSingleChannelWriter(task0.Stream);
            DO0 = task0.DOChannels.CreateChannel("Dev1/port0/line0", "", ChannelLineGrouping.OneChannelForEachLine);
            sw.Start();

             task0.Strat();
            write0.WriteSingleSampleSingleLine(true, true);
            while ((sw.ElapsedTicks *1000000/Stopwatch.Frequency ) <=500)
            {
                continue;
            }
          write0.WriteSingleSampleSingleLine(true, false);
          task0.Dispose();

I want to write "true" on line0 only for 500 microsecond duration and then return to "false".

0 Kudos
Message 6 of 16
(3,821 Views)

Hey, so the way you have it is, as you suspect, software-timed. Instead of a single sample write and a software while loop delay, you are going to want to write a waveform, and enforce the 500 microsecond delay by enforcing the corresponding frequency, 2kHz. Then just configure the waveform to write, a 1 and then a 0, at that frequency. That should be the behavior you are looking for.

 

http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/55df5f1f/

 

Alternatively, if you'd like to create something continuous, a pulse train, this would use a counter task (as opposed to a digital task), and the following link should help you set that up.

http://www.ni.com/example/30745/en/

 

Keep in touch with us, and let me know how it is going for you, and of course if you have anymore questions, or if anything is unclear.

 

Thanks,

Timothy D.
Applications Engineering
National Instruments
0 Kudos
Message 7 of 16
(3,779 Views)

Hi, I tried for the timing and write the waveform. I couldn't do that. Is it possible to give me a brief example of this. I couldn't find any example in NI DAQmx folder for writing the waveform and changing frequency.

Thanks,

E.

0 Kudos
Message 8 of 16
(3,764 Views)

I have written this code:

 NationalInstruments.DAQmx.Task task0 = new NationalInstruments.DAQmx.Task();

DO0 = task0.DOChannels.CreateChannel("Dev1/port0/line0", "Port", ChannelLineGrouping.OneChannelForEachLine);
task0.Timing.SampleTimingType = NationalInstruments.DAQmx.SampleTimingType.OnDemand;

task0.Timing.ConfigureSampleClock("",          2000 ,  SampleClockActiveEdge.Rising,  SampleQuantityMode.FiniteSamples);

.

.

.

But it has an error:

Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.

Property: NationalInstruments.DAQmx.Timing.SampleTimingType
Requested Value: NationalInstruments.DAQmx.SampleTimingType.SampleClock
Possible Values: NationalInstruments.DAQmx.SampleTimingType.OnDemand
Task Name: _unnamedTask<0>
Status Code: -200077

 

Does it mean that usb-6003 is not  able for changing clock frequency?

Also, I was wondering if you could give me a sample code that how I can write a waveform exactly a 1 and a 0.

Thanks,

E.

0 Kudos
Message 9 of 16
(3,748 Views)

Hey, thanks for the replies!

 

I did some research, and found that the USB 6003 cannot do a hardware-timed digital out task. You cannot use hardware timing with the digital out task for the USB 6003.

 

I want to understand what you want to do as we probably offer a device better suited to your needs. Do you simply want two pulse trains running at 2 kHz and 0.5 Hz (500 us delay, and 2s delay)? Or, do you just want a signal that arbitrarily goes high for 500 us and then low indefinitely, and the same situation for 2s on a different signal?

 

If all you want is a pulse train, then we have an example that would do that, which I attached. Although, you only have access to one counter with the USB 6003, so you cannot do two continuous tasks simultaneously at different frequencies.


You can however do an analog square wave task at a 2 kHz frequency. However, your USB 6003 only has 1 counter on it, so you could not do 2 simultaneous tasks at different rates. Check out the spec sheet here:

http://www.ni.com/pdf/manuals/374372a.pdf

 

 

 

For writing the 1 and 0 to a digital waveform, if you configure the task as a square wave, or a pulse train, you would not need to explicitly write a 1 and a 0 periodically. It would automatically happen.

 

However, to explicitly write a line high, there is a lot that goes into that. I have a code snippet from the ContWriteDigChan_PipeSampClk from our examples below:

 

myTask.Stream.WriteRegenerationMode = WriteRegenerationMode.DoNotAllowRegeneration;

                int states = (int)samplesPerBufferNumericUpDown.Value;
                int signals = myTask.DOChannels.Count;

                // Loop through every sample
                waveform = new DigitalWaveform[signals];
               
                Random r = new Random();
                for (int i = 0; i < signals; i++)
                {
                    waveform[i] = new DigitalWaveform(Convert.ToInt32(samplesPerBufferNumericUpDown.Value), 1);
                    // Generate a random set of boolean values
                    for (int j = 0; j < states; j++)
                    {
                        if (r.Next() % 2 == 0)
                            waveform[i].Signals[0].States[j] = DigitalState.ForceUp;
                        else
                            waveform[i].Signals[0].States[j] = DigitalState.ForceDown;
                    }
                }

The bolded lines would be explicitly writing a line high or low, and you could adapt the code as neccessary for your application. However, like I said above, the USB 6003 is unable to do a hardware-timed digital task.

 

I hope this helps. Let us know how this works for you!

 

Timothy D.
Applications Engineering
National Instruments
0 Kudos
Message 10 of 16
(3,737 Views)