Library to communicate with LDC1614

Dependencies:   SHTx

Dependents:   Inductive_Sensor_3

Fork of LDC1101 by Bob Giesberts

Committer:
bobgiesberts
Date:
Wed Aug 24 10:31:08 2016 +0000
Revision:
30:95c53d244f91
Parent:
29:41815fd13822
Child:
31:ab4354a71996
API documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bobgiesberts 28:76a2fc42f888 1 #ifndef _LDC1614_H_
bobgiesberts 28:76a2fc42f888 2 #define _LDC1614_H_
bobgiesberts 16:07d0e43c2d12 3
bobgiesberts 16:07d0e43c2d12 4 #include "mbed.h"
bobgiesberts 16:07d0e43c2d12 5
bobgiesberts 16:07d0e43c2d12 6 #ifndef PI
bobgiesberts 16:07d0e43c2d12 7 #define PI 3.14
bobgiesberts 16:07d0e43c2d12 8 #endif
bobgiesberts 16:07d0e43c2d12 9
bobgiesberts 29:41815fd13822 10
bobgiesberts 29:41815fd13822 11 /*
bobgiesberts 28:76a2fc42f888 12 int min(int a, int b) { return (a<b) ? a : b; }
bobgiesberts 28:76a2fc42f888 13 float min(float a, float b) { return (a<b) ? a : b; }
bobgiesberts 28:76a2fc42f888 14 int max(int a, int b) { return (a>b) ? a : b; }
bobgiesberts 28:76a2fc42f888 15 float max(float a, float b) { return (a>b) ? a : b; }
bobgiesberts 29:41815fd13822 16 */
bobgiesberts 28:76a2fc42f888 17
bobgiesberts 16:07d0e43c2d12 18
bobgiesberts 19:e205ab9142d8 19 typedef enum { LDC_MODE_ACTIVE = 0, \
bobgiesberts 28:76a2fc42f888 20 LDC_MODE_SLEEP = 1, \
bobgiesberts 16:07d0e43c2d12 21 LDC_MODE_SHUTDOWN = 2} LDC_MODE;
bobgiesberts 16:07d0e43c2d12 22
bobgiesberts 28:76a2fc42f888 23 typedef enum { DEGLITCH_1M = 1, \
bobgiesberts 28:76a2fc42f888 24 DEGLITCH_3M = 4, \
bobgiesberts 28:76a2fc42f888 25 DEGLITCH_10M = 5, \
bobgiesberts 28:76a2fc42f888 26 DEGLITCH_33M = 7} DEGLITCHER; // This should be 011 (p. 16) or 111 (p.32)
bobgiesberts 17:a5cf2b4bec13 27
bobgiesberts 28:76a2fc42f888 28 typedef enum { DATA_MSB_CH0 = 0x00, \
bobgiesberts 28:76a2fc42f888 29 DATA_LSB_CH0 = 0x01, \
bobgiesberts 28:76a2fc42f888 30 DATA_MSB_CH1 = 0x02, \
bobgiesberts 28:76a2fc42f888 31 DATA_LSB_CH1 = 0x03, \
bobgiesberts 28:76a2fc42f888 32 DATA_MSB_CH2 = 0x04, \
bobgiesberts 28:76a2fc42f888 33 DATA_LSB_CH2 = 0x05, \
bobgiesberts 28:76a2fc42f888 34 DATA_MSB_CH3 = 0x06, \
bobgiesberts 28:76a2fc42f888 35 DATA_LSB_CH3 = 0x07, \
bobgiesberts 28:76a2fc42f888 36 RCOUNT_CH0 = 0x08, \
bobgiesberts 28:76a2fc42f888 37 RCOUNT_CH1 = 0x09, \
bobgiesberts 28:76a2fc42f888 38 RCOUNT_CH2 = 0x0A, \
bobgiesberts 28:76a2fc42f888 39 RCOUNT_CH3 = 0x0B, \
bobgiesberts 28:76a2fc42f888 40 OFFSET_CH0 = 0x0C, \
bobgiesberts 28:76a2fc42f888 41 OFFSET_CH1 = 0x0D, \
bobgiesberts 28:76a2fc42f888 42 OFFSET_CH2 = 0x0E, \
bobgiesberts 28:76a2fc42f888 43 OFFSET_CH3 = 0x0F, \
bobgiesberts 28:76a2fc42f888 44 SETTLECOUNT_CH0 = 0x10, \
bobgiesberts 28:76a2fc42f888 45 SETTLECOUNT_CH1 = 0x11, \
bobgiesberts 28:76a2fc42f888 46 SETTLECOUNT_CH2 = 0x12, \
bobgiesberts 28:76a2fc42f888 47 SETTLECOUNT_CH3 = 0x13, \
bobgiesberts 28:76a2fc42f888 48 CLOCK_DIVIDERS_CH0 = 0x14, \
bobgiesberts 28:76a2fc42f888 49 CLOCK_DIVIDERS_CH1 = 0x15, \
bobgiesberts 28:76a2fc42f888 50 CLOCK_DIVIDERS_CH2 = 0x16, \
bobgiesberts 28:76a2fc42f888 51 CLOCK_DIVIDERS_CH3 = 0x17, \
bobgiesberts 28:76a2fc42f888 52 STATUS = 0x18, \
bobgiesberts 28:76a2fc42f888 53 ERROR_CONFIG = 0x19, \
bobgiesberts 28:76a2fc42f888 54 CONFIG = 0x1A, \
bobgiesberts 28:76a2fc42f888 55 MUX_CONFIG = 0x1B, \
bobgiesberts 28:76a2fc42f888 56 DRIVE_CURRENT_CH0 = 0x1E, \
bobgiesberts 28:76a2fc42f888 57 DRIVE_CURRENT_CH1 = 0x1F, \
bobgiesberts 28:76a2fc42f888 58 DRIVE_CURRENT_CH2 = 0x20, \
bobgiesberts 28:76a2fc42f888 59 DRIVE_CURRENT_CH3 = 0x21} ADDR;
bobgiesberts 25:ae111662ee03 60
bobgiesberts 29:41815fd13822 61 typedef enum { CHx_ERR_UR = 15, \
bobgiesberts 29:41815fd13822 62 CHx_ERR_OR = 14, \
bobgiesberts 29:41815fd13822 63 CHx_ERR_WD = 13, \
bobgiesberts 29:41815fd13822 64 CHx_ERR_AE = 12, \
bobgiesberts 29:41815fd13822 65 ERR_CHAN = 14, \
bobgiesberts 29:41815fd13822 66 ERR_UR = 13, \
bobgiesberts 29:41815fd13822 67 ERR_OR = 12, \
bobgiesberts 29:41815fd13822 68 ERR_WD = 11, \
bobgiesberts 29:41815fd13822 69 ERR_AHE = 10, \
bobgiesberts 29:41815fd13822 70 ERR_ALE = 9, \
bobgiesberts 29:41815fd13822 71 ERR_ZC = 8, \
bobgiesberts 29:41815fd13822 72 DRDY = 6, \
bobgiesberts 29:41815fd13822 73 CH0_UNREADCONV = 3, \
bobgiesberts 29:41815fd13822 74 CH1_UNREADCONV = 2, \
bobgiesberts 29:41815fd13822 75 CH2_UNREADCONV = 1, \
bobgiesberts 29:41815fd13822 76 CH3_UNREADCONV = 0, \
bobgiesberts 29:41815fd13822 77 UR_ERR2OUT = 15, \
bobgiesberts 28:76a2fc42f888 78 OR_ERR2OUT = 14, \
bobgiesberts 28:76a2fc42f888 79 WD_ERR2OUT = 13, \
bobgiesberts 28:76a2fc42f888 80 AH_ERR2OUT = 12, \
bobgiesberts 28:76a2fc42f888 81 AL_ERR2OUT = 11, \
bobgiesberts 28:76a2fc42f888 82 UR_ERR2INT = 7, \
bobgiesberts 28:76a2fc42f888 83 OR_ERR2INT = 6, \
bobgiesberts 28:76a2fc42f888 84 WD_ERR2INT = 5, \
bobgiesberts 28:76a2fc42f888 85 AH_ERR2INT = 4, \
bobgiesberts 28:76a2fc42f888 86 AL_ERR2INT = 3, \
bobgiesberts 28:76a2fc42f888 87 ZC_ERR2INT = 2, \
bobgiesberts 28:76a2fc42f888 88 DRDY_2INT = 0, \
bobgiesberts 28:76a2fc42f888 89 ACTIVE_CHAN = 14, \
bobgiesberts 28:76a2fc42f888 90 SLEEP_MODE_EN = 13, \
bobgiesberts 28:76a2fc42f888 91 RP_OVERRIDE_EN = 12, \
bobgiesberts 28:76a2fc42f888 92 SENSOR_ACTIVATE_SEL = 11, \
bobgiesberts 28:76a2fc42f888 93 AUTO_AMP_DIS = 10, \
bobgiesberts 28:76a2fc42f888 94 REF_CLK_SRC = 9, \
bobgiesberts 28:76a2fc42f888 95 INTB_DIS = 7, \
bobgiesberts 28:76a2fc42f888 96 HIGH_CURRENT_DRV = 6, \
bobgiesberts 28:76a2fc42f888 97 AUTOSCAN_EN = 15, \
bobgiesberts 28:76a2fc42f888 98 RR_SEQUENCE = 13, \
bobgiesberts 28:76a2fc42f888 99 DEGLITCH = 0} SETTING;
bobgiesberts 28:76a2fc42f888 100
bobgiesberts 28:76a2fc42f888 101
bobgiesberts 28:76a2fc42f888 102
bobgiesberts 17:a5cf2b4bec13 103
bobgiesberts 30:95c53d244f91 104 /** Class for the LDC1614.
bobgiesberts 30:95c53d244f91 105 * @author Bob Giesberts
bobgiesberts 30:95c53d244f91 106 * @date 2016-08-09
bobgiesberts 30:95c53d244f91 107 * @file LDC1614.h
bobgiesberts 30:95c53d244f91 108 * @brief this header file will contain all required
bobgiesberts 30:95c53d244f91 109 * definitions for the functions to interface with Texas
bobgiesberts 30:95c53d244f91 110 * Instruments' LDC1614.
bobgiesberts 30:95c53d244f91 111 */
bobgiesberts 30:95c53d244f91 112 class LDC1614 {
bobgiesberts 16:07d0e43c2d12 113 public:
bobgiesberts 30:95c53d244f91 114 /** Create a new LDC1614 class
bobgiesberts 30:95c53d244f91 115 * @brief Create a new Class to interface to an LDC1614
bobgiesberts 30:95c53d244f91 116 * @param sda I2C SDA pin connected to LDC1614
bobgiesberts 30:95c53d244f91 117 * @param scl I2C SCL pin connected to LDC1614
bobgiesberts 30:95c53d244f91 118 * @param sd Shutdown pin connected to LDC1614
bobgiesberts 30:95c53d244f91 119 * @param os Pin connected to oscillator
bobgiesberts 30:95c53d244f91 120 * @param f_CLKIN f_CLKIN (Hz)
bobgiesberts 30:95c53d244f91 121 * @param sensors number of sensors
bobgiesberts 30:95c53d244f91 122 * @param capacitor Used capacitor on all connected sensors
bobgiesberts 16:07d0e43c2d12 123 **/
bobgiesberts 29:41815fd13822 124 LDC1614(PinName sda, PinName scl, PinName sd, PinName os, float f_CLKIN, int sensors, float capacitor);
bobgiesberts 28:76a2fc42f888 125 ~LDC1614();
bobgiesberts 16:07d0e43c2d12 126
bobgiesberts 16:07d0e43c2d12 127 /**
bobgiesberts 30:95c53d244f91 128 * @brief Set power mode.
bobgiesberts 30:95c53d244f91 129 * The constructor sets the LDC1614 in Active mode.
bobgiesberts 30:95c53d244f91 130 * @param mode choose from:
bobgiesberts 30:95c53d244f91 131 * - LDC_MODE_ACTIVE
bobgiesberts 30:95c53d244f91 132 * - LDC_MODE_SLEEP
bobgiesberts 30:95c53d244f91 133 * - LDC_MODE_SHUTDOWN
bobgiesberts 16:07d0e43c2d12 134 **/
bobgiesberts 20:8e1b1efdbb49 135 void func_mode(LDC_MODE mode);
bobgiesberts 30:95c53d244f91 136
bobgiesberts 30:95c53d244f91 137 /// @brief Put the LDC in configuration modus
bobgiesberts 20:8e1b1efdbb49 138 void sleep(void);
bobgiesberts 30:95c53d244f91 139 /// @brief Get LDC1614 to work for you again
bobgiesberts 20:8e1b1efdbb49 140 void wakeup(void);
bobgiesberts 30:95c53d244f91 141 /// @brief Put the LDC in its lowest power modus
bobgiesberts 29:41815fd13822 142 void shutdown(void);
bobgiesberts 30:95c53d244f91 143 /// @brief initial configurations
bobgiesberts 16:07d0e43c2d12 144 void init(void);
bobgiesberts 19:e205ab9142d8 145
bobgiesberts 16:07d0e43c2d12 146
bobgiesberts 19:e205ab9142d8 147 /**
bobgiesberts 30:95c53d244f91 148 * @brief Set the Reference Count parameter.
bobgiesberts 30:95c53d244f91 149 * @param channel the channel (CH0, CH1, CH2, CH3)
bobgiesberts 30:95c53d244f91 150 * @param RCOUNT For LHR mode, the conversion time is set by the reference count CHx_RCOUNT
bobgiesberts 30:95c53d244f91 151 * The conversion time represents the number of clock cycles used to measure the sensor frequency.
bobgiesberts 30:95c53d244f91 152 * Higher values for CHx_RCOUNT have a higher effective measurement resolution but a lower sample rate.
bobgiesberts 30:95c53d244f91 153 * The maximum setting (0xffff) is required for full resolution
bobgiesberts 30:95c53d244f91 154 * t_conv = (CHx_RCOUNT x 16) / f_REFx
bobgiesberts 30:95c53d244f91 155 * CHx_RCount = (f_CLKIN/sample rate - 55)/16
bobgiesberts 28:76a2fc42f888 156 **/
bobgiesberts 28:76a2fc42f888 157 void setReferenceCount( uint8_t channel, uint16_t rcount );
bobgiesberts 28:76a2fc42f888 158
bobgiesberts 28:76a2fc42f888 159 /**
bobgiesberts 30:95c53d244f91 160 * @brief Sensor offset (p.13)
bobgiesberts 30:95c53d244f91 161 * The sensor might reach a value > 2^28. To prevent this, set an offset.
bobgiesberts 30:95c53d244f91 162 * @param channel the channel (CH0, CH1, CH2, CH3)
bobgiesberts 30:95c53d244f91 163 * @param offset 16 bit value that should be substracted from the current sensor value
bobgiesberts 30:95c53d244f91 164 * f_offsetx = (CHx_OFFSET / 2^16)*f_REFx
bobgiesberts 28:76a2fc42f888 165 **/
bobgiesberts 28:76a2fc42f888 166 void setOffset( uint8_t channel, uint32_t offset );
bobgiesberts 28:76a2fc42f888 167
bobgiesberts 28:76a2fc42f888 168 /**
bobgiesberts 30:95c53d244f91 169 * @brief sensor settling time
bobgiesberts 30:95c53d244f91 170 * CHx_SETTLECOUNT >= Q * f_REFx / (16 * f_SENSORx)
bobgiesberts 30:95c53d244f91 171 * t_settle = (CHx_SETTLECOUNT x 16) / f_REFx
bobgiesberts 30:95c53d244f91 172 * @param channel the channel (CH0, CH1, CH2, CH3)
bobgiesberts 30:95c53d244f91 173 * @param settlecount CHx_SETTLECOUNT (0 - 65 535)
bobgiesberts 28:76a2fc42f888 174 **/
bobgiesberts 28:76a2fc42f888 175 void setSettlecount( uint8_t channel, uint16_t settlecount);
bobgiesberts 28:76a2fc42f888 176
bobgiesberts 28:76a2fc42f888 177 /**
bobgiesberts 30:95c53d244f91 178 * @brief clock divider
bobgiesberts 30:95c53d244f91 179 * Sensor divider (p.14)
bobgiesberts 30:95c53d244f91 180 * f_REF = f_CLKIN / REF_DIVIDER
bobgiesberts 30:95c53d244f91 181 * f_IN = f_SENSOR / IN_DIVIDER
bobgiesberts 30:95c53d244f91 182 * Ideally f_REF > 4*f_IN
bobgiesberts 30:95c53d244f91 183 * @param channel the channel (CH0, CH1, CH2, CH3)
bobgiesberts 30:95c53d244f91 184 * @param divIN CHx_FIN_DIVIDER (4bit: 1 - 15)
bobgiesberts 30:95c53d244f91 185 * @param divREF CHx_FREF_DIVIDER (8 bit: 1 - 255)
bobgiesberts 20:8e1b1efdbb49 186 **/
bobgiesberts 28:76a2fc42f888 187 void setDivider( uint8_t channel, uint8_t divIN, uint8_t divREF );
bobgiesberts 28:76a2fc42f888 188
bobgiesberts 28:76a2fc42f888 189
bobgiesberts 28:76a2fc42f888 190 /**
bobgiesberts 30:95c53d244f91 191 * @brief Configuration of the LDC1614
bobgiesberts 30:95c53d244f91 192 * This function can be used to set all settings (p.31)
bobgiesberts 30:95c53d244f91 193 * @param addr address of the setting catgory
bobgiesberts 30:95c53d244f91 194 * - ERROR_CONFIG
bobgiesberts 30:95c53d244f91 195 * - CONFIG
bobgiesberts 30:95c53d244f91 196 * - MUX_CONFIG
bobgiesberts 30:95c53d244f91 197 * @param setting for ERROR_CONFIG
bobgiesberts 30:95c53d244f91 198 * - UR_ERR2OUT
bobgiesberts 30:95c53d244f91 199 * - OR_ERR2OUT
bobgiesberts 30:95c53d244f91 200 * - WD_ERR2OUT
bobgiesberts 30:95c53d244f91 201 * - AH_ERR2OUT
bobgiesberts 30:95c53d244f91 202 * - AL_ERR2OUT
bobgiesberts 30:95c53d244f91 203 * - UR_ERR2INT
bobgiesberts 30:95c53d244f91 204 * - OR_ERR2INT
bobgiesberts 30:95c53d244f91 205 * - WD_ERR2INT
bobgiesberts 30:95c53d244f91 206 * - AH_ERR2INT
bobgiesberts 30:95c53d244f91 207 * - AL_ERR2INT
bobgiesberts 30:95c53d244f91 208 * - ZC_ERR2INT
bobgiesberts 30:95c53d244f91 209 * - DRDY_2INT
bobgiesberts 30:95c53d244f91 210 * for CONFIG (0x1A)
bobgiesberts 30:95c53d244f91 211 * - ACTIVE_CHAN : 0 (CH0) | 1 (CH1) | 10, 11 (CHx)
bobgiesberts 30:95c53d244f91 212 * - SLEEP_MODE_EN : 0 (ACTIVE) | 1 (SLEEP)
bobgiesberts 30:95c53d244f91 213 * - RP_OVERRIDE_EN : 0 (OFF) | 1 (Rp override on)
bobgiesberts 30:95c53d244f91 214 * - SENSOR_ACTIVATE_SEL : 0 (full current) | 1 (low power)
bobgiesberts 30:95c53d244f91 215 * - AUTO_AMP_DIS : 0 (enabled) | 1 (disabled)
bobgiesberts 30:95c53d244f91 216 * - REF_CLK_SRC : 0 (internal) | 1 (external)
bobgiesberts 30:95c53d244f91 217 * - INTB_DIS : 0 (enabled) | 1 (disabled)
bobgiesberts 30:95c53d244f91 218 * - HIGH_CURRENT_DRV : 0 (1.5 mA) | 1 (> 1.5 mA)
bobgiesberts 30:95c53d244f91 219 * for MUX_CONFIG (0x1B)
bobgiesberts 30:95c53d244f91 220 * - AUTOSCAN_EN : 0 (1 channel) | 1 (multichannel)
bobgiesberts 30:95c53d244f91 221 * - RR_SEQUENCE : 00 (CH0, CH1) | 01 (CH0, CH1, CH2) | 10 (CH0, CH1, CH2, CH3)
bobgiesberts 30:95c53d244f91 222 * - DEGLITCH : 001 (1.0 MHz) | 100 (3.3 MHz) | 101 (10 MHz) | 111 (33 MHz)
bobgiesberts 30:95c53d244f91 223 * @param value 0 | 1 | ...
bobgiesberts 30:95c53d244f91 224 * for MUX_CONFIG.DEGLITCH
bobgiesberts 30:95c53d244f91 225 * f_deglitch > f_sensor_max (p. 16)
bobgiesberts 30:95c53d244f91 226 * DEGLITCH_1M - 1.0 MHz
bobgiesberts 30:95c53d244f91 227 * DEGLITCH_3M - 3.3 MHz
bobgiesberts 30:95c53d244f91 228 * DEGLITCH_10M - 10.0 MHz
bobgiesberts 30:95c53d244f91 229 * DEGLITCH_33M - 33.0 MHz
bobgiesberts 28:76a2fc42f888 230 **/
bobgiesberts 28:76a2fc42f888 231 void set( ADDR addr, SETTING setting, uint8_t value );
bobgiesberts 28:76a2fc42f888 232
bobgiesberts 28:76a2fc42f888 233
bobgiesberts 29:41815fd13822 234 uint8_t get( ADDR addr, SETTING setting, uint8_t mask = 1 );
bobgiesberts 28:76a2fc42f888 235
bobgiesberts 28:76a2fc42f888 236
bobgiesberts 28:76a2fc42f888 237
bobgiesberts 28:76a2fc42f888 238
bobgiesberts 28:76a2fc42f888 239 /** !!!!!!
bobgiesberts 30:95c53d244f91 240 * @brief Set the drive current
bobgiesberts 30:95c53d244f91 241 * Exact functioning still unknown (p.14)
bobgiesberts 30:95c53d244f91 242 * @param idrive 5-bit value
bobgiesberts 30:95c53d244f91 243 * b00000 ( 0) - 16 uA
bobgiesberts 30:95c53d244f91 244 * b11111 (31) - 1563 uA
bobgiesberts 28:76a2fc42f888 245 **/
bobgiesberts 28:76a2fc42f888 246 void setDriveCurrent( uint8_t channel, uint8_t idrive );
bobgiesberts 28:76a2fc42f888 247
bobgiesberts 28:76a2fc42f888 248
bobgiesberts 19:e205ab9142d8 249 /**
bobgiesberts 19:e205ab9142d8 250 * @brief Set the value of the external capacitor
bobgiesberts 19:e205ab9142d8 251 * This is needed for the calculation of the inductance.
bobgiesberts 19:e205ab9142d8 252 **/
bobgiesberts 19:e205ab9142d8 253 void setCapacitor(float c){_cap = c;};
bobgiesberts 19:e205ab9142d8 254 /**
bobgiesberts 19:e205ab9142d8 255 * @brief set the value of the external clock
bobgiesberts 19:e205ab9142d8 256 **/
bobgiesberts 19:e205ab9142d8 257 void setFrequency(float frequency){_fCLKIN = frequency;};
bobgiesberts 19:e205ab9142d8 258
bobgiesberts 19:e205ab9142d8 259
bobgiesberts 20:8e1b1efdbb49 260
bobgiesberts 20:8e1b1efdbb49 261
bobgiesberts 20:8e1b1efdbb49 262
bobgiesberts 19:e205ab9142d8 263 /**
bobgiesberts 30:95c53d244f91 264 * @brief Read Data, the raw 28-bit inductance value.
bobgiesberts 30:95c53d244f91 265 * This is needed for the calculation of the inductance.
bobgiesberts 30:95c53d244f91 266 * @param channel the channel (CH0, CH1, CH2, CH3)
bobgiesberts 19:e205ab9142d8 267 **/
bobgiesberts 28:76a2fc42f888 268 uint32_t get_Data( uint8_t channel );
bobgiesberts 19:e205ab9142d8 269 /**
bobgiesberts 30:95c53d244f91 270 * @brief get the calculated value for f_sensor (Hz)
bobgiesberts 30:95c53d244f91 271 * @param Ldata the obtained Data, if omitted, get_Data(0) will be used
bobgiesberts 19:e205ab9142d8 272 **/
bobgiesberts 28:76a2fc42f888 273 float get_fsensor( uint32_t Ldata = 0 );
bobgiesberts 19:e205ab9142d8 274 /**
bobgiesberts 30:95c53d244f91 275 * @brief get the calculated inductance value
bobgiesberts 30:95c53d244f91 276 * @param Ldata the obtained Data, if omitted, get_Data(0) will be used
bobgiesberts 19:e205ab9142d8 277 **/
bobgiesberts 28:76a2fc42f888 278 float get_Inductance( uint32_t Ldata = 0 );
bobgiesberts 28:76a2fc42f888 279
bobgiesberts 28:76a2fc42f888 280
bobgiesberts 28:76a2fc42f888 281
bobgiesberts 30:95c53d244f91 282 /// @brief get the reference frequency (f_CLKIN)
bobgiesberts 19:e205ab9142d8 283 float get_fCLKIN(void);
bobgiesberts 30:95c53d244f91 284 /// @brief get the reference count
bobgiesberts 28:76a2fc42f888 285 uint16_t get_Rcount( uint8_t channel );
bobgiesberts 30:95c53d244f91 286 /// @brief get the divider
bobgiesberts 28:76a2fc42f888 287 uint8_t get_dividerIN(void);
bobgiesberts 30:95c53d244f91 288 /// @brief get the divider
bobgiesberts 28:76a2fc42f888 289 uint8_t get_dividerREF(void);
bobgiesberts 30:95c53d244f91 290 /// @brief get _Offset
bobgiesberts 28:76a2fc42f888 291 uint32_t get_Offset(void);
bobgiesberts 30:95c53d244f91 292 /// @brief get the capacitance
bobgiesberts 19:e205ab9142d8 293 float get_cap(void);
bobgiesberts 28:76a2fc42f888 294
bobgiesberts 30:95c53d244f91 295 /// @brief get the status of the sensors (p.28)
bobgiesberts 28:76a2fc42f888 296 uint16_t get_status(void);
bobgiesberts 19:e205ab9142d8 297
bobgiesberts 30:95c53d244f91 298 /**
bobgiesberts 30:95c53d244f91 299 * @brief is data ready?
bobgiesberts 30:95c53d244f91 300 * returns true when data is ready for all sensors
bobgiesberts 30:95c53d244f91 301 * returns false if not
bobgiesberts 30:95c53d244f91 302 * @param status the obtained value from get_status()
bobgiesberts 30:95c53d244f91 303 * if omitted, get_status() will be used to get a value
bobgiesberts 28:76a2fc42f888 304 **/
bobgiesberts 29:41815fd13822 305 bool is_ready( uint8_t status = 17 );
bobgiesberts 29:41815fd13822 306
bobgiesberts 29:41815fd13822 307 /**
bobgiesberts 30:95c53d244f91 308 * @brief is there an error?
bobgiesberts 30:95c53d244f91 309 * returns true when there is an error
bobgiesberts 30:95c53d244f91 310 * returns false if not
bobgiesberts 30:95c53d244f91 311 * @param status the obtained value from get_status()
bobgiesberts 30:95c53d244f91 312 * if omitted, get_status() will be used to get a value
bobgiesberts 29:41815fd13822 313 **/
bobgiesberts 29:41815fd13822 314 bool is_error( uint8_t status = 17 );
bobgiesberts 29:41815fd13822 315
bobgiesberts 19:e205ab9142d8 316
bobgiesberts 19:e205ab9142d8 317
bobgiesberts 16:07d0e43c2d12 318 private:
bobgiesberts 28:76a2fc42f888 319 void readI2C( uint16_t *data, uint8_t address, uint8_t length = 1);
bobgiesberts 28:76a2fc42f888 320 void writeI2C( uint16_t *data, uint8_t address, uint8_t length = 1);
bobgiesberts 28:76a2fc42f888 321 void writeI2Cregister( uint8_t reg, uint16_t value);
bobgiesberts 28:76a2fc42f888 322 void regchange( uint8_t addr, uint8_t setting, uint8_t value, uint8_t mask = 1 );
bobgiesberts 28:76a2fc42f888 323
bobgiesberts 22:8da965ce5af3 324 void suicide(void *obj) {delete obj;};
bobgiesberts 16:07d0e43c2d12 325
bobgiesberts 28:76a2fc42f888 326 uint8_t _channels; // number of sensors
bobgiesberts 28:76a2fc42f888 327 uint8_t _dividerIN; // CHx_FIN_DIVIDER
bobgiesberts 28:76a2fc42f888 328 uint8_t _dividerREF; // CHx_FREF_DIVIDER
bobgiesberts 28:76a2fc42f888 329 uint32_t _Offset; // LHR_OFFSET
bobgiesberts 28:76a2fc42f888 330
bobgiesberts 28:76a2fc42f888 331 uint16_t _Rcount; // CHx_RCOUNT
bobgiesberts 28:76a2fc42f888 332 uint16_t _SettleCount; // CHx_SETTLECOUNT
bobgiesberts 28:76a2fc42f888 333 uint8_t _DriveCurrent; // CHx_IDRIVE
bobgiesberts 16:07d0e43c2d12 334
bobgiesberts 30:95c53d244f91 335 float _fsensor; // f_sensor (Hz): the calculated frequency of the sensor
bobgiesberts 30:95c53d244f91 336 float _fCLKIN; // f_CLKIN (Hz): frequency of external clock: 16MHz
bobgiesberts 28:76a2fc42f888 337
bobgiesberts 28:76a2fc42f888 338 float _inductance; // the calculated inductance
bobgiesberts 30:95c53d244f91 339 float _cap; // capacitor (F): 120 pF
bobgiesberts 19:e205ab9142d8 340
bobgiesberts 28:76a2fc42f888 341
bobgiesberts 28:76a2fc42f888 342 I2C _i2c;
bobgiesberts 28:76a2fc42f888 343 DigitalOut _shutdown_pin;
bobgiesberts 29:41815fd13822 344 DigitalOut _oscillator;
bobgiesberts 27:05dd145c7997 345
bobgiesberts 16:07d0e43c2d12 346 };
bobgiesberts 16:07d0e43c2d12 347
bobgiesberts 16:07d0e43c2d12 348 #endif