ADC11/12 What is the correct way to collect streamed data

Post general discussions on using our drivers to write your own software here
Post Reply
Guest

ADC11/12 What is the correct way to collect streamed data

Post by Guest »

Hi

I am trying to collect streamed data from my ADC11/12 by calling the functions in the include file for Delphi, actually I have added some extra functions to the includefile to make it work correctly when using USB communication, as they were missing!

Here are the missing functions and definitions:

type
method = 0..2;

const
BM_SINGLE = 0;
BM_WINDOW = 1;
BM_STREAM = 2;

procedure adc11_run
(no_of_values : longint; {number of samples to collect}
method : word); {method BM_SINGLE (0), BM_WINDOW (1), BM_STREAM (2)}
{$IFDEF WIN32} stdcall; external 'ADC1132.dll'; {$ELSE} far; external 'ADC1116'; {$ENDIF}

function adc11_is_streaming : boolean;
{$IFDEF WIN32} stdcall; external 'ADC1132.dll'; {$ELSE} far; external 'ADC1116'; {$ENDIF}

function adc11_ready : boolean;
{$IFDEF WIN32} stdcall; external 'ADC1132.dll'; {$ELSE} far; external 'ADC1116'; {$ENDIF}

Now to my question!

What is the correct way to collect data from a stream?

Say I want to collect 100 samples with a samplerate of 0.1s from one channel:

begin
n:=Channels_Count(channels);
No_Channels:=n;
max_values:=100;
SampleRate:=0.1*1000000; //times 1000000 to get microseconds!
TargetTime:=SampleRate*max_values*No_Channels;
us := adc11_set_interval (TargetTime, max_values*(n), channels, n);

//After having set the interval information i start collecting the data:

adc11_run(max_values,0);

repeat
StreamReady:=adc11_ready; //I wait until the data is ready
until StreamReady ;

ok := adc11_get_times_and_values (mytimes, myvalues, max_values);
//and then I process the data
end;

Say I want to collect 100 samples in 10 intervals with a samplerate of 0.1s from one channel!

How do I collect the data?

I start by setting the intervalinformation just as above, and then i start collecting the data:

begin
division:=10;
n:=Channels_Count(channels);
No_Channels:=n;
max_values:=100;
SampleRate:=0.1*1000000; //times 1000000 to get microseconds!
TargetTime:=SampleRate*max_values*No_Channels;
us := adc11_set_interval (TargetTime, max_values*(n), channels, n);

//After having set the interval information i start collecting the data:


adc11_run(Trunc(max_values/division),1);

//1 is for BM_WiNDOW collect a sequence of overlapping blocks

//this time I start collecting the data in sequences

for j :=1 to division do //division tells me how many sequences I want
begin

//As I see it, I still have to wait until the data is ready!:

repeat
StreamReady:=adc11_ready; //I wait until the data is ready
until StreamReady ;

ok := adc11_get_times_and_values (mytimes, myvalues, Trunc(max_values/division));

//and then I process the data
end;


The code described above works fine but I don't get the Streamready until all of the samples are collected so what is the difference besides the fact that the timevalues is reset to zero for each interval?

And if this is normal, what is the meaning with the third collection method?
BM_STREAM that collects a continous stream of data, and how should it be used? should I still wait for stream ready?

I hope you are able to clearify this to me.

Regards Palle Koch

User avatar
markspencer
Site Admin
Site Admin
Posts: 598
Joined: Wed May 07, 2003 9:45 am

Post by markspencer »

Hi,

This is the code used to do streaming in C, you should be able to transpose this into Delphi. The streaming will only work with the USB adaptor.

To see if you can use strreaming use the function:

adc11_is_streaming();

Code: Select all

  actual = adc11_set_interval (BUFFER_SIZE * 1000, BUFFER_SIZE, channels, 1);

  /* Start it collecting,
   *  then wait for trigger event
   */
  adc11_run (BUFFER_SIZE, BM_STREAM);
  while (!adc11_ready ())
    {
    Sleep (100);
    }

  /* From here on, we can get data whenever we want...
   */
  block_no = 0;
  fp = fopen ("test.out", "w");
  while (!kbhit ())
    {
    no_of_values = adc11_get_times_and_values (times, values, BUFFER_SIZE);
    printf ("%d values\n", no_of_values);

    if (block_no++ > 20)
      {
      block_no = 0;
      printf ("Press any key to stop\n");
      }

    /* Print out the first 10 readings
     */
    for (i = 0; i < no_of_values; i++)
      {
      fprintf (fp, "%8ld\t%d\n", times [i], adc_to_mv (values [i]));
      }

    /* Wait 100ms before asking again
     */
    Sleep (100);
    }
  fclose (fp);

  adc11_stop ();
I hope this helps you. For a full description of the above code please see our C console example, and the help manual for a description of the functions.

Best regards,
Regards,

Mark Spencer

Post Reply