Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Ramping Sinusoid

USB-6343

Visual Basic 2008  / .NET 3.5

 

Our customer requires the app to ramp a sinusoid output to a preset amplitude and DC offset, wait 1 second, and then ramp to a different amplitude and DC offset.  This process is repeated for multiple levels and the transitions need to be smooth at 200ms +/- 5ms.

 

The code I wrote to generate the waveform uses the FunctionGenerator class from the .NET 3.5 DAQmx samples provided with the Measurement Studio.  Currently, my code steps from level to level without ramping as required.

 

Does anyone know how to achieve the ramping functionality I described?

 

Thank you in advance for your assistance.

0 Kudos
Message 1 of 6
(3,865 Views)

Hi Parksma,

 

Do you know how long the times will be between set points?  When you say the transitions need to be smooth at 200ms, are you saying each new set point will occur 200ms apart?

 

The reason I ask is because you could make this transition very smooth by pre-calculating what all the values will be over the given time period between set points.  If you pre-calculate these numbers, you can load each one of them into the Analog Output FIFO buffer using the DAQmx Write functionality, then you can use DAQmx Staron the 6343, and then clock out each of those at a known sample rate.  This would be hardware timing as opposed to using software timing (where the program outputs a single value to the 6343, and the 6343 updates whenever it receives the software command.

 

If you're looking for examples in the NI Example Finder, I might point you to:

 

...\National Instruments\NI-DAQ\Examples\DotNET3.5\Analog Out\Generate Voltage\ContGenVoltageWfm_IntClk\VB

 

In this example, a FunctionGenerator() is used to write out to the analog output of the device.  You might replace that equation with an equation that computes the ramp values over the period of time you specify.  Then, when you write out multiple samples with writer.WriteMultiSample(), the buffer will be pre-loaded with the levels that provide a smooth transition between the set points.

 

Let me know if this helps,

-Andrew

National Instruments
0 Kudos
Message 2 of 6
(3,842 Views)

Andrew,

 

Thank you for the reply, and for the suggestions.

 

To clarify, the sequence is to hold a sinusoid with a particular amplitude and DC offset for 1 second, and then to ramp to the next level in 200ms +/-5ms.  That level is held for 1 second, and then we ramp to another level.  This sequence continues for 5 -6 levels.

 

I modified the code as you suggest, creating a routine in the function generator that calculates the ramp data.  I now have one routine to calculate a ramping sinusoid in a given timeframe, and another for a steady state sinusoid.  I can output either data set separately and have verified that I get either a ramping sinusoid OR a steady state sinusoid as expected.  My problem comes when I try to output the ramping sinusoid followed by the steady state sinusoid.  When I do this, it seems that the steady state sinusoid trumps the ramp and the output jumps directly to the steady state level.  The example you pointed me to shows how to output a continuous waveform, but not how to concatenate a finite waveform with a continuous.  Below is the code where I attempt to do this:

 

    myTask.AOChannels.CreateVoltageChannel(msDeviceName & "/ao" & _
        ChannelNumber.ToString(), "ao" & ChannelNumber.ToString(), _
        Minimum, Maximum, AOVoltageUnits.Volts)

 

    ' Verify the task before doing the waveform calculations
    myTask.Control(TaskAction.Verify)

 

    writer = New AnalogSingleChannelWriter(myTask.Stream)

 

    '***** Ramping sinusoid *****
    WaveFormInfo.CyclesPerBuffer = WaveFormInfo.Frequency * (WaveFormInfo.RampTime / 1000)
    WaveFormInfo.SamplesPerBuffer = WaveFormInfo.CyclesPerBuffer * 100

 

    fGen = New FunctionGenerator(myTask.Timing, WaveFormInfo)
    fGen.GenerateRampingSineWave(WaveFormInfo.Amplitude, WaveFormInfo.Offset, _
        WaveFormInfo.RampTime, WaveFormInfo.RampFromAmplitude, WaveFormInfo.RampFromOffset)

 

    ' Configure the sample clock with the calculated rate
    myTask.Timing.ConfigureSampleClock("", fGen.ResultingSampleClockRate, _
        SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 100)

 

    ' Write the data to the buffer
    writer.WriteMultiSample(False, fGen.RampData)

 


    '***** steady state sinusoid *****
    WaveFormInfo.CyclesPerBuffer = 1
    WaveFormInfo.SamplesPerBuffer = 100

 

    fGen = New FunctionGenerator(myTask.Timing, WaveFormInfo)
    fGen.GenerateSineWave(WaveFormInfo.Amplitude, WaveFormInfo.Offset)

 

    ' Configure the sample clock with the calculated rate
    myTask.Timing.ConfigureSampleClock("", fGen.ResultingSampleClockRate, _
        SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 100)

 

    ' Write the data to the buffer
    writer.WriteMultiSample(False, fGen.Data)

    myTask.Start()


As I mentioned, I only see the continuous steady state sinusoid on the output channel when I execute the code above.  How do I output the ramping data, then the stead state data with no break between?

 

Thanks again for your assistance.

 

Mike Parks

0 Kudos
Message 3 of 6
(3,791 Views)

You'll probably need to do this by continuously updating the buffer by disallowing regeneration.  Let me know if this Discussion Post helps.

National Instruments
0 Kudos
Message 4 of 6
(3,769 Views)

What does "continuously updating the buffer by disallowing regeneration" mean?  Are there any examples of using this technique?

 

Thanks for your help.

0 Kudos
Message 5 of 6
(3,747 Views)

Hi Parksma,

 

The difference between regeneration and non-regeneration is where the output data is stored on the device.

 

There's an internal FIFO on the DAQ hardware, and then there's your PC RAM.  The output data could be stored in either.

 

In regeneration mode: The FIFO is used exclusively to continually output the same data. Since the FIFO has a limited sample size, you can't generate a very long analog output.  However, because it is local to the DAQ device, so you can output the data more quickly and you know that every output datum will be produced with consistency in the order which it was written to the buffer.

 

In non-regeneration mode: The RAM on your PC transfers the newly written data to your DAQ device to be generated.  In this configuration, you have a lot more memory, so you can output however much data you would like.  However, you are limited to the bus considerations of the PCI/USB bus and any other processes on your operating system competing for use of that.  For lower sample clock rates, this isn't noticeable, but for higher rates it becomes important to use regeneration mode or limit your other processes.

 

In either case, your data is regenerating--it's just a matter of where the data is regenerating from.  Please also see this KnowledgeBase on Analog Output Regeneration Modes

 

-Andrew

National Instruments
0 Kudos
Message 6 of 6
(3,736 Views)