Dear Sirs:
Please, Firs,I don't know If it is the adequete forum but I expect here I can get some hint about my question.....I have a problem and don't know if this have solution with only one PCI 6602 card.
I need to make "simultaneous" tasks such as quadrature encoder reading, PWM generation with
variable duty cycle , and also I need to write and read from digital I/O
lines.
I wrote the following code , but as I indicate, I can't get the things works as I expect.
First I get the PWM works,but then when I start the task for reading I/O lines the PWM generation stops.
So what I must to have present about working with many tasks in the PCI6602 card??
Thank you for your replies.
Regards
My code is here:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <conio.h>
#include "NIDAQmx.h"
#pragma link "nidaqmx.lib"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) FncError(); else
#define DAQmxErrChkOut(functionCall) if( DAQmxFailed(error=(functionCall)) ) FncErrorOut(); else
#define DAQmxErrChkIn(functionCall) if( DAQmxFailed(error=(functionCall)) ) FncErrorIn(); else
char errBuff[2048]={'\0'};
int error=0;
TaskHandle taskHandlePWM=0,taskHandleOut=0,readhandlez=0;
void FncErrorIn(){
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( readhandlez!=0 ) {
}
if( DAQmxFailed(error) )
printf("%s",errBuff);
}
void FncErrorOut(){
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandleOut!=0 ) {
}
if( DAQmxFailed(error) )
printf("%s",errBuff);
}
void FncError(){
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandlePWM!=0 ) {
}
if( DAQmxFailed(error) )
printf("%s",errBuff);
}
int main(int argc, char* argv[])
{
// uInt8 palabra_enable[3]={0,1,1};
char K=0,i;
int32 read;
int32 bytesPerSamp;
uInt8 datain[8]={0,0,0,0,0,0,0,0};
DAQmxErrChk (DAQmxCreateTask("",&taskHandlePWM));
DAQmxErrChkIn(DAQmxCreateTask("",&readhandlez));
//--------------------------------------------------
DAQmxErrChk ( DAQmxCreateCOPulseChanFreq (taskHandlePWM, "Dev1/ctr2","",DAQmx_Val_Hz , DAQmx_Val_High, 0, 1, 0.9));
DAQmxErrChk (DAQmxCfgImplicitTiming(taskHandlePWM,DAQmx_Val_ContSamps,1000));
DAQmxErrChk ( DAQmxStartTask(taskHandlePWM));
// I CHANGE THE DutyCycle. TO 10%
DAQmxErrChk(DAQmxWriteCtrFreqScalar(taskHandlePWM, true, DAQmx_Val_WaitInfinitely, 1, 0.1, NULL));
//WELL...up to this point the PULSE TRAIN is being generated......I SEE THE LED IS OSCILLATING AS I EXPECT IT.
getche();
//-------------------------------------------
//BUT FROM HERE THE LED where I AM SEEING THE PULSE TRAIN TURNS OFF...THE PULSE TRAIN
//IS NO MORE BEING GENERATED...WHY??? and HOW TO SOLVE IT?
//DAQmxErrChkIn( DAQmxCreateDIChan (readhandlez, "Dev1/port0/line4:5", "", DAQmx_Val_ChanForAllLines));
DAQmxErrChkIn( DAQmxCreateDIChan (readhandlez, "Dev1/port0/line4:5", "", DAQmx_Val_ChanPerLine));
DAQmxErrChkIn( DAQmxStartTask(readhandlez));
DAQmxErrChkIn( DAQmxReadDigitalLines (readhandlez, 1, 10.0, DAQmx_Val_GroupByChannel , datain, 8, &read, &bytesPerSamp, NULL));
while(!kbhit()){
DAQmxErrChkIn(DAQmxReadDigitalLines (readhandlez, 1, 10.0, DAQmx_Val_GroupByChannel , datain, 8, &read, &bytesPerSamp, NULL));
for(i=0;i<=7;i++){
gotoxy(10+i,10);
printf("%d",datain[7-i]); //<-----I PRINT ON THE SCREEN THE READ BITS, THIS WORKS FINE
}
}
getch();
// I STOP THE TASKS
DAQmxStopTask(taskHandlePWM);
DAQmxClearTask(taskHandlePWM);
DAQmxStopTask(readhandlez);
DAQmxClearTask(readhandlez);
}
//---------------------------------------------------------------------------