jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. */
|
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */
|
| 4 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #ifndef ANALOG_MODULE_H_
|
| 8 | #define ANALOG_MODULE_H_
|
| 9 |
|
| 10 | #include "ChipObject.h"
|
| 11 | #include "Module.h"
|
| 12 |
|
| 13 | /**
|
| 14 | * Analog Module class.
|
| 15 | * Each module can independently sample its channels at a configurable rate.
|
| 16 | * There is a 64-bit hardware accumulator associated with channel 1 on each module.
|
| 17 | * The accumulator is attached to the output of the oversample and average engine so that the center
|
| 18 | * value can be specified in higher resolution resulting in less error.
|
| 19 | */
|
| 20 | class AnalogModule: public Module
|
| 21 | {
|
| 22 | friend class Module;
|
| 23 |
|
| 24 | public:
|
| 25 | static const long kTimebase = 40000000; ///< 40 MHz clock
|
| 26 | static const long kDefaultOversampleBits = 0;
|
| 27 | static const long kDefaultAverageBits = 7;
|
| 28 | static const float kDefaultSampleRate = 50000.0;
|
| 29 |
|
| 30 | void SetSampleRate(float samplesPerSecond);
|
| 31 | float GetSampleRate();
|
| 32 | void SetAverageBits(UINT32 channel, UINT32 bits);
|
| 33 | UINT32 GetAverageBits(UINT32 channel);
|
| 34 | void SetOversampleBits(UINT32 channel, UINT32 bits);
|
| 35 | UINT32 GetOversampleBits(UINT32 channel);
|
| 36 | INT16 GetValue(UINT32 channel);
|
| 37 | INT32 GetAverageValue(UINT32 channel);
|
| 38 | float GetAverageVoltage(UINT32 channel);
|
| 39 | float GetVoltage(UINT32 channel);
|
| 40 | UINT32 GetLSBWeight(UINT32 channel);
|
| 41 | INT32 GetOffset(UINT32 channel);
|
| 42 | INT32 VoltsToValue(INT32 channel, float voltage);
|
| 43 |
|
| 44 | static AnalogModule* GetInstance(UINT8 moduleNumber);
|
| 45 |
|
| 46 | protected:
|
| 47 | explicit AnalogModule(UINT8 moduleNumber);
|
| 48 | virtual ~AnalogModule();
|
| 49 |
|
| 50 | private:
|
| 51 | static SEM_ID m_registerWindowSemaphore;
|
| 52 |
|
| 53 | UINT32 GetNumActiveChannels();
|
| 54 | UINT32 GetNumChannelsToActivate();
|
| 55 | void SetNumChannelsToActivate(UINT32 channels);
|
| 56 |
|
| 57 | tAI *m_module;
|
| 58 | bool m_sampleRateSet;
|
| 59 | UINT32 m_numChannelsToActivate;
|
| 60 | };
|
| 61 |
|
| 62 | #endif
|