Thanks for responding.
ChannelDIO = 7;
OnOff = 1;
//In the CreateDAQTaskPhaseShift en --IO, the proper handle belonging to channel 0 and 2 will be written to this callback.
//Here is a small bug. The combo of counter 2 only works when there is no autostart enabled for PFI 7.
i32_NI6602_CreateDAQTaskDigitalIO (&HandleDIO[0], DEVICE, ChannelDIO);
DAQmxStartTask (HandleDIO[0]);
//Configuring both the counters.
i32_NI6602_CreateDAQTaskPhaseShift (&HandleChannel[0], &HandleChannel[1], DEVICE, Frequency, NrOfPulses, UpDown);
DAQmxStartTask (HandleChannel[0]);
DAQmxStartTask (HandleChannel[1]);
//Generating a puls on PFI7.
Delay(0.1);
DAQmxWriteDigitalLines (HandleDIO[0], 1, 1, 1.0, DAQmx_Val_GroupByChannel, &OnOff, NULL, 0);
Delay(0.1);
OnOff = 0;
DAQmxWriteDigitalLines (HandleDIO[0], 1, 1, 1.0, DAQmx_Val_GroupByChannel, &OnOff, NULL, 0);
Delay(0.1);
//Clear the IO of PFI7
DAQmxStopTask (HandleDIO[0]);
DAQmxClearTask (HandleDIO[0]);
And the functions implemented in the dll
int DLLEXPORT DLLSTDCALL i32_NI6602_CreateDAQTaskDigitalIO(TaskHandle *taskDIO,char *Device, unsigned int OutPut)
{
char DigitalIO[25]={0},
TaskName[25]={0},
ChannelName[25]={0};
int32 DAQmxError = DAQmxSuccess;
TaskHandle taskOut;
sprintf (DigitalIO, "%s/port0/line%d", Device, OutPut);
sprintf (TaskName, "DAQTaskDigitalIO%d", OutPut);
sprintf (ChannelName, "LineName%d", OutPut);
DAQmxErrChk(DAQmxCreateTask (TaskName, &taskOut));
DAQmxErrChk(DAQmxCreateDOChan (taskOut, DigitalIO, ChannelName, DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute (taskOut, ChannelName, DAQmx_DO_InvertLines,0));
*taskDIO = taskOut;
Error:
return DAQmxError;
}
int DLLEXPORT DLLSTDCALL i32_NI6602_CreateDAQTaskPhaseShift (TaskHandle *taskOutPhaseShiftA, TaskHandle *taskOutPhaseShiftB, char *Device, unsigned int Frequency, unsigned int NrPulses, unsigned int UpDown)
{
char CounterA[25]={0},
CounterB[25]={0},
DigitalIO[25]={0};
double Period,
LowHighTime,
PhaseShift,
PhaseA,
PhaseB;
int32 DAQmxError = DAQmxSuccess;
TaskHandle taskOutA, taskOutB;
sprintf (CounterA, "%s/ctr0", Device);
sprintf (CounterB, "%s/ctr2", Device);
sprintf (DigitalIO, "/%s/PFI7", Device);
Period = (1 / (double)Frequency);
LowHighTime = 0.5 * Period;
PhaseShift = 0.25 * Period;
if (UpDown == 1)
{
PhaseA = 1;
PhaseB = (PhaseShift + 1);
}
else
{
PhaseA = (PhaseShift + 1);
PhaseB = 1;
}
DAQmxErrChk(DAQmxCreateTask ("TaskOutA", &taskOutA));
DAQmxErrChk(DAQmxCreateTask ("TaskOutB", &taskOutB));
DAQmxErrChk(DAQmxCreateCOPulseChanTime (taskOutA, CounterA, "ChannelName0", DAQmx_Val_Seconds, DAQmx_Val_Low, PhaseA, LowHighTime, LowHighTime));
DAQmxErrChk(DAQmxCreateCOPulseChanTime (taskOutB, CounterB, "ChannelName2", DAQmx_Val_Seconds, DAQmx_Val_Low, PhaseB, LowHighTime, LowHighTime));
DAQmxErrChk(DAQmxCfgImplicitTiming (taskOutA, DAQmx_Val_FiniteSamps, NrPulses));
DAQmxErrChk(DAQmxCfgImplicitTiming (taskOutB, DAQmx_Val_FiniteSamps, NrPulses));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig (taskOutA, DigitalIO, DAQmx_Val_Rising));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig (taskOutB, DigitalIO, DAQmx_Val_Rising));
*taskOutPhaseShiftA = taskOutA;
*taskOutPhaseShiftB = taskOutB;
Error:
return DAQmxError;
}
When we replace in the DAQmxWriteDigitalLines the Auto Start a combination of counter 2 and another counter wil run.
Message Edited by Co on 03-11-2008 08:56 AM