Bob Giesberts / LDC1101

Dependents:   Inductive_Sensor Inductive_Sensor_Jasper Inductive_Sensor_3

Fork of LDC1000 by First Last

Revision:
20:8e1b1efdbb49
Parent:
19:e205ab9142d8
Child:
22:8da965ce5af3
--- a/LDC1101.h	Wed Dec 16 16:25:33 2015 +0000
+++ b/LDC1101.h	Fri Dec 18 15:49:12 2015 +0000
@@ -1,14 +1,13 @@
 #ifndef _LDC1101_H_
 #define _LDC1101_H_
 
-#include "FastPWM.h"
 /**
 * @file LDC1101.h
 * @brief this header file will contain all required
 * definitions for the functions to interface with Texas
 * Instruments' LDC1101.
 *
-* @author Victor Sluiter
+* @author Victor Sluiter & Bob Giesberts
 *
 * @date 2015-12-09
 */
@@ -62,22 +61,24 @@
         * The constructor sets the LDC1101 in Active mode.
         * @param mode choose from LDC_MODE_ACTIVE, LDC_MODE STANDBY or LDC_MODE_SHUTDOWN
         **/
-        void func_mode(LDC_MODE mode) { writeSPI((uint8_t *)(&mode), 0x0B); };
-    
+        void func_mode(LDC_MODE mode);
+        /**
+        * @brief Set LDC1101 to lowest power setting
+        **/
+        void sleep(void);
+        /**
+        * @brief Get LDC1101 to work for you again
+        **/
+        void wakeup(void);
         /**
         * @brief initial configurations
         **/
         void init(void);
-        
         /**
         * @brief initialises LHR mode
         * Also enables shutdown modus
         **/
-        void setLHRmode(void)
-        {
-            writeSPIregister(0x05, 0x03); // ALT_CONFIG:  0000 0011 --> LHR modus + Shutdown enabled
-            writeSPIregister(0x0C, 0x01); // D_CONFIG:    Enables a function that can improve L measurements while disabling RP measurements 
-        };
+        void setLHRmode(void);
         
         /**
         * @brief Settings for RP
@@ -105,8 +106,8 @@
         /**
         * @brief Sensor divider (p.26)
         * Sensor input divider         (p.35)
-        * Because f_CLKIN > 4*f_sensor is not realisable for higher frequencies, so there is a divider
-        * f_CLKIN > 4 * f_sensor / SENSOR_DIV
+        * Because f_CLKIN > 4*f_sensor_max is not realisable for higher frequencies, so there is a divider
+        * f_CLKIN > 4 * f_sensor_max / SENSOR_DIV
         * @param div 
         * - DIVIDER_1
         * - DIVIDER_2
@@ -133,16 +134,27 @@
         
         /** 
         * @brief Set the Reference Count parameter.
-        * @param LHR_Count
+        * @param LHR_RCount
         * For LHR mode, the conversion time is set by the reference count LHR_RCOUNT (0x30 & 0x31) (p.34)
         * The conversion time represents the number of clock cycles used to measure the sensor frequency.
         * Higher values for LHR_RCOUNT have a higher effective measurement resolution but a lower sample rate. (p.34)
         * The maximum setting (0xffff) is required for full resolution (p. 35)
-        * 1) LHR_Count = 1/sample rate [kS/s] - 55/f_CLKIN
-        * 2) The reference count value must be chosen to support the required number of effective bits (ENOB).
-        *    e.g. ENOB 13 bits --> minimum converstion time 2^13 = 8192 clock cycles required. 8192 = 0x2000 = RCOUNT.
+        * LHR_RCount = (f_CLKIN/sample rate - 55)/16
+        **/
+        void setReferenceCount(uint16_t LHR_RCount);
+
+        /**
+        * @brief Set the rample rate (indirectly set the reference count)
         **/
-        void setReferenceCount(uint16_t LHR_Count);
+        void setSampleRate( float samplerate );
+        
+        /**
+        * @brief Set the minimum sensor frequency (so without any target)
+        * @param f_sensor_min
+        * in MHz
+        **/
+        void setf_sensorMin(float f_sensor_min);
+
         /**
         * @brief Set the value of the external capacitor
         * This is needed for the calculation of the inductance.
@@ -155,6 +167,9 @@
         void setFrequency(float frequency){_fCLKIN = frequency;};
 
 
+
+
+
         /**
         * @brief Read LHR_Data, the raw 24-bit inductance value.
         * This is needed for the calculation of the inductance.
@@ -176,7 +191,7 @@
         /**
         * @brief get the responsetime
         **/
-        uint16_t get_responsetime(void);
+        uint16_t get_responsetime(void) { uint16_t resps[] = {0, 0, 192, 384, 768, 1536, 3072, 6144}; uint8_t resp[1]; readSPI(resp, 0x04, 1); return resps[(resp[0] & 0x07)]; };
         /**
         * @brief get RPmin
         **/
@@ -184,7 +199,7 @@
         /**
         * @brief get the reference count
         **/
-        uint16_t get_Rcount(void);
+        uint16_t get_Rcount(void) { uint8_t rcount[2]; readSPI(rcount, 0x30, 2); return ((rcount[1] << 8) | rcount[0]); };
         /**
         * @brief get the divider
         **/
@@ -208,8 +223,8 @@
         void writeSPI(uint8_t *data, uint8_t address, uint8_t num_bytes = 1);
         void writeSPIregister(uint8_t reg, uint8_t value){writeSPI(&value,reg);}; // VERKEERD OM?!
         
-        uint32_t readINTB(void); // EXTRA UNTB Read register
-        uint32_t INTB; // extra: read register INTB
+        // uint32_t readINTB(void); // EXTRA UNTB Read register
+        // uint32_t INTB; // extra: read register INTB
         
         uint16_t _responsetime; // Response Time
         uint8_t _divider;       // divider