
/*  DB-889D DEMO3 program                              */
/*  use A-822PGL Multi-function card                   */
/*      Base Address : 0x220                           */
/*      Single-end Analog input channel #0             */
/*      Gain=1 Bipolar mode                            */

/*  Cascaded Two DB-889D                               */

/*  DB-889D #1 Analog output channel set in 0 (JP16)   */
/*  DB-889D #1 CJC output set in X (JP17)              */

/*  DB-889D #2 Analog output channel set in 1 (JP16)   */
/*  DB-889D #2 CJC output set in 8 (JP17)              */



#include <stdio.h>
#include <conio.h>
#include "A822.h"

void main(void)
{
 int ad_data;
 float ad_vol,temp;

  /*===================  init. A-822 & DB-889D ===========*/

 A822_Initialize(0,0x220,-1,-1);   /* A-822 Base address 0x220*/

 /*====================  Init DB-889D #1 ================*/


 A822_AD_SetChGainMode(0,0,1);     /* Channel =0 , Gain=1, Polling trigger */
 A822_DO(0x0100);                  /* Set DB-889D Gain=1 , Channel = 0     */
				   /* set data= 00010000                   */
				   /* D0~D3 set channel                    */
				   /* D4~D6 set Gain                       */


  /*=============== Reading DB-889D #1 Channel 0 =======================*/

 ad_data=A822_AD_PollingVar();     /* Reading data */

 ad_vol=(float)((ad_data-2048)*5/2048);  /* Conversion data to Voltage */
					  /* DB-889D gain=1           */
					  /*      input range=-5 ~ +5V*/

 printf("DB-889D #1 CH0  Voltage = %6.4f V\n",ad_vol );


 printf("---------- Press any key to countiune\n");
 getch();

  /*=============== Init. DB-889D #1 Channel 8   Gain: 10  ===========*/

 A822_AD_SetChGainMode(0,0,1);
 A822_DO(0x0308);                 /* setting data = 0011 1000   */
				  /*                ---- ----   */
				  /*  DB-889D      Gain   Channel*/

 delay(15);                       /* wait Amp. Settling time  */
				  /* Ref. DB-889D User's Manual */



  /*================= Reading DB-889D #1 Channel 8 Data ================*/

  ad_data=A822_AD_PollingVar();
  ad_vol=(float)((ad_data-2048)*0.5/22048);

				  /* DB-889D Gain=10               */
				  /* input range = -0.5 V ~ +0.5 V */

  printf("DB-889D #1 CH8 Voltage = %6.5f V \n",ad_vol);

  printf(" -------- press any key to countiune \n");
  getch();


  /*================= Init DB-889D #2 Channel 0 ========================*/

  A822_AD_SetChGainMode(1,0,1);    /*  Change A-822 Channel to CH1      */
				   /* Because:DB-889D #2 Analog output  */
					/*      channel set in 1      */


  A822_DO(0x0100);                 /* Setting DB-889D #2                */
					/*	Gain=1  Channel =0       */

  /*================== Reading DB-889D #2 Channel 0 =====================*/

  ad_data=A822_AD_PollingVar();
  ad_vol=(float)((ad_data-2048)*5/20448);

  printf(" DB-889D #2 CH0 Voltage= %6.4f V\n",ad_vol);


  /*=================  Reading DB-889D #2 CJC data ====================*/

  A822_AD_SetChGainMode(8,0,1);     /* Change A822 channel 8  */

  ad_data=A822_AD_PollingVar();           /* Reading data     */
  ad_vol=(float)((ad_data-2048)*5/2048);
  temp=ad_vol*1000/24.4;                   /* Conversion data to deg C */

  printf(" DB-889D #2 CJC Temp = %3.1f deg C \n",temp);



 }

