/***************************************************************************
	ad_rddiff_ch.c
	Z-World, 2002

	This sample program is for the LP3500 series controllers.

	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-10 volt power supply 1 to AIN0 on the controller
		and power supply 2 to AIN1.
	2.	Connect power supply grounds to GND on the controller.


	Instructions
	============
	1. Adjust power supply (1) on AIN0 to approximately 9.0 volts.
	2. Adjust power supply (2) on AIN1 to approximately 1.0 volts.
	3. Compile and run this program.
	4. Enter 0 when prompted for AD channel code.

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

const char vstr[][10] = {
	"0 - 20V \0",
	"0 - 10V \0",
	"0 - 5V  \0",
	"0 - 4V  \0",
	"0 - 2.5V\0",
	"0 - 2V  \0",
	"0 - 1V  \0",
	"0 - 1V  \0"};

void printrange()
{
	printf("\ngain_code\tVoltage range\n");
	printf("---------\t-------------\n");
	printf("\t0\t0 - 20 \n");
	printf("\t1\t0 - 10\n");
	printf("\t2\t0 - 5\n");
	printf("\t3\t0 - 4\n");
	printf("\t4\t0 - 2.5\n");
	printf("\t5\t0 - 2\n");
	printf("\t6\t0 - 1.25\n");
	printf("\t7\t0 - 1\n\n");

	printf("\nchannel_code\tInputs\n");
	printf("------------\t-------------\n");
	printf("\t0\t+AIN0 -AIN1\n");
	printf("\t2\t+AIN2 -AIN3\n");
	printf("\t4\t+AIN4 -AIN5\n");
	printf("\t6\t+AIN6 -AIN7\n\n");
}


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

	brdInit();

	while (1)
	{
		printrange();
		printf("\nChoose the AD channel 0,2,4, or 6 .... ");
		gets(buffer);
		channel = atoi(buffer);

		printf("\nVary voltage from 0 -10  .... \n\n");

		while (strcmp(buffer,"q") && strcmp(buffer,"Q"))
		{
			for (gaincode=0; gaincode<=7; gaincode++)
			{
				voltage = anaInDiff(channel, gaincode);
				printf("Ch %2d at gain range %s Volt=%.3f \n", channel, vstr[gaincode], voltage);
			}
			printf("\npress enter key to read value again or 'Q' or read another channel\n\n");
			gets(buffer);
		}
	}

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

