LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Easy aquireing

Hallo,

I have a problem with aquireing data with the highest sample rate my device is able to aquire. (1,000,000 Hz)

I think, I have timing problems and don't know which timer source I should take. I have this program fragment from a Sample Program from ni and modified it.

Maybe, you can tell me how I should set the buffer size and the other critical parameters. When running my program with 1 MHz, some different Errors come.

 

 

{
                GetCtrlVal (handle_panel_main, PANEL_1_NUMERIC_ABTASTRATE, &abtastrate);   // abtsatrate = The sample rate, with which I want to measure.
                DAQmxCreateTask ("ni", &ni_messung);
                DAQmxCreateAIVoltageChan (ni_messung, "Dev1/ai0:3", "", DAQmx_Val_Cfg_Default, 0, 10, DAQmx_Val_Volts, "" );
                DAQmxCfgSampClkTiming (ni_messung, "", abtastrate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 10000); // wich source for timing is good?           
                if( (daten=malloc(10000*4*sizeof(float64)))==NULL )   // I do not know how big the buffer should be.
                {
                    MessagePopup("Fehler","Nicht genügend Arbeitsspeicher" );
                }
           
                DAQmxStartTask(ni_messung);
                messung = 1;
                ProcessDrawEvents();
           
                while (messung)
                {
               
                    SetCtrlVal (handle_panel_main, PANEL_1_LED_MESSUNG, messung);
                    SetCtrlAttribute (handle_panel_main, PANEL_1_NUMERIC_ABTASTRATE, ATTR_DIMMED, messung);
                    SetCtrlAttribute (handle_panel_main, PANEL_1_BUTTOM_MESSUNGSTART, ATTR_DIMMED, messung);
                    SetCtrlAttribute (handle_panel_main, PANEL_1_BUTTON_MESSUNG_STOP, ATTR_DIMMED, 0);
                    DAQmxReadAnalogF64 (ni_messung, -1, 10, DAQmx_Val_GroupByScanNumber, daten, 10000, &gelesen, 0);

                    if (gelesen > 0)
                    {
                        for (i=0; i<gelesen; i++)
                        {
                            if (gelesen > 4000)
                                printf("Warning" );

                            //fprintf (messdatei, "%f;%f;%f;%f\n", daten[0], daten[1], daten[2], daten[3]);
                        }
                    }
               
                    ProcessSystemEvents();

                }
            }

 

Maybe, anybody can help me.

 

Thanks and greetings,

chemph 

Message Edited by chemph on 11-14-2008 01:17 PM
0 Kudos
Message 1 of 13
(4,366 Views)

Hello chemph,

 

Here is what I "feel" about your code:

 

- Any timing source is good if it has correct frequency. Just be sure that your harware supports that frequency. If you need to synchronize your measurements with other events on your system then use an external clock if you have one. Or you can use the onboard clock and export it to other devices (assuming your hardware supports it).

 

- The buffer size specified in your code looked correct to me. You can make the # of samples a variable or #define it and formulate the values (cfg sample clk, buffer size, wait amount) that are depending on it. This way, you do not have to change multiple values in the code to just change the number of samples.

 

