Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB 6009 Analog Output Timing

I am trying to work out a basic control loop that will increase or decrease the analog output voltage in response to an analog input voltage.  I've worked out the analog input, but I can't seem to get the analog output to work.  I'm using Visual Basic and tried to base my project off of the example "ContGenVoltWfm-IntClk", but I get an error when setting up the sample clock.  Here's an excerpt of what I'm trying to do:
 
    numSampsPerChannel = 250
    ReDim data(numSampsPerChannel)
    amplitude = 2
    desiredSampleClockRate = ((10#) * (250#)) / (5#)
    sampsPerCycle = 250# / 5#
    resultingFrequency = (desiredSampleClockRate) / (sampsPerCycle)
 
    clockEdge = DAQmx_Val_Rising
   
    DAQmxErrChk DAQmxCreateTask("", taskHandle)
   
    DAQmxErrChk DAQmxCreateAOVoltageChan(taskHandle, "Dev1/ao0", _
        "aoChannel", 0, 5, DAQmx_Val_VoltageUnits2_Volts, "")
   
    DAQmxErrChk DAQmxGetTaskNumChans(taskHandle, numChannels)
   
    DAQmxErrChk DAQmxCfgSampClkTiming(taskHandle, "", _
        10, clockEdge, DAQmx_Val_AcquisitionType_ContSamps, 100)
       
    DAQmxErrChk DAQmxWriteAnalogF64(taskHandle, numSampsPerChannel, True, 10#, _
        DAQmx_Val_GroupByScanNumber, data(0), sampsPerChanWritten, ByVal 0&)
 
I stepped through the code and it gives an error (-200077) on the DAQmxCfgSampClkTiming and DAQmxWriteAnalogF64 commands.
It creates the task and adds a channel with no problems.
 
Is there an easier way to write to the analog output channel, given what I'm trying to do?  Do I have to use the USB 6009's onboard clock, or can I just maintain an output voltage until a new value is written?  The -200077 error says "Requested value is not a supported value for this property", but I don't really follow what it's trying to tell me.  Any help would be greatly appreciated.
 
Thanks,
Shawn

Message Edited by sdewey on 01-03-2006 04:41 PM

0 Kudos
Message 1 of 4
(2,713 Views)
Shawn,
 
The USB 6009 has no internal sample clock, which is why you get that error. It is only capable of doing software-timed acquisition/generation. It will maintain an output value until a new value is written.
--
Michael P
National Instruments
0 Kudos
Message 2 of 4
(2,691 Views)

Thanks Michael,

I ended up using a much simpler section of code:

    DAQmxErrChk DAQmxCreateTask("", taskHandle)
   
    DAQmxErrChk DAQmxCreateAOVoltageChan(taskHandle, "Dev1/ao0", _
        "aoChannel", 0, 5, DAQmx_Val_VoltageUnits2_Volts, "")
    
    DAQmxErrChk DAQmxWriteAnalogScalarF64(taskHandle, True, 10, AOut, ByVal 0&)

And it seems to work well.  I was hoping to clean it up a bit and tried to pull the DAQmxCreateTask command out of the control loop, but it doesn't seem to work if a new task isn't created each time a new value is written.

Does it have to create a new task each time?  Does it automatically clear the last task after it writes the new value?

-Shawn

0 Kudos
Message 3 of 4
(2,684 Views)

Shawn,

Try putting a DAQmxBaseStartTask before the DAQmxWriteAnalogScalarF64. You shouldn't have to create the task over and over.

--
Michael P
National Instruments
0 Kudos
Message 4 of 4
(2,679 Views)