00001 /* 00002 * rb8905_adc12.h - high speed 12-bit ADC (RB8905). 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: rb8905_adc12.h 2 2004-10-12 11:54:15Z moene $ 00023 */ 00024 00025 #ifndef __RB8905_ADC12_H 00026 #define __RB8905_ADC12_H 00027 00028 #ifndef __RULBUSDEVICE_H 00029 #include "RulbusDevice.h" // for class RulbusDevice 00030 #endif 00031 00032 namespace Rulbus 00033 { 00034 DECLARE_CLASS( RB8905_Adc12 ); // the 12-bit ADC class type 00035 00036 /* * 00037 * \example name.cpp 00038 * This is an example that shows ... . 00039 */ 00040 00251 class RB8905_Adc12 : public RulbusDevice 00252 { 00253 public: // public methods 00254 typedef Int Value; 00255 00258 00259 RB8905_Adc12( 00260 NameCref aName, 00261 Addr aAddr = DEF_ADDR, 00262 Rack aRack = DEF_RACK, 00263 Real aVoltPerBit = DEF_VPB 00264 ); 00265 00266 ~RB8905_Adc12(); 00267 00271 00272 void arm (); 00273 bool isReady () const; 00274 00275 int readVoltage( Volt32* pVoltage, int nelem ); 00276 int readValue ( Int16* pValue , int nelem ); 00277 Value getValue (); 00278 Value getRawValue(); 00279 00283 00284 bool isFastMode () const; 00285 bool isUnipolarMode () const; 00286 bool isEnabledInterrupt() const; 00287 00288 int bufferCapacity () const; 00289 int jmp3BufferCapacity() const; 00290 00291 Real voltperbit () const; 00292 Volt voltageSpan () const; 00293 Volt offsetVoltage () const; 00294 Volt minInputVoltage () const; 00295 Volt maxInputVoltage () const; 00296 00300 00301 void setFastMode (); 00302 void setNormalMode (); 00303 00304 void setBipolarMode (); 00305 void setUnipolarMode (); 00306 00307 bool enableInterrupt ( bool enable = true ); 00308 00309 void setBufferCapacity ( int nelem = CON_JMP3 ); 00310 00312 00313 protected: // protected methods 00316 00317 RB8905_Adc12(); 00318 RB8905_Adc12( RB8905_Adc12Cref rhs ); 00319 RB8905_Adc12Ref operator= ( RB8905_Adc12Cref rhs ); 00320 00324 00325 void setReadMode (); 00326 void setWriteMode (); 00327 00331 00332 void clearAddress (); 00333 00334 int elemSize () const; 00335 int bufferSize () const; 00336 void setBufferSize ( int aSize = CON_JMP3 ); 00337 void setBufferCode ( int aCode ); 00338 00339 int jmp3BufferSize() const; 00340 int detectJmp3BufferSize(); 00341 00342 void checkRead ( int nelem ); 00343 void waitRelais (); 00344 00346 00347 public: // public data 00350 00351 static const Addr DEF_ADDR = 0xBC; 00352 static const float DEF_VPB /* = 10.0/4095.0 */; // volt per bit (10.0 V full scale) 00353 static const int DEF_SAMPLES = 256; 00354 00358 00359 static const int CON_JMP3 = 0; 00360 static const int CON_TRELAIS = 20; 00361 00363 00364 private: // private data 00367 00368 Byte theControlRegister; 00369 Real theVoltPerBit; 00370 int theJmp3BufferSize; 00371 int theBufferCapacity; 00372 00376 00377 static const int OFF_CTL = 0; 00378 static const int OFF_ADC = 0; 00379 static const int OFF_STS = 1; 00380 static const int ADR_WIDTH = OFF_STS + 1; 00381 00385 00386 static const Value LIM_MINVAL8 = 0x000; 00387 static const Value LIM_MAXVAL8 = 0x0FF; 00388 00389 static const Value LIM_MINVAL12 = 0x000; 00390 static const Value LIM_MAXVAL12 = 0xFFF; 00391 00392 static const int LIM_MINJMP3SIZE = 2; 00393 static const int LIM_MAXJMP3SIZE = 256; 00394 00395 static const int LIM_MINBUFSIZE = 512; 00396 static const int LIM_MAXBUFSIZE = 32768; 00397 00401 00402 static const int MSK_CTLBSIZE = 0x07; 00403 static const int MSK_CTLREAD = 0x08; 00404 static const int MSK_CTLFAST = 0x10; 00405 static const int MSK_CTLCLEAR = 0x20; 00406 static const int MSK_CTLINTR = 0x40; 00407 static const int MSK_CTLUNIP = 0x80; 00408 00409 static const int MSK_STSREADY = 0x80; 00410 00411 static const int MSK_ADCALL12 = 0x0FFF; 00412 static const int MSK_ADCALL8 = 0x00FF; 00413 static const int MSK_ADCMSB12 = 0x0800; 00414 static const int MSK_ADCMSB8 = 0x0080; 00415 00417 }; 00418 00422 00427 inline bool RB8905_Adc12::isReady() const 00428 { 00429 return 0 != ( getByte( OFF_STS ) & MSK_STSREADY ); 00430 } 00431 00436 inline bool RB8905_Adc12::isFastMode() const 00437 { 00438 return 0 != ( theControlRegister & MSK_CTLFAST ); 00439 } 00440 00445 inline bool RB8905_Adc12::isUnipolarMode() const 00446 { 00447 return 0 != ( theControlRegister & MSK_CTLUNIP ); 00448 } 00449 00454 inline bool RB8905_Adc12::isEnabledInterrupt() const 00455 { 00456 return 0 != ( theControlRegister & MSK_CTLINTR ); 00457 } 00458 00463 inline Real RB8905_Adc12::voltperbit() const 00464 { 00465 return theVoltPerBit; 00466 } 00467 00472 inline int RB8905_Adc12::bufferCapacity() const 00473 { 00474 return theBufferCapacity; 00475 } 00476 00481 inline int RB8905_Adc12::jmp3BufferCapacity() const 00482 { 00483 return jmp3BufferSize() / elemSize(); 00484 } 00485 00490 inline int RB8905_Adc12::jmp3BufferSize() const 00491 { 00492 return theJmp3BufferSize; 00493 } 00494 00499 inline int RB8905_Adc12::elemSize() const 00500 { 00501 return isFastMode() ? 1 : 2; 00502 } 00503 00508 inline void RB8905_Adc12::setFastMode() 00509 { 00510 putByte( OFF_CTL, theControlRegister |= MSK_CTLFAST ); 00511 } 00512 00517 inline void RB8905_Adc12::setNormalMode() 00518 { 00519 putByte( OFF_CTL, theControlRegister &= ~MSK_CTLFAST ); 00520 } 00521 00526 inline void RB8905_Adc12::setBipolarMode() 00527 { 00528 putByte( OFF_CTL, theControlRegister &= ~MSK_CTLUNIP ); 00529 waitRelais(); 00530 } 00531 00536 inline void RB8905_Adc12::setUnipolarMode() 00537 { 00538 putByte( OFF_CTL, theControlRegister |= MSK_CTLUNIP ); 00539 waitRelais(); 00540 } 00541 00547 inline void RB8905_Adc12::setBufferCapacity( int nelem /* = CON_JMP3 */ ) 00548 { 00549 theBufferCapacity = nelem; 00550 } 00551 00556 inline RB8905_Adc12Ref to_rb8905( RulbusDevicePtr p ) 00557 { 00558 return PROXY_CAST<RB8905_Adc12Ref>( *p ); 00559 } 00560 00565 inline RB8905_Adc12Ptr to_rb8905_ptr( RulbusDevicePtr p ) 00566 { 00567 return PROXY_CAST<RB8905_Adc12Ptr>( p ); 00568 } 00569 00570 } // namespace Rulbus 00571 00572 #endif // __RB8905_ADC12_H 00573 00574 /* 00575 * end of file 00576 */ 00577