Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

continuous digital waveform

Hi,

I'm trying to write a continuous digital waveform to lines 0 and 1 of port 0; I have the PCI-6229 and am using MS Visual C# express edition. I have successfully used this set-up to do single-sample writes to these lines on port 0, but I can't figure out how to generate a continuous (repeating) waveform. I have attached the code I am using; it will compile and run without generating exceptions, but when I monitor the output lines on the DAQ card, I see nothing. I don't see even a single run-through of the waveform data, much less a continuous stream of data. Does anyone know what I'm doing wrong?

Thanks,
Elizabeth

public void GrayEncoderWrite(double periodS)
{
    uint nSamples = (uint)(1 << 2);
    /* Mask the data to the 2 LSBs */
    uint mask = nSamples - 1;

     /* Create a new task */
    doTask = new Task(); // Task doTask is a data member of the form
   
    /* Attach an output channel to the task */
    doTask.DOChannels.CreateChannel("dev1/port0/line0:1",
        "", ChannelLineGrouping.OneChannelForAllLines);

    /* Configure timing for channel: sample rate is 1/periodS */
    doTask.Timing.ConfigureSampleClock("/dev1/pfi0", 1.0 / periodS,
        SampleClockActiveEdge.Rising,
        SampleQuantityMode.ContinuousSamples);

    /* Configure channel writer */
    DigitalSingleChannelWriter dWriter =
        new DigitalSingleChannelWriter(doTask.Stream);

    /* Create waveform to write
     * Turn the Gray-encoded initial state into an index integer
     */
    uint[] grayWaveformUint = new uint[nSamples];
    for (uint i = 0; i < nSamples; i++)
        grayWaveformUint[i & mask] = i^(i>>1);

    /* Do a Gray-encoded waveform starting at the initial state
     */
    DigitalWaveform grayWaveform = DigitalWaveform.FromPort(grayWaveformUint, (byte)mask);
    grayWaveform.Timing = WaveformTiming.CreateWithRegularInterval(TimeSpan.FromSeconds(periodS));

    /* Write waveform to channel */
    dWriter.WriteWaveform(true, grayWaveform);

    /* Write the initial state and start the clock */
    writingSqWave_ = true;
}

// the task is stopped/disposed of in another function
0 Kudos
Message 1 of 8
(4,723 Views)
Hi Elizabeth,

Thank you for posting on the National Instruments forums.
Is your application currently outputting the waveform that you want?  Is it just not doing it continously?
Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 2 of 8
(4,699 Views)
Hi Nick,

Thanks for your response.

Yesterday, it was not putting out any waveform at all. Today I found out that if I commented out the ConfigureSampleClock, then the card will write a single iteration of the pattern at 800kHz (1.25us between each sample). I can change the doTask.Timing parameter to anything I want; it will not affect the rate of the output. If I put the ConfigureSampleClock line back into the code, the code will again not write any output.

As you can imagine, I am very frustrated with this! I noticed that there are no measurement studio examples (for .NET languages) that show how to output a digital waveform--all of the examples are single-sample writes. This puzzles me a bit, since it seems to me that writing a digital waveform should be a basic function of a DAQ card.

I have found and run a few examples of a digital waveform output, but have not been able to get any of them to run successfully.

Any suggestions you have would be greatly welcome.

Thanks,
Elizabeth
0 Kudos
Message 3 of 8
(4,695 Views)
It is all working now...thanks.
0 Kudos
Message 4 of 8
(4,673 Views)
I am having the same problem and was wondering if you could post what you did to fix this.

Thanks
Matt

0 Kudos
Message 5 of 8
(4,647 Views)
My problem was understanding the digital I/O clock--there isn't one. Instead, you can either tie it to one of the analog clocks, use the counter clock, or provide a clock on one of the PFIs. I think there might be a couple other options, but I used the analog input clock. The key then is realizing that the analog input task must be running the entire time that you want your digital I/O running.

So I created a task, added an analog input channel, and started the task. This started the analog input clock, which I then used for my digital I/O. I didn't actually have to be continuously reading data from the task, I just had to have the task running.

Once the analog task was going, I could create another task and add a digital output channel. I used the ConfigureSampleClock function to set up the digital output channel timing, and made the first argument to the function "ai/SampleClock". Then I could create a digital channel writer, and my waveform wrote correctly.

Let me know if this helps and if you have any more questions about what I did.
Message 6 of 8
(4,634 Views)

Elizabeth,

Thanks a lot for your post. I was having the same problem and didn't realize I needed to create an analog task to provide the clock. After about half a day of trial and error I got the waveform output on the digital IO to work. Would be nice if they had provided an example, but your post provided the clue I need.

Mark Doyle

0 Kudos
Message 7 of 8
(4,457 Views)
Hi, Elizabeth,

Thanks for your explaining. I have the same problem, and Your post was very helpful.
But I also use Visual Studio and I have problem with implementation. I try to generate digital waveform with MAX and everything goes ok (as You wrote in last message). Unfortunately, when I do the same (I think the same) in Visual Studio, nothing happend. I think I use some wrong argument or something like this...

Every example I found in NI Zone are written in LabView.
Could You show your C# code to generate digital waveform?
Thanks
Best regards
Zenon Cyganek
0 Kudos
Message 8 of 8
(4,391 Views)