Library for LTC2460 ADC converter

Files at this revision

API Documentation at this revision

Comitter:
igbt6
Date:
Mon May 11 09:28:24 2015 +0000
Commit message:
first version of library for LTC2460 ADC converter

Changed in this revision

ltc2460.cpp Show annotated file Show diff for this revision Revisions of this file
ltc2460.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 7f26ce7f8ff5 ltc2460.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ltc2460.cpp	Mon May 11 09:28:24 2015 +0000
@@ -0,0 +1,50 @@
+#include "ltc2460.h"
+
+
+LTC2460::LTC2460(PinName csPin , PinName mosiPin, PinName misoPin, PinName sckPin,double resDividerVal ): mCSpin(csPin), mSpi(mosiPin, misoPin, sckPin){
+    
+     mResDividerVal= resDividerVal ;
+    if(!initLTC2460()){}; //while(1); //TODO handle error
+
+}   
+    
+    
+bool LTC2460::initLTC2460(void){     
+   //  uint8_t  data;
+    // Setup the spi for 16 bit data
+    // second edge capture, with a 1MHz clock rate
+     mSpi.format(16,0);
+     mSpi.frequency(1000000);
+     return true;
+}
+
+
+uint16_t LTC2460::spiRead(void)
+{
+    __disable_irq();    // Disable Interrupts
+    mCSpin=0;
+    uint16_t val = mSpi.write(0); // The written value is ignored, reg value is read
+    mCSpin = 1;
+    __enable_irq();     // Enable Interrupts
+    return val;
+}
+
+void LTC2460::spiWrite(uint16_t value)
+{
+    __disable_irq();    // Disable Interrupts
+    mCSpin = 0;
+    mSpi.write(value); // New value follows
+    mCSpin= 1;
+    __enable_irq();     // Enable Interrupts
+}
+
+float LTC2460::readVoltage()
+{  
+  
+   uint16_t rawData=spiRead() ;
+   float temp = (float)((1.25/0xFFFF)*rawData);
+   float val = temp*mResDividerVal+temp;
+   return val;
+}
+
+
diff -r 000000000000 -r 7f26ce7f8ff5 ltc2460.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ltc2460.h	Mon May 11 09:28:24 2015 +0000
@@ -0,0 +1,75 @@
+/*
+  @file LTC2460.h
+  
+  @brief LTC2460 - Ultra-Tiny, 16-Bit ΔΣ ADCs with 10ppm/°C Max Precision Reference
+         Breakout SPI Library      
+
+  @Author lukasz uszko(luszko@op.pl)
+
+  Tested on FRDM-KL46Z and FRDM-KL25Z
+  
+  Copyright (c) 2015 lukasz uszko
+  Released under the MIT License (see http://mbed.org/license/mit)
+
+  Documentation regarding the  LTC2460 might be found here: 
+  http://www.linear.com/product/LTC2460
+*/
+
+
+
+#ifndef LTC2460_H
+#define LTC2460_H
+
+#include "mbed.h"
+
+
+class LTC2460{
+      
+      
+ /**********private members and methods********************************/       
+ private: 
+ 
+        DigitalOut          mCSpin;
+        SPI                 mSpi;
+        double mResDividerVal;
+
+
+   /**********public methods********************************/
+    public:
+
+    /** Constructor- Creates an LTC2460 instance
+     * @param cs pin 
+     * @param mosi pin 
+     * @param miso pin
+     * @param sck  pin
+     */
+    LTC2460(PinName csPin , PinName mosiPin, PinName misoPin, PinName sckPin,double resDividerVal=0 ); 
+
+
+    /** Initialization: set member values and configuration registers, ought to be invoked in the body of constructor 
+     * @returns
+     *    true on success,
+     *    false on error
+     */
+    bool initLTC2460(void);
+
+
+    /*reading , writing registers
+    
+    */
+    uint16_t spiRead(void);
+
+    void spiWrite(uint16_t value);
+
+    /** Read volatge real value from ADC , with .
+     * @param resistor divider value: GND---- R1 ----- ADC-----R2--- Vmeasured    --> resDividerVal = R1/R2
+     * @returns
+     *   value of voltage measured voltage 
+     */    
+    float readVoltage();
+   
+
+    
+};
+
+#endif
\ No newline at end of file