Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Use multiple counters on PCI 6601

Hello, my name is Igor and i'm an young VB6 programmer. I'm an electronic engineer but i never used this language to my study.

 

My problem is "simple", i need to measure 3 PWM with an PCI 6601, this is the easy, but my problem is the reading's times.

 

The frequency that i would to measure is 1Khz and if i measure only one channel no problem, i have 1000 samples for second. If i want measure 2 or more PWM the numbers of measure drop to 22 (case with 3 counters).

 

The code is

 

   'Questa funzione serve a creare il canale dalla quale poi viene effettuata la misura
    DAQmxErrChk DAQmxCreateCIPulseWidthChan(taskHandle1, "Dev1/ctr0", MyChannel1, 0.00001, _
    0.00009, DAQmx_Val_TimeUnits3_Seconds, DAQmx_Val_Edge1_Rising, "")
    DAQmxErrChk DAQmxCreateCIPulseWidthChan(taskHandle2, "Dev1/ctr1", MyChannel2, 0.00001, _
    0.00009, DAQmx_Val_TimeUnits3_Seconds, DAQmx_Val_Edge1_Rising, "")
    DAQmxErrChk DAQmxCreateCIPulseWidthChan(taskHandle3, "Dev1/ctr2", MyChannel3, 0.00001, _
    0.00009, DAQmx_Val_TimeUnits3_Seconds, DAQmx_Val_Edge1_Rising, "")

    'Setta il numero di campioni da acquisire ogni volta che va in lettura e
    'il modo di lettura. Si è impostato "contsamps" per avere la lettura continua
'    DAQmxErrChk DAQmxCfgImplicitTiming(taskHandle1, DAQmx_Val_AcquisitionType_ContSamps, 1)
'    DAQmxErrChk DAQmxCfgImplicitTiming(taskHandle2, DAQmx_Val_AcquisitionType_ContSamps, 1)
'    DAQmxErrChk DAQmxCfgImplicitTiming(taskHandle3, DAQmx_Val_AcquisitionType_ContSamps, 1)
    

'parte di prova per lettura di 3 task
    Tm = Timer
    counter = 0
    counter1 = 0
    'While per vedere quanti campioni legge in un secondo. IL numero di counter va
    'poi diviso per due. Si è fatto così almeno si salva sia il periodo basso
    'che quello alto
    DAQmxErrChk DAQmxStartTask(taskHandle1)
    task1IsRunning = True
    DAQmxErrChk DAQmxStartTask(taskHandle2)
    task2IsRunning = True
    DAQmxErrChk DAQmxStartTask(taskHandle3)
    task3IsRunning = True
    'task1IsRunning = True
    Do While (Timer < (Tm + 1))
        DoEvents
        DAQmxErrChk DAQmxReadCounterScalarF64(taskHandle1, 0.005, data1, ByVal 0&)
        DAQmxErrChk DAQmxReadCounterScalarF64(taskHandle2, 0.005, data2, ByVal 0&)
        DAQmxErrChk DAQmxReadCounterScalarF64(taskHandle3, 0.005, data3, ByVal 0&)
        
'        DAQmxErrChk DAQmxReadCounterF64(taskHandle1, 1, 0.005, data1(0), 1, 1, ByVal 0&)
'        DAQmxErrChk DAQmxReadCounterF64(taskHandle2, 1, 0.005, data2(0), 1, 1, ByVal 0&)
'        DAQmxErrChk DAQmxReadCounterF64(taskHandle3, 1, 0.005, data3(0), 1, 1, ByVal 0&)
        counter = counter + 1
    Loop
    counter1 = counter
'fine prova
 

If i use '    DAQmxErrChk DAQmxCfgImplicitTiming(taskHandle1, DAQmx_Val_AcquisitionType_ContSamps, 1) i read faster but i can't use this function for evry task because the pci6601 have only one dma and i've try to change read mechanism but i not arrived to the solution.

 

Can you help me??

 

Sorry for my english that are not so good.

 

Best regards

 

Igor

 

 

0 Kudos
Message 1 of 6
(6,282 Views)

Ciao Igor,

 

It sounds like you are looking for this function:

 

DAQmxSetCIDataXferMech(TaskHandle taskHandle, const char channel[], DAQmx_Val_Interrupts);

 

As you have mentioned, you can only have one task configured as DMA (DAQmx_Val_DMA) on the 6601.  Configure two of your tasks to interrupts using the above call and you should be able to run all 3 simultaneously with implicit timing.

 

 

Best Regards,

John Passiak
0 Kudos
Message 2 of 6
(6,273 Views)

Thanks John,

 

I have tried this function but doesn't work properly, but i'ts possible that i put this code line in the wrong place. I haven't find example of the use of this function...

 

Thanks

 

Best regards

Igor

 

0 Kudos
Message 3 of 6
(6,256 Views)

Hi John,

 

Sorry but i have used DAQmxSetDIDataXferMech, and it doesn't work, the function that you have suggest me is correct and my program work properly.

 

Thanks for your help.Smiley Happy

 

Have a nice day and good job!

 Igor

 

0 Kudos
Message 4 of 6
(6,250 Views)

I'm here, yet.

 

With your help i can read 1000 samples per second on 3 counters (this is my target) but is a buffered measurement and is not the best for our problem.

 

I've try to use a single pwm measurement without success, because if i use a function DAQmxReadCounterScalarF64 (without dma for read 3 counters) all samples are put in the buffer and i read the value in the buffer (for example, i want read a PWM of a 1 KHz square wave evry 100 ms but, when i try, i read 100 times the values of the first 100 ms (but the the elapsed time is about 10 sec)

 

Is not possible to over write the array(also if I read alwais the buffer in the same place of array i have some problems) and i also try to use a method DAQmx_Val_ProgrammedIO but i'm not so fast (nearly 64 sample for second)


The question: Exist a method to read 1 sample in NON-buffered mode? Or Can i erase the unread sample in the buffer?

 

Thanks for your help!!!

 

Igor

0 Kudos
Message 5 of 6
(6,220 Views)

You don't have to read in buffered mode, taking out implicit timing (which will change the data transfer mechanism to programmed I/O) would accomplish this.  However, as you have noted doing this will make the reads take a quite a bit longer to execute (the acquired sample will also start from the next pulse after the read is called).

 

You could instead continue using buffered mode but read the most recent sample previously-acquired by adding the following calls to your implicitly-timed task:

 

DAQmxSetReadRelativeTo(taskHandle,DAQmx_Val_MostRecentSamp);
DAQmxSetReadOffset(taskHandle,-1);

 

Some newer cards (STC3-based ones like X Series or CompactDAQ) support the use of sample-clocked pulse width measurements (you can average out the samples between clocks OR return the most recent data point) but this isn't a feature on the 6602 unfortunately.

 

 

Best Regards,

John Passiak
0 Kudos
Message 6 of 6
(6,211 Views)