The PicoLog data logger doesn't gain the data in 2 channels

Post your C and C++ discussions here
Post Reply
meguru
Newbie
Posts: 0
Joined: Fri Sep 27, 2013 7:57 am

The PicoLog data logger doesn't gain the data in 2 channels

Post by meguru »

Dear Sir,

I am going to use PicoLog data logger (ADC24)
and also a sample program in SDK.

Now, I'm going to make the device for the following situations.

・streaming
・2 differential channel (1-2, 3-4 channels)
enable 1 channel (no single ended)
enable 3 channel (no single ended)

However, the device can gain only 2 data (1 data each channel)
and cannot do more data (after 2data, 0data).

I am poor at programing .
So, please tell me how I can rewrite the program.

Code: Select all

/****************************************************************************
*
* CollectStreaming
*  this function demonstrates how to use streaming.
*
* In this mode, you can collect data continuously at high speed.
*
* This example writes data to disk...
* don't leave it running too long or it will fill your disk up!
*
* Each call to HRDLGetValues returns the readings since the
* last call
*
****************************************************************************/

void CollectStreaming (void)
{
  int		i;
  int		blockNo;
  FILE *	fp;
  int		nValues;
  short channel;
	short numberOfActiveChannels;
	char strError[80];

  printf("Collect streaming...\n");
  printf("Data is written to disk file (test.csv)\n");
  printf("Press a key to start\n");
  getch();


	for (i = HRDL_ANALOG_IN_CHANNEL_1; i <= g_maxNoOfChannels; i++)
	{
		if(!HRDLSetAnalogInChannel(g_device,
			                         (short)i,
													     g_channelSettings[i].enabled, 
													     g_channelSettings[i].range,
													     g_channelSettings[i].singleEnded))
		{
		  HRDLGetUnitInfo(g_device, strError, (short)80, HRDL_SETTINGS);
		  printf("Error occurred: %s\n\n", strError);
		  return;
		}
	}

  //
  // Collect data at 1 second intervals, with maximum resolution
  //
  HRDLSetInterval(g_device, 61, HRDL_60MS);

  //
  // Start it collecting,
  HRDLRun(g_device, BUFFER_SIZE, HRDL_BM_STREAM);

  while (!HRDLReady(g_device))
    Sleep (1000);

  //
  // From here on, we can get data whenever we want...
  //
  blockNo = 0;
  fp = fopen("test.csv", "w");
  if(!fp)
  {
    printf("Error Opening Outputfile");
    return;
  }

	HRDLGetNumberOfEnabledChannels(g_device, &numberOfActiveChannels);
	numberOfActiveChannels = numberOfActiveChannels + (short)(g_channelSettings[HRDL_DIGITAL_CHANNELS].enabled);
  while (!kbhit())
  { 
	  nValues = HRDLGetValues(g_device, g_values, NULL, BUFFER_SIZE/numberOfActiveChannels);
    printf ("%d values\n", nValues);
		for (i = 0; i < nValues * numberOfActiveChannels;)
			{
		  for(channel = HRDL_DIGITAL_CHANNELS; channel <= HRDL_MAX_ANALOG_CHANNELS; channel++)
      {
			  //
        // Print to channel headers to file
        //
        if(nValues && channel == HRDL_DIGITAL_CHANNELS && g_channelSettings[channel].enabled)
			  {
				  fprintf (fp, "Digital IO (1 2 3 4):,");
			  }
			  else if(nValues && g_channelSettings[channel].enabled)
			  {
				  fprintf (fp, "Channel %d:,", channel);
			  }

        //
        // Print to file the new readings
        //

				if(channel == HRDL_DIGITAL_CHANNELS && g_channelSettings[channel].enabled)
				{
					fprintf (fp, "%d %d %d %d,", 0x01 & (g_values [i]),
						                           0x01 & (g_values [i] >> 0x1),
																			 0x01 & (g_values [i] >> 0x2),
																			 0x01 & (g_values [i] >> 0x3));
					i++;
				}
				else if(g_channelSettings[channel].enabled)
				{
					fprintf (fp, "%f,", AdcToMv (channel, g_values [i]));
					i++;
				}
			}
			if(nValues && g_channelSettings[channel].enabled)
  		  fprintf (fp, "\n");
    }

    if ((blockNo++  % 20) == 0)
      printf ("Press any key to stop\n");

		if(nValues)
		  fprintf (fp, "\n");
    //
    // Wait 100ms before asking again
    //

    Sleep (100);
  }
  fclose (fp);
	HRDLStop(g_device);
  getch ();   
}

