/***************************************************************************
	ain_rddiff_ch.c
	Z-World Inc 2003

	This sample program is intended for RabbitNet RN1100 Digital I/O boards

	Description
	===========
	This program demonstrates reading one differential ADC channel
	using two known voltages and constants for that channel.
	It will also continuously display the voltage being monitored.


	Connections
	===========
	You will need two power supplies. For this demonstration,

	1. Connect -0.25 to +0.25 volt power supply 1 to AIN03+ on the controller
		and power supply 2 to AIN03-.
	2.	Connect power supply grounds to GND on the controller.


	Instructions
	============
	1. Adjust power supply (1) on AIN03+ to approximately +0.20 volts.
	2. Adjust power supply (2) on AIN03- to approximately -0.20 volts.
	3. Compile and run this program.

***************************************************************************/
#class auto					// local var storage default to auto

const char vstr[][16] = {
	"0 - 10V\0",
	"0 - 10V\0",
	"0 -  1V\0",
	"+/- 0.25V\0"};

const float vmin[4] = {1.0, 1.0, 0.1, -0.20};
const float vmax[4] = {9.0, 9.0, 0.9, 0.20};


void main ()
{
	auto unsigned int channel, gaincode, handle;
	auto float voltage, volts1, volts2, v1, v2;
	auto char buffer[64], status;
   auto rn_AinData aindata;

	brdInit();                 //initialize controller
   rn_init(RN_PORTS, 1);      //initialize controller RN ports
   if ((handle = rn_device(0000)) == -1)  //device on port 0
   {
   	printf("\n no device found\n");
      exit(0);
   }

   // enable channel for conversions
	channel = 3;
	status = rn_anaInConfig(handle, channel, ENABLE, 0, 0);

	while (1)
	{
		printf("\nReading AIN channel 3 .... ");

		printf("\nVary voltage from -0.25 to +0.25  .... \n\n");

		while (strcmp(buffer,"q") && strcmp(buffer,"Q"))
		{
			status = rn_anaInDiff(handle, channel, &voltage, 1);
			printf("Ch %2d voltage=%.3f \n", channel, voltage);
			printf("\npress enter key to read value again or 'Q' or read another channel\n\n");
			gets(buffer);
		}
	}

}
///////////////////////////////////////////////////////////////////////////

