Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ad5933.h@6:6b9fc31d51b0, 2015-05-20 (annotated)
- Committer:
- dipi
- Date:
- Wed May 20 09:17:24 2015 +0000
- Revision:
- 6:6b9fc31d51b0
- Parent:
- 5:2dc8c3f02788
Beta version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dipi | 1:b6eb241a5fa3 | 1 | /* --------------------------------------------------------------------------------- |
| dipi | 1:b6eb241a5fa3 | 2 | Copyright 2015 Marijn Billiet |
| dipi | 1:b6eb241a5fa3 | 3 | |
| dipi | 1:b6eb241a5fa3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| dipi | 1:b6eb241a5fa3 | 5 | you may not use this file except in compliance with the License. |
| dipi | 1:b6eb241a5fa3 | 6 | You may obtain a copy of the License at |
| dipi | 1:b6eb241a5fa3 | 7 | |
| dipi | 1:b6eb241a5fa3 | 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| dipi | 1:b6eb241a5fa3 | 9 | |
| dipi | 1:b6eb241a5fa3 | 10 | Unless required by applicable law or agreed to in writing, software |
| dipi | 1:b6eb241a5fa3 | 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| dipi | 1:b6eb241a5fa3 | 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| dipi | 1:b6eb241a5fa3 | 13 | See the License for the specific language governing permissions and |
| dipi | 1:b6eb241a5fa3 | 14 | limitations under the License. |
| dipi | 6:6b9fc31d51b0 | 15 | |
| dipi | 1:b6eb241a5fa3 | 16 | --------------------------------------------------------------------------------- */ |
| dipi | 1:b6eb241a5fa3 | 17 | |
| dipi | 2:93dd1ebfedea | 18 | #ifndef MBED_AD5933_H |
| dipi | 2:93dd1ebfedea | 19 | #include "mbed.h" |
| dipi | 2:93dd1ebfedea | 20 | #define MBED_AD5933_H |
| dipi | 1:b6eb241a5fa3 | 21 | |
| dipi | 0:6a71184e6f66 | 22 | |
| dipi | 0:6a71184e6f66 | 23 | /** AD5933 class. |
| dipi | 0:6a71184e6f66 | 24 | * Library to communicate with the AD5933 impedance meter chip. |
| dipi | 6:6b9fc31d51b0 | 25 | * |
| dipi | 6:6b9fc31d51b0 | 26 | * Example: |
| dipi | 6:6b9fc31d51b0 | 27 | * @code |
| dipi | 6:6b9fc31d51b0 | 28 | * #include "mbed.h" |
| dipi | 6:6b9fc31d51b0 | 29 | * #include "ad5933.h" |
| dipi | 6:6b9fc31d51b0 | 30 | * |
| dipi | 6:6b9fc31d51b0 | 31 | * AD5933 Zmeter(p28, p27, false); |
| dipi | 6:6b9fc31d51b0 | 32 | * |
| dipi | 6:6b9fc31d51b0 | 33 | * int main() { |
| dipi | 6:6b9fc31d51b0 | 34 | * float temp = Zmeter.getTemperature(); |
| dipi | 6:6b9fc31d51b0 | 35 | * |
| dipi | 6:6b9fc31d51b0 | 36 | * Zmeter.initFrequencySweepParam(100000, 10, 2, 50, true, 1); |
| dipi | 6:6b9fc31d51b0 | 37 | * |
| dipi | 6:6b9fc31d51b0 | 38 | * while(true) { |
| dipi | 6:6b9fc31d51b0 | 39 | * if(!Zmeter.Measure(true)) |
| dipi | 6:6b9fc31d51b0 | 40 | * printf("error occured"); |
| dipi | 6:6b9fc31d51b0 | 41 | * |
| dipi | 6:6b9fc31d51b0 | 42 | * int real = Zmeter.real; |
| dipi | 6:6b9fc31d51b0 | 43 | * int imag = Zmeter.imaginary; |
| dipi | 6:6b9fc31d51b0 | 44 | * |
| dipi | 6:6b9fc31d51b0 | 45 | * wait(1); |
| dipi | 6:6b9fc31d51b0 | 46 | * } |
| dipi | 6:6b9fc31d51b0 | 47 | * |
| dipi | 6:6b9fc31d51b0 | 48 | * } |
| dipi | 6:6b9fc31d51b0 | 49 | * @endcode |
| dipi | 0:6a71184e6f66 | 50 | */ |
| dipi | 0:6a71184e6f66 | 51 | class AD5933 |
| dipi | 0:6a71184e6f66 | 52 | { |
| dipi | 0:6a71184e6f66 | 53 | public: |
| dipi | 0:6a71184e6f66 | 54 | /** Create AD5933 instance |
| dipi | 0:6a71184e6f66 | 55 | @param sda I2C data line pin |
| dipi | 0:6a71184e6f66 | 56 | @param scl I2C clock line pin |
| dipi | 0:6a71184e6f66 | 57 | @param extClk source of the Clock signal: true = external; false = internal |
| dipi | 0:6a71184e6f66 | 58 | */ |
| dipi | 0:6a71184e6f66 | 59 | AD5933(PinName sda, PinName scl, bool extClk); |
| dipi | 6:6b9fc31d51b0 | 60 | |
| dipi | 0:6a71184e6f66 | 61 | /** Time to wait before the ADC starts to sample |
| dipi | 0:6a71184e6f66 | 62 | @param nrOfCycles Number of cycles (outputfrequency) to wait for sampling can start (max 2044) |
| dipi | 6:6b9fc31d51b0 | 63 | @return true on succes, false on failure |
| dipi | 6:6b9fc31d51b0 | 64 | */ |
| dipi | 0:6a71184e6f66 | 65 | bool setSettlingTime(unsigned int nrOfCycles); |
| dipi | 6:6b9fc31d51b0 | 66 | |
| dipi | 0:6a71184e6f66 | 67 | /** Set the gain of the pre-amplification and the output voltage range |
| dipi | 0:6a71184e6f66 | 68 | @param PGA Gain of the pre-amplifier (true = x1; false = x5) |
| dipi | 0:6a71184e6f66 | 69 | @param RangeNr Set the output voltage (1 = 2V; 2 = 1V; 3 = 400mV; 4 = 200mV) |
| dipi | 6:6b9fc31d51b0 | 70 | @return true on succes, false on failure |
| dipi | 6:6b9fc31d51b0 | 71 | */ |
| dipi | 0:6a71184e6f66 | 72 | bool setAnalogCircuit(bool PGA, int RangeNr); |
| dipi | 6:6b9fc31d51b0 | 73 | |
| dipi | 0:6a71184e6f66 | 74 | /** Measure Impedance |
| dipi | 0:6a71184e6f66 | 75 | @param increment (true = goto next frequency in sweep; false = remeasure at current frequency) |
| dipi | 6:6b9fc31d51b0 | 76 | @return true on succes, false on failure |
| dipi | 6:6b9fc31d51b0 | 77 | */ |
| dipi | 0:6a71184e6f66 | 78 | bool Measure(bool increment); |
| dipi | 6:6b9fc31d51b0 | 79 | |
| dipi | 0:6a71184e6f66 | 80 | /// Resets Device |
| dipi | 6:6b9fc31d51b0 | 81 | ///@return true on succes, false on failure |
| dipi | 0:6a71184e6f66 | 82 | bool reset(); |
| dipi | 6:6b9fc31d51b0 | 83 | |
| dipi | 3:b844dd14179c | 84 | /// Get temperature of chip |
| dipi | 6:6b9fc31d51b0 | 85 | ///@return temperature in degrees Celcius |
| dipi | 3:b844dd14179c | 86 | float getTemperature(); |
| dipi | 6:6b9fc31d51b0 | 87 | |
| dipi | 6:6b9fc31d51b0 | 88 | /// Puts the Device in Standby Mode |
| dipi | 6:6b9fc31d51b0 | 89 | ///@return true on succes, false on failure |
| dipi | 4:1ecb56465953 | 90 | bool standby(); |
| dipi | 6:6b9fc31d51b0 | 91 | |
| dipi | 6:6b9fc31d51b0 | 92 | /// Puts the Device in PowerDown Mode |
| dipi | 6:6b9fc31d51b0 | 93 | ///@return true on succes, false on failure |
| dipi | 6:6b9fc31d51b0 | 94 | bool powerdown(); |
| dipi | 6:6b9fc31d51b0 | 95 | |
| dipi | 6:6b9fc31d51b0 | 96 | /** Initialises a frequency sweep. |
| dipi | 6:6b9fc31d51b0 | 97 | @param startFreq initial frequency (max 100000Hz) |
| dipi | 6:6b9fc31d51b0 | 98 | @param stepFreq stepsize of increment in frequency |
| dipi | 6:6b9fc31d51b0 | 99 | @param nrOfSteps number of increments |
| dipi | 6:6b9fc31d51b0 | 100 | @param nrOfCycles Number of cycles (outputfrequency) to wait for sampling can start (max 2044) |
| dipi | 6:6b9fc31d51b0 | 101 | @param PGA Gain of the pre-amplifier (true = x1; false = x5) |
| dipi | 6:6b9fc31d51b0 | 102 | @param RangeNr Set the output voltage (1 = 2V; 2 = 1V; 3 = 400mV; 4 = 200mV) |
| dipi | 6:6b9fc31d51b0 | 103 | @return true on succes, false on failure |
| dipi | 6:6b9fc31d51b0 | 104 | */ |
| dipi | 6:6b9fc31d51b0 | 105 | bool initFrequencySweepParam(unsigned int startFreq, unsigned int stepFreq, unsigned int nrOfSteps, unsigned int nrOfCycles, bool PGA, int RangeNr); |
| dipi | 6:6b9fc31d51b0 | 106 | |
| dipi | 0:6a71184e6f66 | 107 | /// real part of impedance (uncalibrated) |
| dipi | 5:2dc8c3f02788 | 108 | unsigned int real; |
| dipi | 6:6b9fc31d51b0 | 109 | |
| dipi | 0:6a71184e6f66 | 110 | /// imaginary part of impedance (uncalibrated) |
| dipi | 5:2dc8c3f02788 | 111 | unsigned int imaginary; |
| dipi | 6:6b9fc31d51b0 | 112 | |
| dipi | 0:6a71184e6f66 | 113 | private: |
| dipi | 0:6a71184e6f66 | 114 | I2C sCom; |
| dipi | 0:6a71184e6f66 | 115 | uint8_t PGAandVoltout; |
| dipi | 0:6a71184e6f66 | 116 | |
| dipi | 6:6b9fc31d51b0 | 117 | bool setFrequencySweepParam(unsigned int startFreq, unsigned int stepFreq, unsigned int nrOfSteps); |
| dipi | 0:6a71184e6f66 | 118 | bool gotoAdressPointer(uint8_t Adress); |
| dipi | 0:6a71184e6f66 | 119 | bool setRegister(uint8_t RegisterAdress, uint8_t RegisterValue); |
| dipi | 0:6a71184e6f66 | 120 | bool writeBlock(uint8_t ByteArray[], uint8_t sizeArray); |
| dipi | 0:6a71184e6f66 | 121 | uint8_t getRegister(uint8_t RegisterAdress); |
| dipi | 0:6a71184e6f66 | 122 | bool readBlock(uint8_t* ByteArray, uint8_t sizeArray); |
| dipi | 0:6a71184e6f66 | 123 | bool setControlReg(uint8_t Command); |
| dipi | 0:6a71184e6f66 | 124 | bool getData(); |
| dipi | 0:6a71184e6f66 | 125 | bool _extClk; |
| dipi | 0:6a71184e6f66 | 126 | |
| dipi | 0:6a71184e6f66 | 127 | }; |
| dipi | 0:6a71184e6f66 | 128 | #endif |