02-02-2017 04:00 PM - edited 02-02-2017 04:01 PM
Hello everybody,
Here is what i would like my PXI 6259 generates :
- t0 :
- a 62,5 kHz digital output pulse data signal (on port0/line1)
- a digital signal S1 at +5v output (on port0/line2)
-t1 :
- stop the 62,5 kHz output
- stop the S1 signal (from 5V to 0V output)
I'm using the C API and here it what I made to generate that :
- I have created a task for the counter (62,5 kHz)
- A task for the pattern data signal
- A task for S1 signal
All task are already started.
At t0, i write the samples to the pattern task, and I set the output to 1 for the S1 task.
At t1, i writle 0 for the samples to the pattern task and i set the output to 0 for the S1 task.
The generation works fine : data and my S1 signal are correctly generated but I have a delay
- between the S1 to +5v and the start of the data output (the data start sometimes after S1 and sometimes before)
- the stop of the data output and S1 to 0v (same issue, S1 could stop after or before the data but never in the same time).
It is an issue for me.
I would like to both my data and my S1 signal start to output at the same time and stop at the same time.
I have tried another design :
at
- (t0 - offset) : write the samples in my pattern task
- start the pattern task
- set the initial delay to offset for the counter pulse
- start the counter task
- t0 : write 1 to the S1 chan to have the output at 5v
t1 :
- stop pattern and counter task
- write 0 to the S1 chan to have the output at 0v
It arrives that the delay pulse is not respected and the data task start its output while the S1 output is not as yet generated.
Would you have an idea to synchronise my both output : S1 start emitting at the same time as my data, and both stop at the same time ?
Thank you for your help and idea.
02-13-2017 07:23 AM
Hello Jank91,
Would you be able to post your code for us to have a look and to have a better understanding where you are in your developping state?
Let me also ask you some question:
- "It arrives that the delay pulse is not respected and the data task start its output while the S1 output is not as yet generated"
=> What kind of delay are we talking about?
=> Is there a specific situation when it happens?
Would you be able to test the code in attachment and see if a delay is generated between your outputs?
I think we need more information to help you: code, snapshot...
Thank you in advance for your return.
Bye!
02-22-2017 08:14 AM - edited 02-22-2017 08:15 AM
Thank you Pierre D. for your answer.
Sorry for the delay.
It is what I have tried (Here is a piece of truncated code where i have kept the interesting part)
1 - Creation of the counter and the data task using or counter as clock source
Only the counter task is started, the DO task (patternHandle) is not yet started
Note : The patternHandle Task is configured to write on 2 DO with different pattern and potentially simultaneously.
For my case e.g :
at t = 1 ms, I want to generate pattern_a_1 on the first DO during 10 ms
at t = 5 ms, generate another pattern_b on the second DO during 20 ms .
at t = 12 ms, generate another pattern_a_2 on the first DO during 15 ms
and so on.
That's why once this task is started, it will never be stopped until the program is finished.
/* Create counter task */ error = DAQmxCreateTask(taskName, &result->counter); /* Create the channel to generate the pulses */ error = DAQmxCreateCOPulseChanFreq(result->counter, result->counterName, COPulse_nameToAssignChannel, DAQmx_Val_Hz, DAQmx_Val_Low, COPulse_initialDelay, COPulse_frequency, COPulse_dutyCycle); /* Configure samples for our counter task */ DAQmxCfgImplicitTiming(result->counter, DAQmx_Val_ContSamps, (uint) COPulse_frequency); /* Create the task which will generate data using the counter as clock source */ error = DAQmxCreateDOChan(result->patternHandle, DOChan_physicalChannel, DOChan_virtualChannelName, DAQmx_Val_ChanForAllLines); error = DAQmxCfgSampClkTiming(result->patternHandle, clockSource, /* ctr1 timer is associated to PFI13 source */ COPulse_frequency, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 512); /* Start our counter task */ error = DAQmxStartTask(result->counter);
2 - Creation of the signal task (not started for the moment)
/* Create or Signal task */ error = DAQmxCreateTask(taskName, &result->SignalTask); /* Add DO to the task */ error = DAQmxCreateDOChan(result->SignalTask, DOChan_PhysicalChannel, DOChan_VirtualChannel, DAQmx_Val_ChanForAllLines);
3 - When I receive a " start top" I would generate the data on a given DO and the sig and start them at the same time
For that, when I receive the top this is what i do sequentially :
- Write the sample
- Start the signal task
/* Write our samples to the data task and start the task if it is not started */ error = DAQmxWriteDigitalU32(fsk->patternHandle, SAMPLE_COUNT, 1, -1, DAQmx_Val_GroupByChannel, fskSamples, &returnValue, NULL); /* Set the output of our sigTask to 1 */ error = DAQmxWriteDigitalU32(sigTask, 1, 1, -1, DAQmx_Val_GroupByChannel, &value, NULL, NULL);
4- When I receive the "stop top" I don't stop both the data and signal task but write 0 as pattern for data task and 0 as output for signal task
/* Write our samples = table of sample count set 0 to the data task */ error = DAQmxWriteDigitalU32(fsk->patternHandle, SAMPLE_COUNT, 1, -1, DAQmx_Val_GroupByChannel, fskSamples, /* all the sample count to 0 */ &returnValue, NULL); /* Set the output of our sigTask to 1 */ error = DAQmxWriteDigitalU32(sigTask, 1, 1, -1, DAQmx_Val_GroupByChannel, &value, /* Value = 0 for the concerned DO */ NULL, NULL);
What I observe is a delay between the start or the stop of data task and sig task and it always arrives :
=> when i receive the "start top" : the output data pattern start emitting after the signal while the data task was written before the sig task one (attachment : data_start_after_sig, data in pink, sig in yellow)
=> when i receive the "stop top" : the output data pattern stop emitting after the signal while the data task was written to 0 before the sig task one (attachment : data stop_after_sig, data in pink, sig in blue)
Trying to start the data and sig starting and stopping at the same time, I have tried different solution (I exclude the trigger my PXI 6259 card does not support software and digital trigger)
Here are explained my variant :
Step 1 : the counter task is not started, only the pattern task is started (and emit nothing because of the counter task which is not started)
Step 3 : when receiving the "start top", just a little time before emitting data (at t0 - delta), i write my pattern to the data task (digitalWrite) and configure a delay before starting the counter task with DAQmxSetCOPulseFreqInitialDelay with a delay of delta.
When the time is up to start generating, i write 1 to the output of the sig task (other variant i stop the sig task)
Step 4 : I stop the data task and the sig task when the time is up to stop emitting
I have never succeeded to have a data and sig task starting and stopping at the same time.
Is this delay usual ?
I have a look to the code in attachement and i'll let you know.
Thank you very much for your help
Jank