Library to communicate with LDC1614
Dependents: Inductive_Sensor_3
Fork of LDC1101 by
Diff: LDC1101.cpp
- Revision:
- 17:a5cf2b4bec13
- Parent:
- 16:07d0e43c2d12
- Child:
- 18:fc9bb81a631f
--- a/LDC1101.cpp Thu Dec 10 15:12:16 2015 +0000 +++ b/LDC1101.cpp Sat Dec 12 11:26:23 2015 +0000 @@ -12,7 +12,7 @@ #include "LDC1101.h" -LDC1101::LDC1101(PinName mosi, PinName miso, PinName sck, PinName cs, float capacitor, float f_external, PinName clock_out) : _spiport(mosi,miso,sck, NC), _cs_pin(cs), _clock(clock_out,1) +LDC1101::LDC1101(PinName mosi, PinName miso, PinName sck, PinName cs, float capacitor, float f_external, PinName clock_out) : _spiport(mosi,miso,sck, NC), _cs_pin(cs)//, _clock(clock_out,1) { cap = capacitor; @@ -36,6 +36,7 @@ wait_us(10); setResponseTime(LDC_RESPONSE_6144); + setDivider(DIVIDER_1); // L-Only Measurement writeSPIregister(0x05, 0x03); // ALT_CONFIG: clock config >> we get 0x00 if this line is disabled and the cable is reconnected @@ -55,11 +56,18 @@ writeSPIregister(0x04, responsetime); } +void LDC1101::setDivider(DIVIDER div) +{ + // _divider = (float) pow(2, div); + writeSPIregister(0x34, div); +} + + void LDC1101::setFrequency(float frequency) { _frequency = frequency; - _clock.period(1.0/frequency); - _clock.pulsewidth(0.5/frequency); + //_clock.period(1.0/frequency); + //_clock.pulsewidth(0.5/frequency); } float LDC1101::getInductance() @@ -67,10 +75,14 @@ uint16_t resp[] = {0,0,192, 384, 768, 1536, 3072, 6144}; _raw_l = readRawCounts(); - // f_CLKIN * RESP_TIME - // ------------------- - // 3 * L_DATA - _fsensor = (_frequency/(_raw_l*3.0))*resp[(uint8_t)(_responsetime)]; + // f_CLKIN * RESP_TIME + // f_sensor = ------------------- + // 3 * L_DATA + _fsensor = 1 *(_frequency/(_raw_l*3.0))*resp[(uint8_t)(_responsetime)]; + + // 2^SENSORDIV * f_CLKIN(L_DATA + LHROFFSET*2^8) + // f_sensor = --------------------------------------------- + // 2^24 // 1 // --------------------- --> p. 31