/*
   IOE_MUX.C
   
   BL11xx/Little Giant with IOE-MUX or IOE-A/D 

   Uses the following functions:
        
   int exp_init(int ppia, int ppib, int ppicu, int ppicl);
   int mux_ch (int chan);
 
   This example shows the use of the four channel multiplexer on
   the IOE-MUX and IOE-A/D.  The four channels are changed and
   then sampled by channel 0 of the Little Giant's A/D in unipolar
   mode. The output is displayed in the STDIO window.  If you have
   the DAC installed you can move the output between the different
   mux channels and observe the output.

   Simply apply an analog voltage to CH0H of the Little Giant and
   the IOE-MUX will read the value and display the corresponding
   number of counts in the stdio window.
   
   After displaying the mux channels the PPI ports B and C are read
   and displayed as well as the RDTTL (not available in the IOE-MUX.)
*/

main()
{
   int j, k;
   long l;

   exp_init(0, -1, -1, -1);  // port A must be output, all others can be I/O

   // if you have a DAC you can use the output in this test
//	k = 200;
//	wdac (k);

   while(1)
   {
   	hitwd();

//		k += 10;
//		wdac (k);

      for (j = 0; j < 4; ++j)
      {
      	hitwd();
         mux_ch (j);                                  // set to channel j 
         for (l = 200L; --l;);                        // wait for settle 

         // change the ad_rd(8) call to match the converter on your system 
         // use either ad_rd10() or ad_rd12(8)
         
         printf ("Mux Channel %d = %x\n", j, (ad_rd10(8) >> 2));
      }
      for (l = 20000L;--l;) hitwd();                // pause 

      printf ("PPIDB inputs = %x\n", inport(PPIB));
      printf ("PPIDC inputs = %x\n", inport(PPIC)); 		// opto isolated inputs 
      printf ("RDTTL inputs = %x\n\n", inport(RDTTL)); 	// TTL inputs 
      for (l = 20000L;--l;) hitwd();               		// pause 
   }
}