09-05-2008 06:06 AM
Hello,
I have a M series DAQ board and am using LabWindows/CVI 8.0 to program it.
What I'm trying to do is to make a program where I can output a voltage (DAC) for a specific duration of time (from 0.001ms to 1s).
I also want to measure voltage at an ADC input while the voltage at the DAC is present for the time duration.
I made a similar program before with counters in the old DAQ library, but I'm not familar with DAQmx yet.
Any information would be helpful.
Thank you.
09-08-2008 05:29 PM - edited 09-08-2008 05:32 PM
Hey slumber70,
Thanks for posting on the NI Discussion Forums! I understand you are new to programming DAQmx in LabWindows/CVI. Two great resources are the DAQmx C Reference Help and the ANSI C examples. The DAQmx C Reference Help can be found by going to Start»Programs»National Instruments»NI-DAQ»NI-DAQmx C Reference Help. See the following KnowledgeBase article for the location of the ANSI C examples.
KnowledgeBase 3V09OJNY: Location of ANSI C NI-DAQmx Shipping Examples and DAQmx Library File for Win...
I would specifically look at the following two examples to get more familiar with the DAQmx programming architecture.
MultVoltUpdates-IntClk
Acq-IntClk
In order to read back the analog output voltage, you can create an analog input task and reference the ao0_vs_aognd channel as seen in the image below.
09-08-2008 07:25 PM
Thank you RT4CY for the information.
I have no problem programming voltage input and outputs with LabWindows/CVI.
What I'm having trouble is how to program counters or timers so that I can output voltages for a specific duration of time.
I used to use onboard counters to do this job with MIO-16X series boards.
Now I need to port the old code to DAQmx and I'm stuck.
Would you point me to a relevant example or functions?
Thank you again.
slumber70
09-09-2008 08:41 PM
Hi slumber70,
Sorry about that, I had misunderstood your original post. How exactly did you use the counters to time your analog output? Did you have some kind of counter input task? Is there any reason why you have to use a counter task, instead of just configuring your analog output task as finite? It would be helpful if you could post a snippet of your traditional daq code, so I could point you in the right direction.
09-10-2008 07:23 AM
Hi RT4CY,
Thank you for taking care of my questions.
I made a function called wait(a) which wait for 'a' milliseconds using internal time base.
(see below for the snippet of the codes).
Then, I could do following to output voltages for specific duration like this.
AO_VWrite (1, Vch, Vout);
Wait (pulsewidth)
AO_VWrite (1, Vch, 0.0);
Probably, this is not the best way to accomplish this. If there is better way, let me know.
Would you also point me to functions which replace DAQ_Op() function in old DAQ?
The snippet of my old codes follows. Thank you so much.
--------------------------------------------------------------------------------------------------------------------
void InitializeTimer(void)
{
GPCTR_Control(1, ND_COUNTER_0, ND_RESET); //reset timer
GPCTR_Set_Application(1, ND_COUNTER_0, ND_SIMPLE_EVENT_CNT); //Set timer application for simple event counting
GPCTR_Change_Parameter(1, ND_COUNTER_0, ND_SOURCE, ND_INTERNAL_100_KHZ); //Set source as 100kHz internal time base
}
void Wait(float ptime) //wait for ptime (units of msec)
{
unsigned long i = 0;
int Handle, ItemID;
InitializeTimer();
GPCTR_Control(1, ND_COUNTER_0, ND_PROGRAM); //start counter
while(i < 100*ptime) {
GPCTR_Watch(1, ND_COUNTER_0, ND_COUNT, &i); //read the counter
GetUserEvent (0, &Handle,&ItemID);
}
}
09-11-2008 12:01 PM - edited 09-11-2008 12:01 PM
Howdy slumber,
The simplest way to input or output a voltage for a specified period of time on one channel would be to use the number of samples to be written/read and the rate. For example, if you want to output a constant voltage for 8 seconds, you could use something like one of these configurations:
You could ensure that both tasks start simultaneously by sharing a start trigger as illustrated in the image attached to this post. (LabVIEW code translates pretty much 1:1 to CVI)
Since you want to perform both AI and AO simultaneously, I'll mention an alternative and slightly more robust technique; and that is generating a custom pulse on counter 0 and using this pulse as your sample clock for both your AI and your AO task. The pulse would effectively handle the timing of your output, which will make sure both tasks start simultaneously and stay synchronized.
In terms of example code, you can combine a few examples in NI Example Finder for the each task
Let us know how things go!