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 1:a88df80e7664, committed 2015-04-29
- Comitter:
- hamid567
- Date:
- Wed Apr 29 14:57:22 2015 +0000
- Parent:
- 0:90873b4e8330
- Child:
- 2:44b76f6f19d5
- Commit message:
- Corrected read and write actions
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 Sun Apr 05 18:19:12 2015 +0000 +++ b/LDC1000.cpp Wed Apr 29 14:57:22 2015 +0000 @@ -17,9 +17,11 @@ _spiport.format(8,3); _spiport.frequency(1E6); _cs_pin.write(1); + wait_us(100); + mode(LDC_MODE_ACTIVE); + wait_us(10); setFrequency(f_external); setResponseTime(LDC_RESPONSE_384); - mode(LDC_MODE_ACTIVE); } void LDC1000::setOutputPower(LDC_AMPLITUDE amplitude) @@ -33,6 +35,8 @@ } + + void LDC1000::setResponseTime(LDC_RESPONSE responsetime) { uint8_t buffer; @@ -46,6 +50,7 @@ void LDC1000::setFrequency(float frequency) { _frequency = frequency; + _clock.write(0.5); _clock.period(1.0/frequency); } @@ -75,7 +80,7 @@ _spiport.write(address | 0x80); //read flag for(int i=0; i < num_bytes ; i++) { - _spiport.write(data[i]); + data[i] = _spiport.write(0xFF); } _cs_pin.write(1); } @@ -86,7 +91,7 @@ _spiport.write(address); for(int i=0; i < num_bytes ; i++) { - *data = _spiport.write(0xFF); + _spiport.write(data[i]); } _cs_pin.write(1); } \ No newline at end of file
--- a/LDC1000.h Sun Apr 05 18:19:12 2015 +0000 +++ b/LDC1000.h Wed Apr 29 14:57:22 2015 +0000 @@ -29,7 +29,7 @@ LDC_AMPLITUDE_2V, \ LDC_AMPLITUDE_4V} LDC_AMPLITUDE; -typedef enum { LDC_MODE_STANDBY = 0; LDC_MODE_ACTIVE = 1} LDC_MODE; +typedef enum { LDC_MODE_STANDBY = 0, LDC_MODE_ACTIVE = 1} LDC_MODE; /** @@ -49,7 +49,7 @@ * The constructor sets the LDC1000 in Active mode. * @param mode choose from LDC_MODE_ACTIVE or LDC_MODE STANDBY **/ - void mode(LDC_MODE mode){writeSPI(&mode, 0x0B);}; + void mode(LDC_MODE mode){writeSPI((uint8_t *)(&mode), 0x0B);}; /** * @brief get the calculated inductance value **/ @@ -88,8 +88,8 @@ * - LDC_AMPLITUDE_2V * - LDC_AMPLITUDE_4V **/ - enable power void setOutputPower(LDC_AMPLITUDE amplitude); + private: void readSPI(uint8_t *data, uint8_t address, uint8_t num_bytes = 1); void writeSPI(uint8_t *data, uint8_t address, uint8_t num_bytes = 1);