Marijn Billiet / AD5933
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ad5933.h Source File

ad5933.h

00001 /* ---------------------------------------------------------------------------------
00002 Copyright 2015 Marijn Billiet
00003 
00004    Licensed under the Apache License, Version 2.0 (the "License");
00005    you may not use this file except in compliance with the License.
00006    You may obtain a copy of the License at
00007 
00008        http://www.apache.org/licenses/LICENSE-2.0
00009 
00010    Unless required by applicable law or agreed to in writing, software
00011    distributed under the License is distributed on an "AS IS" BASIS,
00012    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013    See the License for the specific language governing permissions and
00014    limitations under the License.
00015    
00016  --------------------------------------------------------------------------------- */
00017 
00018 #ifndef MBED_AD5933_H
00019 #include "mbed.h"
00020 #define MBED_AD5933_H
00021 
00022 
00023 /** AD5933 class.
00024  *  Library to communicate with the AD5933 impedance meter chip.
00025  *
00026  * Example:
00027  * @code
00028  * #include "mbed.h"
00029  * #include "ad5933.h"
00030  *
00031  * AD5933 Zmeter(p28, p27, false);
00032  *
00033  * int main() {
00034  *     float temp = Zmeter.getTemperature();
00035  *
00036  *     Zmeter.initFrequencySweepParam(100000, 10, 2, 50, true, 1);
00037  *
00038  *     while(true) {
00039  *          if(!Zmeter.Measure(true))
00040  *              printf("error occured");
00041  *          
00042  *          int real = Zmeter.real;
00043  *          int imag = Zmeter.imaginary;
00044  *
00045  *          wait(1);
00046  *     }
00047  *     
00048  * }
00049  * @endcode
00050  */
00051 class AD5933
00052 {
00053 public:
00054     /** Create AD5933 instance
00055     @param sda I2C data line pin
00056     @param scl I2C clock line pin
00057     @param extClk source of the Clock signal:  true = external;  false = internal
00058     */
00059     AD5933(PinName sda, PinName scl, bool extClk);
00060 
00061     /** Time to wait before the ADC starts to sample
00062     @param nrOfCycles Number of cycles (outputfrequency) to wait for sampling can start  (max 2044)
00063     @return true on succes, false on failure
00064     */
00065     bool setSettlingTime(unsigned int nrOfCycles);
00066 
00067     /** Set the gain of the pre-amplification and the output voltage range
00068     @param PGA Gain of the pre-amplifier (true = x1; false = x5)
00069     @param RangeNr Set the output voltage (1 = 2V; 2 = 1V; 3 = 400mV; 4 = 200mV)
00070     @return true on succes, false on failure
00071     */
00072     bool setAnalogCircuit(bool PGA, int RangeNr);
00073 
00074     /** Measure Impedance
00075     @param increment (true = goto next frequency in sweep; false = remeasure at current frequency)
00076     @return true on succes, false on failure
00077     */
00078     bool Measure(bool increment);
00079 
00080     /// Resets Device
00081     ///@return true on succes, false on failure
00082     bool reset();
00083 
00084     /// Get temperature of chip
00085     ///@return temperature in degrees Celcius
00086     float getTemperature();
00087 
00088     /// Puts the Device in Standby Mode
00089     ///@return true on succes, false on failure
00090     bool standby();
00091 
00092     /// Puts the Device in PowerDown Mode
00093     ///@return true on succes, false on failure
00094     bool powerdown();
00095 
00096     /** Initialises a frequency sweep.
00097     @param startFreq initial frequency (max 100000Hz)
00098     @param stepFreq stepsize of increment in frequency
00099     @param nrOfSteps number of increments
00100     @param nrOfCycles Number of cycles (outputfrequency) to wait for sampling can start  (max 2044)
00101     @param PGA Gain of the pre-amplifier (true = x1; false = x5)
00102     @param RangeNr Set the output voltage (1 = 2V; 2 = 1V; 3 = 400mV; 4 = 200mV)
00103     @return true on succes, false on failure
00104     */
00105     bool initFrequencySweepParam(unsigned int startFreq, unsigned int stepFreq, unsigned int nrOfSteps, unsigned int nrOfCycles, bool PGA, int RangeNr);
00106 
00107     /// real part of impedance (uncalibrated)
00108     unsigned int real;
00109 
00110     /// imaginary part of impedance (uncalibrated)
00111     unsigned int imaginary;
00112 
00113 private:
00114     I2C sCom;
00115     uint8_t PGAandVoltout;
00116 
00117     bool setFrequencySweepParam(unsigned int startFreq, unsigned int stepFreq, unsigned int nrOfSteps);
00118     bool gotoAdressPointer(uint8_t Adress);
00119     bool setRegister(uint8_t RegisterAdress, uint8_t RegisterValue);
00120     bool writeBlock(uint8_t ByteArray[], uint8_t sizeArray);
00121     uint8_t getRegister(uint8_t RegisterAdress);
00122     bool readBlock(uint8_t* ByteArray, uint8_t sizeArray);
00123     bool setControlReg(uint8_t Command);
00124     bool getData();
00125     bool _extClk;
00126 
00127 };
00128 #endif