Library to work with the LDC1000 from Texas Instruments
LDC1000
This library was written to interface to Texas Instruments' LDC1000 in order to perform inductance measurement. This libary needs a SPI peripheral on your mbed device to talk to the LDC1000.
Clock
The LDC1000 needs a high speed clock for its internal frequency counter. In order to provide this clock, the FastPWM library is used. This may change the behaviour of other PWM channels, please be aware of that, and read the FastPWM documentation to understand the implications.
Unsupported
Not supported (yet):
- Setting the RpMAX and RpMIN values
- Setting the interrupt pin functionality
Revision 8:b5fb9681869c, committed 2015-05-29
- Comitter:
- hamid567
- Date:
- Fri May 29 09:28:46 2015 +0000
- Parent:
- 7:7f1522ad3df5
- Child:
- 9:6e2d808b113d
- Commit message:
- Working program but with not the right return data from readCounts()
Changed in this revision
LDC1000.cpp | Show annotated file Show diff for this revision Revisions of this file |
LDC1000.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LDC1000.cpp Tue May 26 14:50:16 2015 +0000 +++ b/LDC1000.cpp Fri May 29 09:28:46 2015 +0000 @@ -20,27 +20,28 @@ wait_us(100); mode(LDC_MODE_STANDBY); setFrequency(f_external); - wait(0.1); - //setOutputPower(LDC_AMPLITUDE_4V); + wait(0.1); wait_us(10); - //setResponseTime(LDC_RESPONSE_384); - //setWatchdog(5000); + + setWatchdog(5000); + setResponseTime(LDC_RESPONSE_6144); + setOutputPower(LDC_AMPLITUDE_4V); -// Write comando's like in EVM start log: - //writeSPIregister(0x0B,0x00); - //writeSPIregister(0x01,0x0E); - //writeSPIregister(0x02,0x3C); +//*** Write comando's like in EVM start log: +/* writeSPIregister(0x0B,0x00); */ + writeSPIregister(0x01,0x0E); + writeSPIregister(0x02,0x3C); writeSPIregister(0x03,0x15); - writeSPIregister(0x04,0x17); - writeSPIregister(0x05,0x00); - //writeSPIregister(0x06,0x50); - //writeSPIregister(0x07,0x14); - //writeSPIregister(0x08,0xC0); - //writeSPIregister(0x09,0x12); - //writeSPIregister(0x0A,0x04); -// writeSPIregister(0x0C,0x01); - //writeSPIregister(0x0B,0x01); - + writeSPIregister(0x04,0x17); + writeSPIregister(0x05,0x00); + writeSPIregister(0x06,0x50); + writeSPIregister(0x07,0x14); + writeSPIregister(0x08,0xC0); + writeSPIregister(0x09,0x12); + writeSPIregister(0x0A,0x04); + writeSPIregister(0x0C,0x01); + writeSPIregister(0x0B,0x01);/* +*/ mode(LDC_MODE_ACTIVE); } @@ -50,7 +51,7 @@ _amplitude = amplitude; readSPI(&buffer, 0x04); buffer &= 0xE7; //clear amplitude bits - buffer |= (amplitude<<3) & 0xE7; + buffer |= (amplitude<<3) & 0x18; writeSPI(&buffer,0x04); } @@ -60,7 +61,6 @@ uint8_t buffer; buffer = 68.94*log(frequency/2500); writeSPI(&buffer,0x03); - } void LDC1000::setResponseTime(LDC_RESPONSE responsetime) @@ -70,6 +70,7 @@ readSPI(&buffer, 0x04); buffer &= 0xF8; //clear responsetime bits buffer |= responsetime & 0x07; + //writeSPIregister(0x04,buffer); writeSPI(&buffer,0x04); } @@ -82,12 +83,33 @@ float LDC1000::getInductance() { - uint16_t resp[] = {192, 384, 768, 1536, 3072, 6144}; + uint16_t resp[] = {0,0,192, 384, 768, 1536, 3072, 6144}; _raw_l = readRawCounts(); _fsensor = (_frequency/(_raw_l*3.0))*resp[(uint8_t)(_responsetime)]; return 1./(cap*pow(2*PI*_fsensor,2)); }; + +/* oude code terugzetten*/ + +uint32_t LDC1000::readRawCounts(void) +{ + //union + //{ + // uint8_t buf[4]; + // uint32_t value; + //} val; + //val.value = 0; + uint8_t val[5]; + readSPI(val,0x21,5); + return (uint32_t)(*(&val[2])); +} + + + + + + /* uint32_t LDC1000::readRawCounts(void) { union @@ -95,13 +117,11 @@ uint8_t buf[4]; uint32_t value; } val; - val.value = 0; - uint8_t bla[5]; - readSPI(bla,0x21,5); + val.value = 8; + readSPI(val.buf,0x23,3); return val.value; } - - +*/ void LDC1000::readSPI(uint8_t *data, uint8_t address, uint8_t num_bytes) { @@ -123,4 +143,20 @@ _spiport.write(data[i]); } _cs_pin.write(1); -} \ No newline at end of file +} + +// EXTRA test get and print variables values to verify (to calculate the induction) +// Begin *********************************************************** + float LDC1000::get_raw_l() {_raw_l = readRawCounts(); + return _raw_l;}; + float LDC1000::get_fsensor() { + uint16_t resp[] = {0, 0, 192, 384, 768, 1536, 3072, 6144}; + _raw_l = readRawCounts(); + _fsensor = (_frequency/(_raw_l*3.0))*resp[(uint8_t)(_responsetime)]; + return _fsensor;}; + + float LDC1000::get_frequency() {return _frequency;}; + float LDC1000::get_responsetime() {return _responsetime;}; + float LDC1000::get_cap() {return cap;}; +// END *********************************************************** +
--- a/LDC1000.h Tue May 26 14:50:16 2015 +0000 +++ b/LDC1000.h Fri May 29 09:28:46 2015 +0000 @@ -20,7 +20,7 @@ #endif typedef enum { LDC_RESPONSE_192=2,\ - LDC_RESPONSE_384, \ + LDC_RESPONSE_384= 3, \ LDC_RESPONSE_768, \ LDC_RESPONSE_1536, \ LDC_RESPONSE_3072, \ @@ -58,6 +58,16 @@ * @brief get the calculated inductance value **/ float getInductance(void); + + + // EXTRA test get variables values to verify (to calculate the induction) + float get_raw_l(void); + float get_fsensor(void); + float get_frequency(void); + float get_responsetime(void); + float get_cap(void); + + /** * @brief Set the value of the external capacitor * This is needed for the calculation of the inductance. @@ -74,8 +84,6 @@ **/ uint32_t readRawL(void){_raw_l = readRawCounts(); return _raw_l;}; - // EXTRA test Read INTB register - uint32_t readINTBregister(void){INTB = readINTB(); return INTB;}; /** * @brief Set the Response Time parameters.