j***@gmail.com
2008-07-03 10:49:19 UTC
I've been crawling these forums and google groups for a while now, and
found some really interesting info, but I still can't get my analog
output to work. What I want to do is simple : I have a 1KHz waveform
output on Ao0, and want to change the amplitude of that waveform on
the fly when I press an "up" or "down" button.
Here is my sourcecode :
ampl = 4.0;
for(int i=0;i<1000;i++)
data[i] = ampl*sin((double)i*2.0*PI/1000.0);
error = DAQmxCreateTask("",&taskHandle);
error = DAQmxCreateAOVoltageChan(taskHandle,"Dev1/
ao0","",-5.0,5.0,DAQmx_Val_Volts,NULL);
error = DAQmxCfgSampClkTiming(taskHandle,"",
1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
error = DAQmxSetWriteRegenMode(taskHandle, DAQmx_Val_AllowRegen);
error = DAQmxSetAOUseOnlyOnBrdMem (taskHandle, NULL, 0);
error = DAQmxWriteAnalogF64(taskHandle,
1000,0,0.0,DAQmx_Val_GroupByChannel,data,&res,NULL);
error = DAQmxStartTask(taskHandle);
and this is the code for the "up" button (the "down button is
identical, except for the increment on the first line) :
ampl += 1.0;
if (ampl > 5.0)
ampl = 5.0;
for(int i=0;i<1000;i++)
data[i] = ampl*sin((double)i*2.0*PI/1000.0);
int32 res;
int32 x = DAQmxWriteAnalogF64(taskHandle,
1000,0,1.0,DAQmx_Val_GroupByChannel,data,&res,NULL);
if (x < 0)
{
char buf[4097];
DAQmxGetErrorString (x, buf, 4096);
AfxMessageBox(buf);
}
This code works perfectly, but has a very bizarre delay : when
pressing the up or down button, it takes about 7 re-generations before
the result is seen on the output pins (got a scope attached) ! So on a
1KHz sample rate, it takes about 7 seconds before my output amplitude
increases or decreases
If I up the samplerate to 10KHz, it still takes 7 regenerations, but
now they are done much faster ofcourse
does anyone have an idea on how to fix this ? I really really need the
output to change as fast as possible (the final code will not use user-
clicked buttons, but input from a TTL signal, which is then processed
into a new amplitude)
many many thanks in advance!
Jeroen
found some really interesting info, but I still can't get my analog
output to work. What I want to do is simple : I have a 1KHz waveform
output on Ao0, and want to change the amplitude of that waveform on
the fly when I press an "up" or "down" button.
Here is my sourcecode :
ampl = 4.0;
for(int i=0;i<1000;i++)
data[i] = ampl*sin((double)i*2.0*PI/1000.0);
error = DAQmxCreateTask("",&taskHandle);
error = DAQmxCreateAOVoltageChan(taskHandle,"Dev1/
ao0","",-5.0,5.0,DAQmx_Val_Volts,NULL);
error = DAQmxCfgSampClkTiming(taskHandle,"",
1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
error = DAQmxSetWriteRegenMode(taskHandle, DAQmx_Val_AllowRegen);
error = DAQmxSetAOUseOnlyOnBrdMem (taskHandle, NULL, 0);
error = DAQmxWriteAnalogF64(taskHandle,
1000,0,0.0,DAQmx_Val_GroupByChannel,data,&res,NULL);
error = DAQmxStartTask(taskHandle);
and this is the code for the "up" button (the "down button is
identical, except for the increment on the first line) :
ampl += 1.0;
if (ampl > 5.0)
ampl = 5.0;
for(int i=0;i<1000;i++)
data[i] = ampl*sin((double)i*2.0*PI/1000.0);
int32 res;
int32 x = DAQmxWriteAnalogF64(taskHandle,
1000,0,1.0,DAQmx_Val_GroupByChannel,data,&res,NULL);
if (x < 0)
{
char buf[4097];
DAQmxGetErrorString (x, buf, 4096);
AfxMessageBox(buf);
}
This code works perfectly, but has a very bizarre delay : when
pressing the up or down button, it takes about 7 re-generations before
the result is seen on the output pins (got a scope attached) ! So on a
1KHz sample rate, it takes about 7 seconds before my output amplitude
increases or decreases
If I up the samplerate to 10KHz, it still takes 7 regenerations, but
now they are done much faster ofcourse
does anyone have an idea on how to fix this ? I really really need the
output to change as fast as possible (the final code will not use user-
clicked buttons, but input from a TTL signal, which is then processed
into a new amplitude)
many many thanks in advance!
Jeroen