/****************************************************************************
*
* SetAnalogChannels
*  this function demonstrates how to detect available input range and set it.
*  We will first check to see if a channel is available, then check what ranges
*  are available and then check to see if differential mode is supported for thet
*  channel.
*
****************************************************************************/
void SetAnalogChannels(void)
{ 
  int channel;
  short range;
  short available;

  //
  // Iterate through the channels on the device and if one is avilable give
  // user the option of using one;
  //
  // A channel may not be available if:
  //
  // a) it is not available on the current device,
  // b) the input is a secondary differential input and is already in use for a differential channel or
  // c) the input is a primary differential input and cannot used for a differential channel because the
  //    secondary input of the pair is already in use for a single ended channel.
  //
  // Primary inputs for differential pairs are odd channel numbers eg  1, 3, 5, etc. Their corresponding
  // secondary numbers are primary channel number + 1 eg 1 and 2, 3 and 4, etc.
  //
  // You should firstly make sure that the channel is available on the current unit
  // and secondly ensure that the input, or both inputs for a differential channel,
  // are not already in use for another channel.


  for (channel = HRDL_ANALOG_IN_CHANNEL_1; channel <= g_maxNoOfChannels; channel++)
    printf("%d - Channel %d\n", channel, channel); 

  //
  // Let the user select the channel

  printf("select a channel..\n");
  channel = 0;
  do {
    scanf("%d", &channel);   
  } while (channel < HRDL_ANALOG_IN_CHANNEL_1 || channel > g_maxNoOfChannels);

  printf("enable the channel? (Y\\N)\n\n");  
  g_channelSettings[channel].enabled = (short) toupper(getch()) == 'Y';

  //
  // Disable the channel if the user does not require it

  if(!g_channelSettings[channel].enabled)
  {
    printf("Channel %d disabled\n\n", channel);
    HRDLSetAnalogInChannel(g_device, (short)channel, 0, HRDL_1250_MV, 1);
    return;
  }          

  //
  // Iterate through all the input ranges, if the range is available on
  // the current device, give the user the option of using it.

  available = 0;
  for (range = 0; range < HRDL_MAX_RANGES; range++)
  {
    if (HRDLSetAnalogInChannel(g_device, (short)channel, 1, range, 1))
    {
      printf("%d - %dmV\n", range, (int)(2500/inputRangeV[range]));    
      available = 1;
    }
  }

  if(!available)
  {
    printf("Channel is not available for use:\n ");
    if((channel & 0x01) && g_channelSettings[channel + 1].enabled )  // odd channels
    {
      printf("The channel cannot be enabled because it is a primary differential channel  \
             and its corresponding secondary channel is already in use for a single ended measurement\n");           
    }
    else if (g_channelSettings[channel - 1].enabled)
    {
      printf("The channel cannot be enabled because it is a secondary differential channel  \
             and is already in use for a differential measurement\n");
    }
    else
    {
      printf("This channel cannot be enabled because it is not availble on this Pico HRDL variant\n");
    }                                         
    return;
  }

  //
  // Let the user select the range
  printf("Select Range...\n");
  do {
    g_channelSettings[channel].range = (short) getch() - '0';
  } while (!HRDLSetAnalogInChannel(g_device, (short)channel, 1, g_channelSettings[channel].range, 1));

  //
  // See if it possible to use this channel as differential.
  // 
  // It may not be used as differential if this input is a secondary differential input
  // or this input is a primary differential input and the coresponding secondary input
  // is already in use for a single ended channel.

  if (HRDLSetAnalogInChannel(g_device, (short)channel, 1, g_channelSettings[channel].range, 0))
  {
    printf("single ended? (Y\\N)");  
    g_channelSettings[channel].singleEnded = (short) toupper(getch()) == 'Y';
  }
  else
  {
    g_channelSettings[channel].singleEnded = 1;           
  }

  HRDLSetAnalogInChannel(g_device, (short)channel, g_channelSettings[channel].range, 1, g_channelSettings[channel].singleEnded);

  // Let the user know what they got
  printf("\nChannel %d, %dmV range, %s\n\n", channel, (int)(2500 / inputRangeV[g_channelSettings[channel].range]), g_channelSettings[channel].singleEnded ? "single endeded" : "differential");

}
meguru

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: The PicoLog data logger doesn't gain the data in 2 chan

Post by Martyn »

Are you saying that you have run the sample code exactly as supplied ?

Have you selected option A to set up the channels and then option S to start Streaming ?

Have you tried one of the other modes, possibly immediate block ?

Does the program sit there running until you press a key ?


If you are just interested in collecting streamed data I would suggest that you go through the code and remove all the unwanted sections, then clean out the streaming section to remove the digital parts. this should leave you with a smaller piece of code that makes it easier to understand, follow and single step debug.
Martyn
Technical Support Manager

Post Reply