00001 /* 00002 * rb8509_adc12.h - 8-channel 12-bit ADC (RB8509). 00003 * 00004 * This file is part of the Rulbus Device Class Library (RDCL). 00005 * 00006 * Copyright (C) 2003-2004, Leiden University. 00007 * 00008 * This library is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * The library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with mngdriver; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * $Id: rb8509_adc12.h 2 2004-10-12 11:54:15Z moene $ 00023 */ 00024 00025 #ifndef __RB8509_Adc12_ADC12_H 00026 #define __RB8509_Adc12_ADC12_H 00027 00028 #ifndef __RULBUSDEVICE_H 00029 #include "RulbusDevice.h" // for class RulbusDevice 00030 #endif 00031 00032 namespace Rulbus 00033 { 00034 DECLARE_CLASS( RB8509_Adc12 ); // the 12-bit ADC class type 00035 00036 /* * 00037 * \example name.cpp 00038 * This is an example that shows ... . 00039 */ 00040 00193 class RB8509_Adc12 : public RulbusDevice 00194 { 00195 public: // public methods 00196 typedef Int Value; 00197 00200 00201 RB8509_Adc12( 00202 NameCref aName, 00203 Addr aAddr = DEF_ADDR, 00204 Rack aRack = DEF_RACK, 00205 bool aBipolarFlag = DEF_BIP, 00206 Real aVoltPerBit = DEF_VPB, 00207 bool aExtTrigInpFlag = DEF_ETI 00208 ); 00209 00210 ~RB8509_Adc12(); 00211 00215 00216 int channel() const; 00217 int gain() const; 00218 00219 Volt voltage(); 00220 Value value() ; 00221 Value result(); 00222 Value rawresult(); 00223 00224 bool hasExtTriggerInput() const; 00225 00226 bool extTriggerLevel() const; 00227 00228 bool isEnabledExtTrigger() const; 00229 bool isEnabledMultiplexer() const; 00230 bool isEnabledInterrupt() const; 00231 00232 bool isBusyAdc() const; 00233 bool isReady() const; 00234 bool isBipolar() const; 00235 bool isPendingInterrupt() const; 00236 00237 Real voltperbit() const; 00238 00242 00243 bool isValidChannel( int aChannel ) const; 00244 bool isValidGain ( int aGain ) const; 00245 00249 00250 void setChannel( int aChannel ); 00251 00252 void setGain ( int aGain ); 00253 void autoscale (); 00254 00255 void convert (); 00256 00257 bool enableMultiplexer( bool enable = true ); 00258 bool enableExtTrigger ( bool enable = true ); 00259 bool enableInterrupt ( bool enable = true ); 00260 00262 00263 protected: // protected methods 00266 00267 RB8509_Adc12(); 00268 RB8509_Adc12( RB8509_Adc12Cref rhs ); 00269 RB8509_Adc12Ref operator= ( RB8509_Adc12Cref rhs ); 00270 00274 00275 void checkChannel ( int aChannel ) const; 00276 void checkGain ( int aGain ) const; 00277 00279 00280 public: // public data 00283 00284 static const Addr DEF_ADDR = 0xC0; 00285 // static const Rack DEF_RACK = 0; ///< default rack 00286 static const int DEF_GAIN = 1; 00287 static const int DEF_CHAN = 0; 00288 static const bool DEF_BIP = true; 00289 static const Real DEF_VPB /* = 5e-3 */; 00290 static const bool DEF_ETI = false; 00291 00295 00296 static const int LIM_MINCHAN = 0; 00297 static const int LIM_MAXCHAN = 7; 00298 00299 static const int LIM_MINGAIN = 1; 00300 static const int LIM_MAXGAIN = 8; 00301 00302 static const Real LIM_MINVPB /* = 1e-3 */ ; 00303 static const Real LIM_MAXVPB /* = 10e-3 */ ; 00304 00305 static const int LIM_TIMOUT = 1000; 00306 static const Value LIM_MINVAL = 0x0000; 00307 static const Value LIM_MAXVAL = 0x0FFF; 00308 static const Value LIM_BIPVAL = 0x0800; 00309 00311 00312 private: // private data 00315 00316 Byte theControlRegister; 00317 bool theExtTrigInpFlag; 00318 bool theBipolarFlag; 00319 Real theVoltPerBit; 00320 00324 00325 static const int OFF_ADCLSB = 0; 00326 static const int OFF_CONTROL = 0; 00327 static const int OFF_STATUS = 1; 00328 static const int OFF_CONVERT = 1; 00329 static const int ADR_WIDTH = OFF_CONVERT + 1; 00330 00334 00335 static const int MSK_CTLCHAN = 0x07; 00336 static const int MSK_CTLMPLX = 0x08; 00337 static const int MSK_CTLGAIN = 0x30; 00338 static const int MSK_CTLTRIG = 0x40; 00339 static const int MSK_CTLINTR = 0x80; 00340 00341 static const int MSK_STSBSY = 0x10; 00342 static const int MSK_STSEOC = 0x20; 00343 static const int MSK_STSINTR = 0x40; 00344 static const int MSK_STSTRIG = 0x80; 00345 static const int MSK_VALMSN = 0x0F; 00346 00347 static const int SHL_CTLCHAN = 0; 00348 static const int SHL_CTLGAIN = 4; 00349 00351 }; 00352 00354 00359 inline bool RB8509_Adc12::hasExtTriggerInput() const 00360 { 00361 return theExtTrigInpFlag; 00362 } 00363 00368 inline bool RB8509_Adc12::isBipolar() const 00369 { 00370 return theBipolarFlag; 00371 } 00372 00377 inline Real RB8509_Adc12::voltperbit() const 00378 { 00379 return theVoltPerBit; 00380 } 00381 00386 inline bool RB8509_Adc12::isValidChannel( int aChannel ) const 00387 { 00388 return aChannel >= LIM_MINCHAN && 00389 aChannel <= LIM_MAXCHAN ; 00390 } 00391 00396 inline bool RB8509_Adc12::isValidGain( int aGain ) const 00397 { 00398 return aGain == 1 || 00399 aGain == 2 || 00400 aGain == 4 || 00401 aGain == 8 ; 00402 } 00403 00408 inline RB8509_Adc12Ref to_rb8509( RulbusDevicePtr p ) 00409 { 00410 return PROXY_CAST<RB8509_Adc12Ref>( *p ); 00411 } 00412 00417 inline RB8509_Adc12Ptr to_rb8509_ptr( RulbusDevicePtr p ) 00418 { 00419 return PROXY_CAST<RB8509_Adc12Ptr>( p ); 00420 } 00421 00422 } // namespace Rulbus 00423 00424 #endif // __RB8509_Adc12_ADC12_H 00425 00426 /* 00427 * end of file 00428 */ 00429