Wiblocks --- DAC

DAC/DAC.h

00001 #ifndef __DAC_H__
00002 #define __DAC_H__
00003 
00004 extern "C" 
00005 {
00006 #include <float.h>
00007 }
00008 
00013 
00014 #define DAC_TLV5620_NUM_CHS 4
00015 
00016 enum dac_tlv5620_ranges { DAC_REF=0, DAC_REFX2=1 };
00017 enum dac_tlv5620_chs    { DAC_CH_A=0, DAC_CH_B=1, DAC_CH_C=2, DAC_CH_D=3 };
00018 
00022 
00023 class DAC_TLV5620 {
00024  private:
00025   unsigned char _load_pin;
00026   unsigned char _latch_pin;
00027   enum dac_tlv5620_ranges _range[DAC_TLV5620_NUM_CHS];
00028   double _lsb[DAC_TLV5620_NUM_CHS];
00029  public:
00030   static const double _ref = 1.24;             
00031   static const unsigned char _fs_code   = 255; 
00032   static const unsigned int  _num_steps = 256; 
00033   DAC_TLV5620(unsigned char load_pin, unsigned char latch_pin);
00034   char write_data(dac_tlv5620_chs ch, dac_tlv5620_ranges range, 
00035                   unsigned char code);
00036   char set_voltage(dac_tlv5620_chs ch, double v);
00037   void set_range(dac_tlv5620_chs ch, dac_tlv5620_ranges range);
00038   char set_code(dac_tlv5620_chs ch, unsigned char code);
00039 };
00040 
00041 
00046 
00047 #define DAC_TLV5618_NUM_CHS 2
00048 #define DAC_TLV5618_RS_MASK 0x60
00049 
00050 enum dac_tlv5618_rs   { DAC_WRITE_B_AND_BUFFER=0x00, DAC_WRITE_BUFFER=0x10, DAC_WRITE_A_UPDATE_B=0x80 };
00051 enum dac_tlv5618_spds { DAC_SLOW=0x00, DAC_FAST=0x40 };
00052 enum dac_tlv5618_pwrs { DAC_NORMAL=0x00, DAC_POWER_DOWN=0x20 };
00053 
00057 
00058 class DAC_TLV5618 {
00059  private:
00060   unsigned char _cs_pin;
00061   double _lsb;
00062   union {
00063     struct {
00064       unsigned R1 : 1;
00065       unsigned SPD: 1;
00066       unsigned PWR: 1;
00067       unsigned R0 : 1;
00068       unsigned UNUSED: 4;
00069     } control_bits;
00070     unsigned char control_byte;
00071   } _control;
00072  public:
00073   static const double _ref = 1.225;             
00074   static const unsigned int _fs_code   = 4095;  
00075   static const unsigned int  _num_steps = 4096; 
00076   DAC_TLV5618(unsigned char cs_pin, dac_tlv5618_pwrs pwr=DAC_NORMAL, dac_tlv5618_spds spd=DAC_SLOW);
00077   char write_data(dac_tlv5618_rs rs, unsigned int code);
00078   char set_voltage(dac_tlv5618_rs rs, double v);
00079   char set_code(dac_tlv5618_rs rs, unsigned int code);
00080   void set_speed(dac_tlv5618_spds spd);
00081   void set_power_control(dac_tlv5618_pwrs pwr);
00082 
00083 };
00084 
00085 
00086 
00087 #endif