home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
-
- FILE
- dac2.c - driver for Metrabyte DAC-02 digital to analog i/o board
-
- ROUTINES
- da_init - initialize D/A
- da_limits - return output limits of D/A
- da_write - D/A output
-
- REMARKS
- The DAC-02 is a 2-channel 12-bit DAC using 8 consequetive i/o
- addresses. Data has to be "left-justified" and sent out in 2 bytes,
- least significant byte first. One can also use the 16-bit i/o
- instructions, but we will not do so here.
-
- LAST UPDATE
- 1 May 1985
-
- Copyright (c) 1985 D.M. Auslander and C.H. Tham
-
- ***********************************************************************/
-
- /***********************************************************************
- I M P O R T S
- ***********************************************************************/
-
- #include <stdio.h>
-
- #include "envir.h" /* environment declarations */
- #include "inout.h" /* i/o mapping macros */
- #include "dac2.h" /* exported declarations for this module */
-
-
- /***********************************************************************
- P R I V A T E D A T A
- ***********************************************************************/
-
- #define DABASE 0x330 /* base address of D/A */
-
- #define DAMIN -2048 /* min. output value accepted */
- #define DAMAX 2047 /* max. output value accepted */
-
- #define DALO0 DABASE /* D/A 0 low byte */
- #define DAHI0 DABASE+1 /* D/A 0 high byte */
- #define DALO1 DABASE+2 /* D/A 1 low byte */
- #define DAHI1 DABASE+3 /* D/A 1 high byte */
-
-
- /***********************************************************************
- E N T R Y R O U T I N E S
- ***********************************************************************/
-
- /*----------------------------------------------------------------------
- PROCEDURE
- DA_LIMITS - returns D/A output limits.
-
- SYNOPSIS
- void da_limits(lo, hi)
- int *lo, *hi;
-
- PARAMETERS
- lo - pointer to low limit
- hi - pointer to high limit
-
- REMARKS
- The limits are returned by means of side effects. This routine
- enables other routines to perform limit checks in a more device
- independent manner.
-
- LAST UPDATE
- 1 May 1985
- ----------------------------------------------------------------------*/
-
- void da_limits(lo, hi)
- int *lo, *hi;
- {
-
- *lo = DAMIN;
- *hi = DAMAX;
-
- }
-
-
-
- /*----------------------------------------------------------------------
- FUNCTION
- DA_WRITE - write output to D/A
-
- SYNOPSIS
- int da_write(chan, value)
- int chan, value;
-
- PARAMETERS
- chan - channel number (0 or 1)
- value - output value
-
- RETURNS
- 0 if all is well, -1 if error
-
- REMARKS
- The channel number is checked, but no range checking is performed on
- the output value in the interest of speed. The calling routine is
- responsible for such checks - that's what da_limits() is for.
-
- The DAC uses an offset binary format where 0 will put out -10 volts
- and 4095 will put out +10 volts.
-
- The output value is scaled such that:
-
- -2048 ---> -10V
- 0 ---> 0V
- +2047 ---> +10V
-
- LAST UPDATE
- 1 May 1985
- ----------------------------------------------------------------------*/
-
- int da_write(chan, value)
- int chan, value;
- {
- int rval; /* error indication return value */
-
-
- value = 0x800 + value; /* convert to offset binary */
-
- switch (chan)
- {
- case 0: /* channel 0 */
-
- out(DALO0, value << 4); /* send low byte */
- out(DAHI0, value >> 4); /* send high byte */
-
- rval = 0; /* indicate all O.K. */
-
- break;
-
- case 1: /* channel 1 */
-
- out(DALO1, value << 4);
- out(DAHI1, value >> 4);
-
- rval = 0;
-
- break;
-
- default: /* bad channel number */
-
- rval = -1;
- break;
- }
-
- return(rval);
- }
-
-
-
- /***********************************************************************
- I N I T I A L I Z A T I O N R O U T I N E
- ***********************************************************************/
-
- /*----------------------------------------------------------------------
- PROCEDURE
- DA_INIT - initialize D/A
-
- SYNOPSIS
- void da_init()
-
- REMARKS
- Initialzie both output channels to 0 volts.
-
- LAST UPDATE
- 1 May 1985
- ----------------------------------------------------------------------*/
-
- void da_init()
- {
-
- out(DALO0, 0x00); /* zero channel 0 */
- out(DAHI0, 0x80);
-
- out(DALO1, 0x00); /* zero channel 1 */
- out(DAHI1, 0x80);
-
- }
-