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 30:95c53d244f91 1 /** LDC1614 library
bobgiesberts 28:76a2fc42f888 2 * @file LDC1614.cpp
bobgiesberts 16:07d0e43c2d12 3 * @brief this C++ file contains all required
bobgiesberts 16:07d0e43c2d12 4 * functions to interface with Texas
bobgiesberts 28:76a2fc42f888 5 * Instruments' LDC1614.
bobgiesberts 28:76a2fc42f888 6 *
bobgiesberts 28:76a2fc42f888 7 * @author Bob Giesberts
bobgiesberts 28:76a2fc42f888 8 *
bobgiesberts 28:76a2fc42f888 9 * @date 2016-08-09
bobgiesberts 16:07d0e43c2d12 10 *
bobgiesberts 30:95c53d244f91 11 * @code
bobgiesberts 28:76a2fc42f888 12 * Serial pc(USBTX, USBRX);
bobgiesberts 28:76a2fc42f888 13 * LDC1614 ldc(PTC6, PTC7, PTC5, 16E6, 2, 120E-12);
bobgiesberts 28:76a2fc42f888 14 * int main(){
bobgiesberts 28:76a2fc42f888 15 * while(1) {
bobgiesberts 28:76a2fc42f888 16 * while( !ldc.is_ready() ) {}
bobgiesberts 28:76a2fc42f888 17 *
bobgiesberts 28:76a2fc42f888 18 * pc.printf("sensor 1: %d | sensor 2: %d\r\n", ldc.get_Data(0), ldc.get_Data(1) );
bobgiesberts 28:76a2fc42f888 19 * }
bobgiesberts 28:76a2fc42f888 20 * }
bobgiesberts 30:95c53d244f91 21 * @endcode
bobgiesberts 16:07d0e43c2d12 22 */
bobgiesberts 16:07d0e43c2d12 23
bobgiesberts 28:76a2fc42f888 24 #include "LDC1614.h"
bobgiesberts 29:41815fd13822 25 #include "mbed_debug.h"
bobgiesberts 28:76a2fc42f888 26
bobgiesberts 30:95c53d244f91 27
bobgiesberts 29:41815fd13822 28 LDC1614::LDC1614(PinName sda, PinName scl, PinName sd, PinName os, float f_CLKIN, int channels, float capacitor) : _i2c(sda, scl), _shutdown_pin(sd), _oscillator(os)
bobgiesberts 16:07d0e43c2d12 29 {
bobgiesberts 18:fc9bb81a631f 30 // settings
bobgiesberts 28:76a2fc42f888 31 _channels = channels; // number of sensors
bobgiesberts 28:76a2fc42f888 32 _cap = capacitor;
bobgiesberts 28:76a2fc42f888 33 _fCLKIN = f_CLKIN;
bobgiesberts 28:76a2fc42f888 34
bobgiesberts 28:76a2fc42f888 35 _Offset = 0; // no offset needed
bobgiesberts 28:76a2fc42f888 36 _Rcount = 0xffff; // maximum for greatest precision
bobgiesberts 28:76a2fc42f888 37 _SettleCount = 50; // CHx_SETTLECOUNT = t_settle * f_REFx/16 = 50 (p.12)
bobgiesberts 28:76a2fc42f888 38 _DriveCurrent = 31; // max???
bobgiesberts 22:8da965ce5af3 39
bobgiesberts 29:41815fd13822 40 // start communication
bobgiesberts 28:76a2fc42f888 41 _i2c.frequency(400000); // 400 kHz (p.6)
bobgiesberts 16:07d0e43c2d12 42
bobgiesberts 29:41815fd13822 43 // Initilialize the LDC1614
bobgiesberts 16:07d0e43c2d12 44 init();
bobgiesberts 16:07d0e43c2d12 45 }
bobgiesberts 16:07d0e43c2d12 46
bobgiesberts 28:76a2fc42f888 47 LDC1614::~LDC1614()
bobgiesberts 26:1ef9172cd355 48 {
bobgiesberts 28:76a2fc42f888 49
bobgiesberts 26:1ef9172cd355 50 }
bobgiesberts 26:1ef9172cd355 51
bobgiesberts 28:76a2fc42f888 52 void LDC1614::init()
bobgiesberts 16:07d0e43c2d12 53 {
bobgiesberts 20:8e1b1efdbb49 54 /********* SETTINGS *****************
bobgiesberts 25:ae111662ee03 55 ** C_sensor = 120 pF
bobgiesberts 25:ae111662ee03 56 ** L_sensor = 5 uH
bobgiesberts 25:ae111662ee03 57 ** Rp_min = 1500 Ohm
bobgiesberts 20:8e1b1efdbb49 58 **
bobgiesberts 25:ae111662ee03 59 ** RCount = 65535 (max)
bobgiesberts 28:76a2fc42f888 60 ** Settlecount = 50
bobgiesberts 20:8e1b1efdbb49 61 ** Samplerate = 15.3 Hz
bobgiesberts 20:8e1b1efdbb49 62 ** t_conv = 65.5 ms
bobgiesberts 20:8e1b1efdbb49 63 **
bobgiesberts 25:ae111662ee03 64 ** f_sensor_min = 6.4 MHz (d = inf)
bobgiesberts 25:ae111662ee03 65 ** f_sensor_max = 10 MHz (d = 0)
bobgiesberts 28:76a2fc42f888 66 **
bobgiesberts 28:76a2fc42f888 67 ** CHx_FIN_DIVIDER = 2 (6.4/2 = 3.2 < 16.0/4 = 4)
bobgiesberts 28:76a2fc42f888 68 ** CHx_FREF_DIVIDER = 1 (16.0 MHz)
bobgiesberts 20:8e1b1efdbb49 69 ************************************/
bobgiesberts 20:8e1b1efdbb49 70
bobgiesberts 29:41815fd13822 71 // Configuring setup, set LDC in configuration modus
bobgiesberts 29:41815fd13822 72 sleep();
bobgiesberts 29:41815fd13822 73
bobgiesberts 28:76a2fc42f888 74 for(int i = 0; i < _channels; i++)
bobgiesberts 28:76a2fc42f888 75 {
bobgiesberts 28:76a2fc42f888 76 // set Reference Count to highest resolution
bobgiesberts 28:76a2fc42f888 77 setReferenceCount( i, _Rcount );
bobgiesberts 18:fc9bb81a631f 78
bobgiesberts 28:76a2fc42f888 79 // set the settling time
bobgiesberts 28:76a2fc42f888 80 // t_settle = (settlecount * 16) /f_REF
bobgiesberts 28:76a2fc42f888 81 setSettlecount( i, _SettleCount );
bobgiesberts 28:76a2fc42f888 82
bobgiesberts 28:76a2fc42f888 83 // set Divider to 1 (for large range / ENOB / resolution)
bobgiesberts 28:76a2fc42f888 84 setDivider( i, 1, 2 ); // IN = 2 | REF = 1
bobgiesberts 28:76a2fc42f888 85
bobgiesberts 28:76a2fc42f888 86 // set the drive current during sampling
bobgiesberts 28:76a2fc42f888 87 setDriveCurrent( i, _DriveCurrent ); // (p. 15 | Figure 14)
bobgiesberts 28:76a2fc42f888 88
bobgiesberts 28:76a2fc42f888 89 // shift the signal down a bit
bobgiesberts 28:76a2fc42f888 90 setOffset( i, _Offset );
bobgiesberts 28:76a2fc42f888 91 }
bobgiesberts 16:07d0e43c2d12 92
bobgiesberts 28:76a2fc42f888 93 // error_config (all is standard)
bobgiesberts 20:8e1b1efdbb49 94
bobgiesberts 28:76a2fc42f888 95 // mux_config
bobgiesberts 28:76a2fc42f888 96 set( MUX_CONFIG, AUTOSCAN_EN, _channels > 1 );
bobgiesberts 29:41815fd13822 97 set( MUX_CONFIG, RR_SEQUENCE, ( ( _channels - 2 > 0 ) ? _channels - 2 : 0 ) );
bobgiesberts 28:76a2fc42f888 98 set( MUX_CONFIG, DEGLITCH, DEGLITCH_10M );
bobgiesberts 18:fc9bb81a631f 99
bobgiesberts 28:76a2fc42f888 100 // override Rp and use own Drive Current to reduce power consumption
bobgiesberts 28:76a2fc42f888 101 set( CONFIG, RP_OVERRIDE_EN, 1 );
bobgiesberts 28:76a2fc42f888 102 set( CONFIG, SENSOR_ACTIVATE_SEL, 1 );
bobgiesberts 28:76a2fc42f888 103 set( CONFIG, AUTO_AMP_DIS, 1 );
bobgiesberts 28:76a2fc42f888 104 set( CONFIG, REF_CLK_SRC, 1 ); // external f_CLKIN
bobgiesberts 28:76a2fc42f888 105 set( CONFIG, INTB_DIS, 1 );
bobgiesberts 28:76a2fc42f888 106 set( CONFIG, HIGH_CURRENT_DRV, 0 );
bobgiesberts 28:76a2fc42f888 107
bobgiesberts 28:76a2fc42f888 108 // Done configuring settings, set LDC1614 in measuring modus
bobgiesberts 28:76a2fc42f888 109 wakeup();
bobgiesberts 16:07d0e43c2d12 110 }
bobgiesberts 16:07d0e43c2d12 111
bobgiesberts 28:76a2fc42f888 112
bobgiesberts 28:76a2fc42f888 113 void LDC1614::func_mode(LDC_MODE mode)
bobgiesberts 28:76a2fc42f888 114 {
bobgiesberts 28:76a2fc42f888 115 switch (mode)
bobgiesberts 28:76a2fc42f888 116 {
bobgiesberts 28:76a2fc42f888 117 case LDC_MODE_ACTIVE:
bobgiesberts 28:76a2fc42f888 118 case LDC_MODE_SLEEP:
bobgiesberts 29:41815fd13822 119
bobgiesberts 29:41815fd13822 120 // turn on oscillator
bobgiesberts 29:41815fd13822 121 _oscillator.write( 1 );
bobgiesberts 29:41815fd13822 122 wait_ms(3); // datasheet oscillator says 3 ms max
bobgiesberts 29:41815fd13822 123
bobgiesberts 29:41815fd13822 124 // turn on LDC
bobgiesberts 28:76a2fc42f888 125 _shutdown_pin.write( 0 );
bobgiesberts 29:41815fd13822 126 set( CONFIG, SLEEP_MODE_EN, mode );
bobgiesberts 29:41815fd13822 127 wait_us(400); // Wait 16384 f_INT clock cycles (0.377 ms) (p.16)
bobgiesberts 28:76a2fc42f888 128 break;
bobgiesberts 28:76a2fc42f888 129
bobgiesberts 28:76a2fc42f888 130 case LDC_MODE_SHUTDOWN:
bobgiesberts 28:76a2fc42f888 131 _shutdown_pin.write( 1 );
bobgiesberts 29:41815fd13822 132 _oscillator.write( 0 );
bobgiesberts 28:76a2fc42f888 133 break;
bobgiesberts 28:76a2fc42f888 134 }
bobgiesberts 19:e205ab9142d8 135 }
bobgiesberts 29:41815fd13822 136 void LDC1614::sleep( void ) { func_mode( LDC_MODE_SLEEP ); }
bobgiesberts 29:41815fd13822 137 void LDC1614::wakeup( void ) { func_mode( LDC_MODE_ACTIVE ); }
bobgiesberts 29:41815fd13822 138 void LDC1614::shutdown( void ) { func_mode( LDC_MODE_SHUTDOWN ); }
bobgiesberts 19:e205ab9142d8 139
bobgiesberts 28:76a2fc42f888 140 void LDC1614::setReferenceCount( uint8_t channel, uint16_t rcount )
bobgiesberts 28:76a2fc42f888 141 {
bobgiesberts 28:76a2fc42f888 142 writeI2Cregister( RCOUNT_CH0 + channel, rcount );
bobgiesberts 25:ae111662ee03 143 }
bobgiesberts 25:ae111662ee03 144
bobgiesberts 28:76a2fc42f888 145 void LDC1614::setOffset( uint8_t channel, uint32_t offset )
bobgiesberts 19:e205ab9142d8 146 {
bobgiesberts 28:76a2fc42f888 147 _Offset = offset;
bobgiesberts 28:76a2fc42f888 148 writeI2Cregister( OFFSET_CH0 + channel, uint16_t (offset >> 16) );
bobgiesberts 19:e205ab9142d8 149 }
bobgiesberts 19:e205ab9142d8 150
bobgiesberts 28:76a2fc42f888 151 void LDC1614::setSettlecount( uint8_t channel, uint16_t settlecount )
bobgiesberts 17:a5cf2b4bec13 152 {
bobgiesberts 28:76a2fc42f888 153 // _t_settle = (settlecount * 16) / (_f_CLKIN / dividerREF[channel])
bobgiesberts 28:76a2fc42f888 154 writeI2Cregister( SETTLECOUNT_CH0 + channel, settlecount );
bobgiesberts 28:76a2fc42f888 155 }
bobgiesberts 28:76a2fc42f888 156
bobgiesberts 28:76a2fc42f888 157 void LDC1614::setDivider( uint8_t channel, uint8_t divIN, uint8_t divREF )
bobgiesberts 28:76a2fc42f888 158 {
bobgiesberts 28:76a2fc42f888 159 // make sure the values fit
bobgiesberts 29:41815fd13822 160 _dividerIN = (( divIN < 15) ? (( divIN > 1) ? divIN : 1) : 15 ); // 4 bit
bobgiesberts 29:41815fd13822 161 _dividerIN = ((divREF < 255) ? ((divREF > 1) ? divREF : 1) : 255 ); // 8 bit
bobgiesberts 28:76a2fc42f888 162 writeI2Cregister( CLOCK_DIVIDERS_CH0 + channel, uint16_t ((_dividerIN << 12) + _dividerREF) );
bobgiesberts 20:8e1b1efdbb49 163 }
bobgiesberts 20:8e1b1efdbb49 164
bobgiesberts 28:76a2fc42f888 165 void LDC1614::setDriveCurrent( uint8_t channel, uint8_t idrive )
bobgiesberts 28:76a2fc42f888 166 {
bobgiesberts 29:41815fd13822 167 _DriveCurrent = ((idrive < 31) ? idrive : 31 ); // 5-bit (b1 1111)
bobgiesberts 29:41815fd13822 168
bobgiesberts 28:76a2fc42f888 169 // todo: read initial idrive [10:6]
bobgiesberts 28:76a2fc42f888 170
bobgiesberts 28:76a2fc42f888 171 writeI2Cregister(DRIVE_CURRENT_CH0 + channel, uint16_t (_DriveCurrent<<10) );
bobgiesberts 25:ae111662ee03 172 }
bobgiesberts 25:ae111662ee03 173
bobgiesberts 28:76a2fc42f888 174 void LDC1614::set( ADDR addr, SETTING setting, uint8_t value )
bobgiesberts 20:8e1b1efdbb49 175 {
bobgiesberts 28:76a2fc42f888 176 uint8_t mask = 1;
bobgiesberts 28:76a2fc42f888 177 if ( addr == MUX_CONFIG )
bobgiesberts 28:76a2fc42f888 178 {
bobgiesberts 28:76a2fc42f888 179 switch (setting){
bobgiesberts 28:76a2fc42f888 180 case AUTOSCAN_EN: mask = 1; break; // 1
bobgiesberts 28:76a2fc42f888 181 case RR_SEQUENCE: mask = 3; break; // 11
bobgiesberts 28:76a2fc42f888 182 case DEGLITCH: mask = 7; break; // 111
bobgiesberts 28:76a2fc42f888 183 }
bobgiesberts 28:76a2fc42f888 184 }
bobgiesberts 28:76a2fc42f888 185 regchange( addr, setting, value, mask );
bobgiesberts 20:8e1b1efdbb49 186 }
bobgiesberts 20:8e1b1efdbb49 187
bobgiesberts 29:41815fd13822 188 uint8_t LDC1614::get( ADDR addr, SETTING setting, uint8_t mask )
bobgiesberts 29:41815fd13822 189 {
bobgiesberts 29:41815fd13822 190 if ( addr == MUX_CONFIG )
bobgiesberts 29:41815fd13822 191 {
bobgiesberts 29:41815fd13822 192 switch (setting){
bobgiesberts 29:41815fd13822 193 case AUTOSCAN_EN: mask = 1; break; // 1
bobgiesberts 29:41815fd13822 194 case RR_SEQUENCE: mask = 3; break; // 11
bobgiesberts 29:41815fd13822 195 case DEGLITCH: mask = 7; break; // 111
bobgiesberts 29:41815fd13822 196 }
bobgiesberts 29:41815fd13822 197 }
bobgiesberts 29:41815fd13822 198
bobgiesberts 29:41815fd13822 199 uint16_t data[1];
bobgiesberts 29:41815fd13822 200 readI2C( data, addr );
bobgiesberts 29:41815fd13822 201 return ( data[0]>>setting ) & mask;
bobgiesberts 29:41815fd13822 202 }
bobgiesberts 29:41815fd13822 203
bobgiesberts 28:76a2fc42f888 204
bobgiesberts 28:76a2fc42f888 205
bobgiesberts 28:76a2fc42f888 206
bobgiesberts 28:76a2fc42f888 207
bobgiesberts 28:76a2fc42f888 208
bobgiesberts 28:76a2fc42f888 209 /* GETTING DATA FROM SENSOR */
bobgiesberts 28:76a2fc42f888 210
bobgiesberts 28:76a2fc42f888 211 uint16_t LDC1614::get_status( void )
bobgiesberts 20:8e1b1efdbb49 212 {
bobgiesberts 28:76a2fc42f888 213 uint16_t status[1];
bobgiesberts 28:76a2fc42f888 214 readI2C( status, STATUS );
bobgiesberts 28:76a2fc42f888 215 return status[0];
bobgiesberts 20:8e1b1efdbb49 216 }
bobgiesberts 29:41815fd13822 217 bool LDC1614::is_ready( uint8_t status )
bobgiesberts 29:41815fd13822 218 {
bobgiesberts 29:41815fd13822 219 if( status == 17 ) { status = get_status(); }
bobgiesberts 29:41815fd13822 220 return ( status>>DRDY ) & 1;
bobgiesberts 29:41815fd13822 221 }
bobgiesberts 29:41815fd13822 222 bool LDC1614::is_error( uint8_t status )
bobgiesberts 29:41815fd13822 223 {
bobgiesberts 29:41815fd13822 224 if( status == 17 ) { status = get_status(); }
bobgiesberts 30:95c53d244f91 225 return ((( status>>ERR_ZC ) & 6) == 0);
bobgiesberts 29:41815fd13822 226 }
bobgiesberts 17:a5cf2b4bec13 227
bobgiesberts 17:a5cf2b4bec13 228
bobgiesberts 28:76a2fc42f888 229 uint16_t LDC1614::get_Rcount( uint8_t channel )
bobgiesberts 16:07d0e43c2d12 230 {
bobgiesberts 28:76a2fc42f888 231 uint16_t rcount[1];
bobgiesberts 28:76a2fc42f888 232 readI2C( rcount, RCOUNT_CH0 + channel );
bobgiesberts 28:76a2fc42f888 233 return rcount[0];
bobgiesberts 20:8e1b1efdbb49 234 }
bobgiesberts 20:8e1b1efdbb49 235
bobgiesberts 28:76a2fc42f888 236 uint32_t LDC1614::get_Data( uint8_t channel )
bobgiesberts 22:8da965ce5af3 237 {
bobgiesberts 28:76a2fc42f888 238 uint16_t data[2];
bobgiesberts 30:95c53d244f91 239 readI2C( data, DATA_MSB_CH0 + channel, 2 );
bobgiesberts 29:41815fd13822 240
bobgiesberts 29:41815fd13822 241 if( ((data[0]>>CHx_ERR_UR) & 1) == 1 ) { debug( "Under-range Error" ); }
bobgiesberts 29:41815fd13822 242 if( ((data[0]>>CHx_ERR_OR) & 1) == 1 ) { debug( "Over-range Error" ); }
bobgiesberts 29:41815fd13822 243 if( ((data[0]>>CHx_ERR_WD) & 1) == 1 ) { debug( "Watchdog Timeout Error" ); }
bobgiesberts 29:41815fd13822 244 if( ((data[0]>>CHx_ERR_AE) & 1) == 1 ) { debug( "Amplitude Error" ); }
bobgiesberts 29:41815fd13822 245
bobgiesberts 30:95c53d244f91 246 return ( (data[0] & 0x0fff)<<16 ) | data[1]; // MSB + LSB
bobgiesberts 22:8da965ce5af3 247 }
bobgiesberts 20:8e1b1efdbb49 248
bobgiesberts 28:76a2fc42f888 249
bobgiesberts 28:76a2fc42f888 250
bobgiesberts 30:95c53d244f91 251
bobgiesberts 30:95c53d244f91 252
bobgiesberts 30:95c53d244f91 253
bobgiesberts 29:41815fd13822 254 /* REGISTER FUNCTIONS (READ / WRITE) */
bobgiesberts 28:76a2fc42f888 255
bobgiesberts 28:76a2fc42f888 256 void LDC1614::readI2C( uint16_t *data, uint8_t address, uint8_t length )
bobgiesberts 22:8da965ce5af3 257 {
bobgiesberts 28:76a2fc42f888 258 // I2C reads per 8-bits, char is 8-bit, combine 8-bit in 16-bit sets
bobgiesberts 28:76a2fc42f888 259 char temp[length*2];
bobgiesberts 28:76a2fc42f888 260 _i2c.read( address, temp, length*2 );
bobgiesberts 28:76a2fc42f888 261
bobgiesberts 28:76a2fc42f888 262 for ( int i = 0; i < length; i++ )
bobgiesberts 28:76a2fc42f888 263 data[i] = (uint16_t) (temp[2*i+1]<<8) | temp[2*i];
bobgiesberts 22:8da965ce5af3 264 }
bobgiesberts 20:8e1b1efdbb49 265
bobgiesberts 28:76a2fc42f888 266 void LDC1614::writeI2C( uint16_t *data, uint8_t address, uint8_t length )
bobgiesberts 22:8da965ce5af3 267 {
bobgiesberts 28:76a2fc42f888 268 // I2C reads per 8-bits, char is 8-bit, split 16-bit data up in sets of 8-bit
bobgiesberts 28:76a2fc42f888 269 char temp[length*2];
bobgiesberts 28:76a2fc42f888 270 for ( int i = 0; i < length; i++ )
bobgiesberts 28:76a2fc42f888 271 {
bobgiesberts 28:76a2fc42f888 272 temp[2*i] = (data[i] & 0x00ff) >> 0; // 0, 2, 4 ...
bobgiesberts 28:76a2fc42f888 273 temp[2*i+1] = (data[i] & 0xff00) >> 8; // 1, 3, 5 ...
bobgiesberts 28:76a2fc42f888 274 }
bobgiesberts 28:76a2fc42f888 275 _i2c.write( address, temp, length*2 );
bobgiesberts 22:8da965ce5af3 276 }
bobgiesberts 20:8e1b1efdbb49 277
bobgiesberts 28:76a2fc42f888 278 void LDC1614::writeI2Cregister(uint8_t reg, uint16_t value)
bobgiesberts 28:76a2fc42f888 279 {
bobgiesberts 28:76a2fc42f888 280 writeI2C( &value, reg );
bobgiesberts 28:76a2fc42f888 281 }
bobgiesberts 28:76a2fc42f888 282
bobgiesberts 28:76a2fc42f888 283 void LDC1614::regchange( uint8_t addr, uint8_t setting, uint8_t value, uint8_t mask )
bobgiesberts 28:76a2fc42f888 284 {
bobgiesberts 28:76a2fc42f888 285 uint16_t config[1];
bobgiesberts 28:76a2fc42f888 286 readI2C( config, addr );
bobgiesberts 28:76a2fc42f888 287 writeI2Cregister( addr, uint16_t ( (config[0] & !(mask<<setting)) | (value<<setting)) ); // replace bits with number SETTING
bobgiesberts 28:76a2fc42f888 288 }
bobgiesberts 28:76a2fc42f888 289
bobgiesberts 28:76a2fc42f888 290
bobgiesberts 25:ae111662ee03 291
bobgiesberts 25:ae111662ee03 292 /* CALCULATE STUFF WITH SENSOR DATA */
bobgiesberts 25:ae111662ee03 293
bobgiesberts 28:76a2fc42f888 294 float LDC1614::get_fsensor( uint32_t LData )
bobgiesberts 28:76a2fc42f888 295 {
bobgiesberts 28:76a2fc42f888 296 _fsensor = _dividerIN * (_fCLKIN/_dividerREF) * ((LData / 268435456) + (_Offset / 65536)); // (p.14)
bobgiesberts 18:fc9bb81a631f 297 return _fsensor;
bobgiesberts 19:e205ab9142d8 298 }
bobgiesberts 18:fc9bb81a631f 299
bobgiesberts 28:76a2fc42f888 300 float LDC1614::get_Inductance( uint32_t Ldata )
bobgiesberts 18:fc9bb81a631f 301 {
bobgiesberts 25:ae111662ee03 302 float fsensor = get_fsensor( Ldata );
bobgiesberts 28:76a2fc42f888 303 _inductance = 1.0 / (_cap * 4 * PI*PI * fsensor*fsensor ); // ???
bobgiesberts 19:e205ab9142d8 304 return _inductance;
bobgiesberts 19:e205ab9142d8 305 }
bobgiesberts 16:07d0e43c2d12 306
bobgiesberts 16:07d0e43c2d12 307
bobgiesberts 16:07d0e43c2d12 308
bobgiesberts 16:07d0e43c2d12 309 // EXTRA test: Get&print values of all variables to verify (to calculate the induction)
bobgiesberts 16:07d0e43c2d12 310 // The data will be printed on the screen using RealTerm: baud 9600.
bobgiesberts 16:07d0e43c2d12 311 // Begin ***********************************************************
bobgiesberts 28:76a2fc42f888 312 float LDC1614::get_fCLKIN() {return _fCLKIN;}
bobgiesberts 28:76a2fc42f888 313 uint8_t LDC1614::get_dividerIN() {return _dividerIN;}
bobgiesberts 28:76a2fc42f888 314 uint8_t LDC1614::get_dividerREF() {return _dividerREF;}
bobgiesberts 28:76a2fc42f888 315 uint32_t LDC1614::get_Offset() {return _Offset;}
bobgiesberts 28:76a2fc42f888 316 float LDC1614::get_cap() {return _cap;}
bobgiesberts 16:07d0e43c2d12 317 // END ***********************************************************