#use "default.h"

#if !((BOARD_TYPE==LITTLE_GIANT) || (BOARD_TYPE==TINY_GIANT))
#fatal "This program only runs on the BL11xx/Little Giant or the Tiny Giant."
#endif

/*
  DASAMPL2.C - DAC PLCBus Expansion board sample program #2.
               For the BL11xx/Little Giant or Tiny Giant.

     This program simply increments the voltage output on both 
  DAC output channels.  The board written to is the one one with 
  the highest logical address (0-63) found on the PLCBus.  To watch
  the output increment, connect a voltage meter to either output.
  Alternatively, you can place an LED in series with a 1K resistor 
  between either output and ground and watch the intensity gradually
  increase as the voltage rises.

  Setup - Software (see the Dynamic C User's Manual for more details
                    on libraries)

  1. If you havent done so already, copy the PBUS_LG.LIB (for BL11xx/Little
     Giant) or PBUS_TG.LIB (for Tiny Giant) library to your dynamic C 
     home directory.  These libraries are located in the PLCBUS directory
     of the Example Applications Diskette.

  2. Add a line to your LIB.DIR file to include this library.


  Setup - Hardware

  1. Connect DAC board to BL11xx/Little Giant or Tiny Giant with appropriate
     cable.  See Chapter 2 of the PLCBus Expansion Boards Technical
     Manual for more details.

  2. Connect voltage meter or LED/resistor network to either output.

  3. Make sure J1 and J2 are jumpered to connect pins 2-3.  This
     configures both channels for voltage output.

  4. Apply power to the BL11xx/Little Giant or Tiny Giant.

  5. Apply +24V power to the DAC board at wago H1 pin 8 from left.



  DAC wago H1 connections (from left)
  -----------------------------------
  1 - Ch2 output      5 - Vcc (+5v)
  2 - Gnd             6 - V-
  3 - Ch1 output      7 - V+ (+15v)
  4 - Gnd             8 - +24VI  

*/


main()  
{ int i,logical_addr,plcbus_addr,da_addr,hi_addr,ifail,vfail;
  float adv,exp,err,offset,ma; 

	Reset_PBus();           // reset the plcbus
	Reset_PBus_Wait();      // wait for reset to end   

	if(sysclock() > 0x1e00)
		Reset_PBus_Wait();   // for boards faster than 9 Mhz
									// double wait.         
  /* Locate D/A Nodes - save addr of last found 
  --------------------------------------------- */
  for(logical_addr=0;logical_addr<64;logical_addr++)
  {  plcbus_addr = DAC_Board_Addr(logical_addr);
     if(Poll_PBus_Node(plcbus_addr))
     { hi_addr = plcbus_addr;
      }
    hitwd();
   }

   PBus12_Addr(hi_addr);  /* must set board address on PLCBus before using */
   Init_DAC();           
   DAC_On();              /* turn on high-side switch if installed */

   /* Increment Voltages on DAC Channels out 1 and 2
   ------------------------------------------------- */
   while(1)
   {
   	for (i=0;i<4097;i+=10)
     { Set_DAC1(i);            /* Set DAC output #1 */
       Set_DAC2(i);            /* Set DAC output #2 */
       hitwd();
      }
   }
}                    

