Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

ppmc_dac.c

Go to the documentation of this file.
00001 //ppmc dac functions
00002 
00003 #include "ppmc.h"
00004 
00005 
00006 /*
00007 VoltToCount(double volts)  converts a voltage to a
00008 number of counts to output to the dac
00009 
00010   output to DAC word works like:
00011 
00012   0xFFFF -> +10 V
00013   0x8000 ->   0 V
00014   0x0000 -> -10 V
00015   */
00016 
00017 
00018 __inline unsigned short VoltToCounts(double volts)
00019 {
00020         long nCounts;
00021         nCounts = (long) (((volts / 10.0) * 0x7FFF)+0x8000);
00022 
00023         if (nCounts > 0xffff)
00024     {
00025       nCounts = 0xffff;
00026     }
00027         if (nCounts < 0 )
00028     {
00029       nCounts = 0;
00030     }
00031         return (unsigned short)nCounts;
00032 }
00033 
00034 int RawDAC(int nAxis, double volts)
00035 {
00036   
00037 
00038   if ( (nAxis > PPMC_MAX_AXIS) || (nAxis < 0) )        /* is axis within range? */
00039     return -1;
00040 
00041   /* convert -10.0 -> 0,0 to 0x8000 10 -> 0xFFFF */
00042   
00043   if (nAxis <=3)
00044    {
00045     SelWrt16(DAC_0 + (nAxis << 1), VoltToCounts(volts));
00046         SelWrt(DAC_WRITE_0, 0);
00047    }
00048   else {
00049     SelWrt16(DAC_4 + ((nAxis-4) << 1), VoltToCounts(volts));
00050         SelWrt(DAC_WRITE_1, 0);
00051   }
00052         
00053         
00054   return 0;
00055 }
00056 
00057 short DACInit(void)
00058 {
00059         SelWrt(DAC_WRITE_0,0);    // reset strobe
00060         SelWrt(DAC_MODE_0,0);     // sel strobe to INTR/ line
00061         return 0;
00062 }
00063 
00064 short DACQuit(void)
00065 {
00066            return DACInit();  //init sets all outputs to zero
00067 }
00068 int ppmcDacNum(void)
00069 {
00070         return PPMC_MAX_AXIS;
00071 }
00072 
00073 int ppmcDacWrite(int dac, double volts)
00074 {
00075   return RawDAC(dac, volts);
00076 }
00077 
00078 int ppmcDacWriteAll(int max, double * volts)
00079 {
00080         int t;
00081   int smax;
00082  
00083   /* clip smax to max supported-- if they want more, ignore */
00084   if (max > PPMC_MAX_AXIS) {
00085     smax = PPMC_MAX_AXIS;
00086   }
00087   else {
00088     smax = max;
00089   }
00090 #ifndef PPMC_8_AXIS
00091   //take advantage of auto increment of address pointer in ppmc
00092         SelAddr(DAC_0);
00093         for (t = 0; t < smax; t++)
00094         {
00095   /*      printf(" dac channel %d volts %12.4f   digital # %d\n",
00096           t,volts[t],VoltToCounts(volts[t]));  */
00097                 WriteData16(VoltToCounts(volts[t]));
00098     }
00099         /*      printf("\n");  */
00100 #else
00101         SelAddr(DAC_0);
00102         if(smax<=4)
00103         {
00104            for (t = 0; t < smax; t++)
00105              {
00106                 WriteData16(VoltToCounts(volts[t]));
00107              }
00108            return 0;
00109         }
00110         else
00111         {
00112           for (t = 0; t < 4; t++)
00113             {
00114               WriteData16(VoltToCounts(volts[t]));
00115             }
00116           SelAddr(DAC_1);
00117           for (t = 4; t < smax; t++)
00118             {
00119                 WriteData16(VoltToCounts(volts[t]));
00120             }
00121     }
00122 #endif
00123   return 0;
00124 }
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 

Generated on Sun Dec 2 15:27:41 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001