Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

How to config an External Clock in VB 6?

Hi, there,

Does some one tell me how to config an External Clock that is genterated by a counter in VB 6? Here are my code, but it doesn't work:

    Dim i As Integer
    Dim data(1000) As Double
    Dim written As Long
    Dim firstTaskHandle As Long
    Dim secondTaskHandle As Long
    Dim thirdTaskHandle As Long
   
    DAQmxErrChk DAQmxCreateTask("MyTask", firstTaskHandle)
    DAQmxErrChk DAQmxCreateAIVoltageChan(firstTaskHandle, "Dev1/ai0", "AIChannel", DAQmx_Val_Cfg_Default, -5#, 5#, DAQmx_Val_VoltageUnits2_Volts, "")
    'Configure to clock using signal generated by Counter 0
    DAQmxErrChk DAQmxCfgSampClkTiming(firstTaskHandle, "/Dev1/Ctr0Out", 1000, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_ContSamps, 4000)
   
    'Analog Output
    'allocate memory for the data buffer
    DAQmxErrChk DAQmxCreateTask("MyAnalogOutputTask", secondTaskHandle)
    DAQmxErrChk DAQmxCreateAOVoltageChan(secondTaskHandle, "Dev1/ao0", "AnalogOutput", -10#, 10#, DAQmx_Val_VoltageUnits2_Volts, "")
    'Configure to clock using signal generated by Counter 0
    DAQmxErrChk DAQmxCfgSampClkTiming(secondTaskHandle, "/Dev1/Ctr0Out", 1000, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_ContSamps, 1000)
   
    For i = 0 To 999
        data(i) = 2 * Sin((i * 2# * Pi) * 1000)
     Next i

    'Write the first set of Analog Output data to the buffer so it is ready to generate
    DAQmxErrChk DAQmxWriteAnalogF64(secondTaskHandle, 1000, 0, 10#, DAQmx_Val_GroupByChannel, data(0), written, ByVal 0&)
   
    'Generate External Clock With Counter 0
    DAQmxErrChk DAQmxCreateTask("External Clock", thirdTaskHandle)
    DAQmxErrChk DAQmxCreateCOPulseChanFreq(thirdTaskHandle, "Dev1/ctr0", "External Clock", DAQmx_Val_FrequencyUnits2_Hz, DAQmx_Val_Low, 0#, 1000, 0.5)
    'Configure the pulse train to generate external clock triggered off PFI0
    DAQmxErrChk DAQmxCfgDigEdgeStartTrig(thirdTaskHandle, "/Dev1/PFI0", DAQmx_Val_Rising)
    DAQmxErrChk DAQmxCfgImplicitTiming(thirdTaskHandle, DAQmx_Val_AcquisitionType_ContSamps, 1000)
   
    'Start Tasks
    DAQmxErrChk DAQmxStartTask(firstTaskHandle)
    DAQmxErrChk DAQmxStartTask(secondTaskHandle)
    DAQmxErrChk DAQmxStartTask(thirdTaskHandle)

Thanks in advance,
 
Yingmai
0 Kudos
Message 1 of 2
(6,855 Views)
Hello Yingmai,

For help setting up an external clock in Visual Basic, I would recommend that you view this document. For general NI-DAQmx examples for Visual Basic 6.0, you can check out another document here. I hope these documents are useful. Let me know if you still have any questions.


Matt Anderson

Hardware Services Marketing Manager
National Instruments
0 Kudos
Message 2 of 2
(6,842 Views)