- Why are you calling the DAQmxReadAnalogF64 function in the loop? You have already set a timing for your samples. Just initiate the acquisition and wait until it is finished. The time required is (# of samples)/(sampling rate). After that you call DAQmxReadAnalogF64 just once and all data is in your array. Here, be sure your hardware has enough memory to store all the samples.

 

Hope this helps. 

S. Eren BALCI
IMESTEK
Message 2 of 13
(4,342 Views)

Some more comments:

If the "messung" variable is for being able to stop the process, then use the DAQmxIsTaskDone function in the loop to check if the task is finished or still sampling. For the values you provided (1MHz sampling and 10,000 samples) acquisition takes only 10 msec. I think you can just wait for it? 🙂

 

But for a rate like 100 Hz and 10,000 samples it would take 100 sec, in which case you may need put a cancelling option for the user.

 

I do not know much analog input boards capable of sampling 4 channels together at 1MHz. So, check your hardware documentation.

Can you also clarify what you mean by "different errors come" ? That error may be related to the hardware limitation I just mentioned.

 

Hope this helps.  

S. Eren BALCI
IMESTEK
Message 3 of 13
(4,339 Views)

Hello, I am using ni 6024e. I do not think that there are any problems with 4 channels and 1,000,000 Hz. Or do I see this wrong? Smiley Happy

 

How should I arrange the Read-function when not in a loop? I did not understand your solution.

 

This error came:

 

 NON-FATAL RUN-TIME ERROR:   "messung.c", line 53, col 21, thread id 0x00000598:   Function DAQmxReadAnalogF64: (return value == -200279 [0xfffcf1a9]). Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.  Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem. Property: DAQmx_Read_RelativeTo Corresponding Value: DAQmx_Val_CurrReadPos  Property: DAQmx_Read_Offset Corresponding Value:    Task Name: ni  Status Code: -200279

 

Sorry, when posting stupid questions, but I tried with ni examples and have theese problems 

0 Kudos
Message 4 of 13
(4,302 Views)

Hi chemph,

 

The loop is OK, I did not realize at first that you wanted to make continious acquisition.

If you had configured the card for finite samples then my comments would be valid.

 

About the hardware, I do not think you have 1MHz sampling capability with 6024E. The NI web page says it 200 kS/s.

http://sine.ni.com/nips/cds/print/p/lang/en/nid/10969  (Isn't this your DAQ card?)

 

So you can sample with a clock of maximum 200kHz.

Did you try running your card from its Test Panel in MAX? Try it see if you can achieve setting the sampling rate as 1MS/s.


If this is your card, its onboard memory can hold 2048 samples. But you wanted to make a continious acquisiton of 10,000 samples per channel.

The error you got warns you that the sample buffer got full before you read it and it had to overwrite the previous values.

 

I can comment more on this once we are certain about your hardware. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 13
(4,284 Views)

Hi ebalci,

 

Thank you very much for answering! 

I am using ni PCI_6024E, not the PCMCIA one. The reason because I wondered is that wehn passing a 1,000,000 rate, no error appears, but when passing a rate higher than 1MHz there is an error that it is not supported by device. Why does not the error appear wehn passing rate higher than 200,000 Hz?

But you're right. Wehn running Test pannels in MAX, at 200,000 Hz everyting is fine, but over 200,000 Hz a warning appears. 1,000,000 Hz measurement is running without errors.

Maybe, when it is only possible to aquire safty with 200,000 Hz for four channels then this should be enough. But I want that I can use the maximum destinated sample rate of my device secure.

 What does it mean, when the memory can hold 2048 samples? Is it per channel or total? (sample = measured float64 data?)

 

 

 

 

Maybe, I do not know exactly how to set the best configuration. 

 

DAQmxCfgSampClkTiming (ni_messung, "", abtastrate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, ????); 

 

and

 

                if( (daten=malloc(????*4*sizeof(float64)))==NULL )
                {
                    MessagePopup("Fehler","Nicht genügend Arbeitsspeicher" );
                }

 

and

 

DAQmxReadAnalogF64 (ni_messung, -1 correct????, 10, DAQmx_Val_GroupByScanNumber, daten, ????, &gelesen, 0);
 

 

 

 

Message Edited by chemph on 11-21-2008 01:38 AM
0 Kudos
Message 6 of 13
(4,265 Views)

Hi chemph,

 

To be sure, lets do some double-check:

Lets connect a sine-wave of 200kHz to your card to one of the inputs. Use MAX again and verify you can see an acceptable sine wave on the screen using 1,000,000 sample rate.

If your card is really capable of 1,000,000 then it will display a sine with less amplitude and it may look like a staircase but if you see the periodic positive and negative hills with correct frequency then you have 1,000,000 Hz sampling capability.

 

If the card cannot go beyond 200,000 then you will not see a 200,000 kHz wave on the test panel graph. Just some DC value probably (since signal freq is an integer multiple of our sampling rate, we'll sample the signal at the same level once every five cycles) depending on the instant you started your test panel.

 

But I am not sure about the memory of PCI version of the card. It may be larger.

Or you might have purchased it with a higher memory option. I do not know.

But you should be able to find the information from the hardware documentation that came with the card. You can also search it in the DAQ forum.

 

It is probably per channel, because 2048 samples for 16 channels would be to tiny to practical. And it is float64 data, since it is compatible with DAQmx library.

If the test panel in MAX give you the option to configure the buffer size you can try and see it by yourself. 

S. Eren BALCI
IMESTEK
0 Kudos
Message 7 of 13
(4,261 Views)

Hi ebalci,

 

I did not make the double-check with the function generator yet, but I wondered that the error

 NON-FATAL RUN-TIME ERROR:   "messung.c", line 53, col 21, thread id 0x000017AC:   Function DAQmxReadAnalogF64: (return value == -200279 [0xfffcf1a9]). Measurements: Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.  Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem. Property: DAQmx_Read_RelativeTo Corresponding Value: DAQmx_Val_CurrReadPos  Property: DAQmx_Read_Offset Corresponding Value:    Task Name: ni  Status Code: -200279
also appeas when trying with 100,000 Hz. When changing the red marked values in functions above (expected the -1) from 5E6 to 5E5, the same error appears but earlier. So I can set this values very high but the error will come earlier or later, right?

 

0 Kudos
Message 8 of 13
(4,247 Views)

Hi chemph,

 

Since the cause of the error is probably the card memory getting full.

If you do not empty (read) it with the rate it is getting filled, yes, you'll encounter the error sooner or later.

 

Getting an error does not always mean that you are doing something wrong.

In some applications you can live with the card overwriting the previous values. Well, in some applications it can be fatal.

 

There is a function (DAQmxRegisterEveryNSamplesEvent) in DAQmx for installing a callback that gets called every time N samples is read into the memory.

You might consider using it to be sure you get "informed" as the memory is getting filled.

 

S. Eren BALCI
IMESTEK
0 Kudos
Message 9 of 13
(4,237 Views)

Hi ebalci,

 

I understand what you said but it should be possible to have a continious measurement with four channels and 100,000 Hz with ni PCI-6024E, or not?

I really do not know how to set the red marked parameters in the post before. I am trying since a few days, but I do not find a solution. I think it must have something to do with the 512 samples the pci-card can hold for each channel. 

0 Kudos
Message 10 of 13
(4,214 Views)