Hi All,
I am using NI DAQ USB-6353 with text-based C code to control it. I would like to send a continuous pulse train from the DAQ to pulse a power supply, which then activates an electron beam producing current to be read by the analog input port of the same DAQ. I would like to keep only the analog samples during the pulse peak and samples of a couple pulse widths right after. I am successfully to generate a pulse train using the sampled clock from a counter output channel, but fail to use the same clock to synchronize the pulse train with the analog input. DAQmxReadAnalogF64 is not called by the static function EveryNCallback set for the analog input task. Am I doing something wrong with the following codes? It would be great if it turns out only I am using the wrong sampled clock name of the counter ("dev1/PFI8") for the analog input. Or is something more fundamental that a counter cannot be sync. with an analog input?
Would someone be able to send me a link to an example in C or C++ or visual basic showing how to synchronize a buffered sample clocked digital pulse train from a counter output channel to an analog input? To simplify the post, the below codes do not include the static functions EveryNCallback and DoneCallBack, but I can send them if needed.
Many thanks in advance for your help,
Thuc Bui
//setting operation parameters
double initDelay = 0.0, freq = 10;
double dutyCycle = 0.0001; //thus pulse width is 10 microsec
unsigned highTicks = 4; //per period
unsigned numSamplesPerPeriod = highTicks / dutyCycle; //40000 samples/period
unsigned lowTicks = numSamplesPerPeriod - highTicks; //per period
unsigned sampleRate = 2*numSamplesPerPeriod*freq; //800000 samples/s
//create counter
TaskHandle counterTask;
int errCode = DAQmxCreateTask("", & counterTask);
errCode = DAQmxCreateCOPulseChanFreq(counterTask, "dev1/ctr0", "",
DAQmx_Val_Hz, DAQmx_Val_Low,
initDelay, freq, dutyCycle);
errCode = DAQmxCfgSampClkTiming(counterTask, "dev1/PFI8", sampleRate, DAQmx_Val_Rising,
DAQmx_Val_ContSamp, numSamplesPerPeriod);
//create analog input
TaskHandle aiTask;
double minVolt = 0.0, maxVolt = 1.0;
errCode = DAQmxCreateAIVoltageChan(aiTask, "dev1/ai0", "", DAQmx_Val_Diff,
minVolt, maxVolt, DAQmx_Val_Volts, "");
unsigned bufferSize = 10* numSamplesPerPeriod;
errCode = DAQmxSetBufInputBufSize(aiTask, bufferSize);
errCode = DAQmxCfgSampClkTiming(aiTask, "dev1/PFI8", sampleRate, DAQmx_Val_Rising, DAQmx_Val_ContSamp, numSamplesPerPeriod);
errCode = DAQmxRegisterEveryNSamplesEvent(aiTask, DAQmx_Val_Acquired_Into_Buffer,
numSamplesPerPeriod, 0, EveryNCallback, 0);
errCode = DAQmxRegisterDoneEvent(aiTask, 0, DoneCallBack, 0)
//start aiTask first
errCode = DAQmxStartTask(aiTask);
//then counterTask
errCode = DAQmxStartTask(counterTask);