08-17-2010 05:35 AM
Hi,
I am using USB6221 device.
I have created two Digital Output channels with a frequency of 75KHz and Duty cycle of 50%.But I need a delay of 1 microsecond between the two channels.
I craeted both vchannels on the same task, and assumed that if I use a delay of 0, the channels will be synchronized, but looking at the scope, the channels are not synchronized. Below is the code I used (of coarse I checked also all return codes, and all is well).
Thanks,
Danny.
int32 RetCode;
RetCode = DAQmxCreateTask("", &m_OCtaskHandle);
LogMessage(RetCode, "CreateTask", "");
if ( RetCode >= 0 )
{
// define the first output channel for Transmitter 1 (75KHz)
RetCode = DAQmxCreateCOPulseChanFreq(m_OCtaskHandle, "/Dev1/ctr0",
"Transmit1 Line1", /* Name to assign to channel */
DAQmx_Val_Hz, DAQmx_Val_High,
0.0, /* Initial delay in seconds */
75000.0, /* Freq */
0.5 /* Duty Cycle */);
// define the second output channel for Transmitter 1 (75KHz with 1 microsecond delay)
RetCode = DAQmxCreateCOPulseChanFreq(m_OCtaskHandle, "/Dev1/ctr1",
"Transmitt1 Line2", /* Name to assign to channel */
DAQmx_Val_Hz, DAQmx_Val_High,
0.000001, /* Initial delay */
75000.0, /* Freq */
0.5 /* Duty Cycle */);
// define all channels of task to be continuous
RetCode = DAQmxCfgImplicitTiming(m_OCtaskHandle, DAQmx_Val_ContSamps, 1000 /* I think NA since continuous */);
RetCode = DAQmxStartTask(m_OCtaskHandle);
Solved! Go to Solution.
08-18-2010 02:24 PM
Hello Danny,
With the counters on the USB6221, there aren't automatically synchronized by being placed into the same task. In order to synchronize them, I would suggest using a DAQmx start trigger and I have included the function that you would need for this. I would place this piece of code in between the Configure Timing function and the DAQmx start.
Digital Start Trigger:
int32 DAQmxCfgDigEdgeStartTrig (TaskHandle taskHandle, const char triggerSource[], int32 triggerEdge);
As you can see from this function, you will need to provide an external signal to trigger the generation. If you don't have an external signal that will trigger this generation, you can use a Digital Output to provide the trigger. You will need to wire the Digital Output to the PFI line you select to be your trigger. I hope this information helps you and if you need any more assistance, feel free to post.
08-18-2010 02:49 PM
Hi Jim,
Thank you very much for your response.
While waiting for your solution, I tried something else that worked as well.
I defined each channel in a different task.
I then called DAQmxCfgDigEdgeStartTrig(m_SecondSignalTaskHandle,"ctr0InternalOutput",DAQmx_Val_Rising);
and then I started both tasks (first the main task that uses Ctr0 and then the m_SecondSignalTaskHandle task.
In doing so I also gained one more feature that I needed: The two channels are identical (75KHz with 50% duty cycle), but I needed them to be inverted.
The HW we have (USB-6221) does no support inverting channels, but the since I used DAQmx_Val_Rising, the channels are now synchronized and inverted.
I do have another question: As you can see I used here the two crt channels. But I need additional 4 channels (all 4 are identical but shifted in time). These channels must be synchronized to the previous ones, and are used as enable /. disable: i.e for N pulses of the previous channel, I should have signal up, and for M pulses I need signal down. Are there any channels left I can use to create more signals with frequency and duty cycle? Any other idea how to implement this?
Best Regards,
Danny.
08-19-2010 03:15 PM
Hello Danny,
If you are looking for more channels to output digital pulse trains, you can create 1 counter task that is used as the clock for output data on several digital lines. For this digital task, you will need to make the source of the clock to the PFI line of the output of your Counter task. After this has been done, you will need to create the digital signal for each line to output and write that to the card. The example called Write Dig Chan-Ext Clk will explain how to setup the digital task so that the task has an external clock (the counter). I hope this information helps you and if you have any more questions, feel free to post.