Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

[bug]A combo of two conters and one trigger, CTR2 doesn't work with autostart

When we want to start two counters with one trigger, this is only possible when we set the trigger up with the following set-up.

DAQmxErrChk(DAQmxSetChanAttribute (taskOut, ChannelName, DAQmx_DO_InvertLines,0));

DAQmxStartTask (HandleDIO[0]);

Then the trigger(HandleDIO[0]) is activated and both the counters will start running.
DAQmxWriteDigitalLines (HandleDIO[0], 1, 1, 1.0, DAQmx_Val_GroupByChannel, &OnOff, NULL, 0);

When we use the auto-start option in DAQmxSetChanAttribute(), only counter2 will not start running with a combination of two counters. A combination with two counters without counter 2 works perfectly with the autostart option.


We are using NI-6602 with CVI 8.11

Message Edited by Co on 03-05-2008 04:12 AM
0 Kudos
Message 1 of 5
(4,286 Views)

Dear Co,

Could you please post some example code so we can try and reproduce the issue. At this point we I can't even tell if you are measuring or generating? I would need your DAQmx calls in sequence of calling inorder to recreate your exact situation.

Kind Regards

Karsten

National Instruments

0 Kudos
Message 2 of 5
(4,258 Views)
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
0 Kudos
Message 3 of 5
(4,253 Views)
I adapted the code whithout lose of functionality to a code what is easier to copy or reproducte.

//Adapted code for the bug report
#define DEVICE "Dev1"

void main(void){
double Period,
LowHighTime,
PhaseShift,
PhaseA,
PhaseB;

Period = (1 / (double)Frequency);
LowHighTime = 0.5 * Period;
PhaseShift = 0.25 * Period;
PhaseA = 1;
PhaseB = (PhaseShift + 1);



//----------------------
//Setting up the channel PFI 7 as trigger for both the timers
//----------------------

ChannelDIO = 7;
OnOff = 1;

int32 DAQmxError = DAQmxSuccess;

sprintf (DigitalIO, "%s/port0/line%d", Device, ChannelDIO);
sprintf (TaskName, "DAQTaskDigitalIO%d", ChannelDIO);
sprintf (ChannelName, "LineName%d", ChannelDIO);

DAQmxErrChk(DAQmxCreateTask (TaskName, &taskOut));
DAQmxErrChk(DAQmxCreateDOChan (taskOut, DigitalIO, ChannelName, DAQmx_Val_ChanPerLine));
DAQmxErrChk(DAQmxSetChanAttribute (taskOut, ChannelName, DAQmx_DO_InvertLines,0));

DAQmxStartTask (taskOut);


//------------------------
//Configuring both the counters with a phaseshift.
//------------------------

sprintf (CounterA, "%s/ctr0", Device);
sprintf (CounterB, "%s/ctr2", Device);
sprintf (DigitalIO, "/%s/PFI7", Device);

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, 50));
DAQmxErrChk(DAQmxCfgImplicitTiming (taskOutB, DAQmx_Val_FiniteSamps, 50));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig (taskOutA, DigitalIO, DAQmx_Val_Rising));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig (taskOutB, DigitalIO, DAQmx_Val_Rising));

DAQmxStartTask (TaskOutA);
DAQmxStartTask (TaskOutB);

//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, the counters will be stopped in a timer which checks wether or not the tasks are done.
DAQmxStopTask (HandleDIO[0]);
DAQmxClearTask (HandleDIO[0]);
}
0 Kudos
Message 4 of 5
(4,231 Views)
Hi,

Is there anything new to report about this issue?
Are we doing something wrong or is it really a bug?

Greetings,
Co
0 Kudos
Message 5 of 5
(4,156 Views)