Lib LTC2944

Fork of LTC2944 by ltc2944_team

Files at this revision

API Documentation at this revision

Comitter:
gr66
Date:
Wed May 17 18:45:40 2017 +0000
Parent:
0:ec69fa9832e5
Commit message:
Test 2944

Changed in this revision

AS5600.cpp Show diff for this revision Revisions of this file
AS5600.h Show diff for this revision Revisions of this file
LTC2944.cpp Show annotated file Show diff for this revision Revisions of this file
LTC2944.h Show annotated file Show diff for this revision Revisions of this file
diff -r ec69fa9832e5 -r 378dc5a174ce AS5600.cpp
--- a/AS5600.cpp	Tue Feb 28 12:26:56 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-// AS5600 Verson 1.3
-// 20/03/2015  GR : fonction limitant la dynamique autour de zero à -max , +max
-#include "AS5600.h"
-//#include "mbed.h"
-
-
-
-AS5600::AS5600(PinName sda, PinName scl) : i2c(sda,scl)
-{
-    addresse=0x36;
-    i2c.frequency(400000);
-}
-int AS5600::isMagnetPresent()
-{
-    char cmd=0x0B,data=0,value=0;
-    data=this->read(cmd);
-    value=(char) (data & 0x20) >> 5 ;
-
-    return value;
-}
-
-
-int AS5600::getAngleAbsolute()
-{
-    char cmd1=0x0E,cmd2=0x0F;
-    int data=0;
-
-    data=this->read(cmd1) << 8;
-    data=data+this->read(cmd2);
-
-    return data;
-}
-
-int AS5600::getAngleRelative()
-{
-    return ((this->getAngleAbsolute() + (2047 - relative_zero)) % 4096) - 2047;
-}
-
-
-float AS5600::getAngleDegrees()
-{
-    return ((float)this->getAngleRelative() * 180) / 2048 ;
-}
-
-void AS5600::setZero()
-{
-    relative_zero=0;
-    relative_zero=this->getAngleAbsolute();
-}
-
-
-char AS5600::read(char address)
-{
-    char retval;
-    i2c.write(addresse * 2, &address, 1);
-    i2c.read(addresse * 2, &retval, 1);
-    return retval;
-}
-
-void AS5600::init()
-{
-
-    for (int i=0; i<100; i++)
-        this->setZero();
-
-}
-
-float AS5600::getAngleMinMax(float angleMax)
-{
-    static unsigned char etat=0;           // etat de l'automate
-    static int anglePrec=0;                // angle precedent
-    float angle=0;                         // angle courant
-    float angleX=0;                        //angle en sortie borne
-    //
-    angle=this->getAngleDegrees();         // lecture de l'angle courant
-    switch(etat) {
-        case 0 :    // angle compris entre min et max
-            angleX = angle;
-            if(angle > angleMax)  etat = 2;
-            if(angle < -angleMax) etat = 1;
-            break;
-        case 1 :    // angle inferieur a -max
-            angleX = -angleMax;
-            if((anglePrec <= -angleMax) && (angle >= -angleMax) && (angle < 0)) etat = 0;
-            break;
-        case 2 :
-            angleX = angleMax;
-            if((anglePrec >=  angleMax) && (angle <= angleMax) && (angle > 0))etat = 0;
-            break;
-        default :
-            break;
-    }
-    anglePrec=angle;
-    return angleX;
-}
\ No newline at end of file
diff -r ec69fa9832e5 -r 378dc5a174ce AS5600.h
--- a/AS5600.h	Tue Feb 28 12:26:56 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-
-#include "mbed.h"  
-
-
-
-class AS5600 {
-    public:
-    AS5600(PinName sda, PinName scl);
-    float getAngleDegrees();
-    int getAngleAbsolute();
-    int getAngleRelative();
-    float getAngleMinMax(float angleMax);
-    
-    int isMagnetPresent();
-    
-    void init();
-    void setZero();
-    
-    private:
-    char read(char address);
-    I2C i2c;
-    unsigned char addresse;
-    int relative_zero  ;
-    };
-
-
-
diff -r ec69fa9832e5 -r 378dc5a174ce LTC2944.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LTC2944.cpp	Wed May 17 18:45:40 2017 +0000
@@ -0,0 +1,113 @@
+// LTC2944 V1.0
+// 07/03/2017  GR :
+#include "LTC2944.h"
+//Serial pc(USBTX, USBRX);  // I/O terminal PC
+
+
+
+LTC2944::LTC2944(PinName sda, PinName scl) : i2c(sda,scl),pc(USBTX, USBRX)
+{
+    address=0xC8;   // adresse I2C
+    //i2c.frequency(400000);
+}
+void LTC2944::setRsense(float r)
+{
+    rsense=r;
+}
+//
+void LTC2944::setMode(unsigned char m)
+{
+    dataw[0]=0x01;  // registre B control
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,1);    // lecture du registre
+    pc.printf("valm1 %x \n",datar[0]);
+    dataw[1]=(datar[0]&~0xC0)|(m<<6);
+    i2c.write(address,dataw,2);  // ecriture
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,1);    // lecture du registre
+    pc.printf("valm2 %x \n",datar[0]);
+}
+//
+void LTC2944::setPrescaler(unsigned char p)
+{
+    dataw[0]=0x01;  // registre B control
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,1);    // lecture du registre
+    pc.printf("valp1 %x \n",datar[0]);
+    dataw[1]=(datar[0]&~0x38)|(p<<3);
+    i2c.write(address,dataw,2);  // ecriture
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,1);    // lecture du registre
+    pc.printf("valp2 %x \n",datar[0]);
+}
+//
+void LTC2944::setImin(float imin)
+{
+    dataw[0]=0x12;  // registre B control
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,2);    // lecture du registre
+    pc.printf("valImin1 %x %x \n",datar[0],datar[1]);
+    short val=(short)((imin*rsense*32767/64)+32767);
+    dataw[1]=(char)(val>>8);
+    dataw[2]=(char)(val&0x00FF);
+    i2c.write(address,dataw,3);  // ecriture
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,2);    // lecture du registre
+    pc.printf("valmin2 %x %x \n",datar[0],datar[1]);
+}
+
+void LTC2944::setImax(float imin)
+{
+    dataw[0]=0x10;  // registre B control
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,2);    // lecture du registre
+    pc.printf("valImax1 %x %x \n",datar[0],datar[1]);
+    short val=(short)((imin*rsense*32767/64)+32767);
+    dataw[1]=(char)(val>>8);
+    dataw[2]=(char)(val&0x00FF);
+    i2c.write(address,dataw,3);  // ecriture
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,2);    // lecture du registre
+    pc.printf("valmax2 %x %x \n",datar[0],datar[1]);
+}
+//
+float LTC2944::getVoltage(void)
+{
+    dataw[0]=8;  // adresse de la tension
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,2);    // lecture du registre de deux octets
+    return((((unsigned short)(datar[0])<<8)+datar[1])*70.8/0xFFFF);
+}
+
+float LTC2944::getCurrent(void)
+{
+    dataw[0]=0xE;  // adresse de la tension
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,2);    // lecture du registre de deux octets
+    unsigned short value=((unsigned short)(datar[0])<<8)|(unsigned short)datar[1];
+    return(((float)(value)-32767.0)*64./rsense/32767.0);
+}
+
+unsigned short LTC2944::getAccumulatedCharge(void)
+{
+    dataw[0]=0x2;  // adresse de la tension
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,2);    // lecture du registre de deux octets
+    return(((unsigned short)(datar[0])<<8)|(unsigned short)datar[1]);
+
+}
+unsigned char LTC2944::getStatus(void)
+{
+    dataw[0]=0x0;  // adresse status
+    i2c.write(address,dataw,1,1);  // positionnement de l'adresse
+    i2c.read(address,datar,1);    // lecture du registre de deux octets
+    return(datar[0]);
+
+}
+unsigned char LTC2944::alertResponse(void)
+{
+    i2c.read(0x18,datar,1);    // lecture du registre de deux octets
+
+
+    return( datar[0]);
+}
\ No newline at end of file
diff -r ec69fa9832e5 -r 378dc5a174ce LTC2944.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LTC2944.h	Wed May 17 18:45:40 2017 +0000
@@ -0,0 +1,34 @@
+
+#include "mbed.h"  
+
+
+
+class LTC2944 {
+    public:
+    LTC2944(PinName sda, PinName scl);
+    float getVoltage();
+    float getCurrent();
+    unsigned short getAccumulatedCharge();
+    float getTemp();
+    void setRsense(float);
+    void setPrescaler(unsigned char);
+    void setMode(unsigned char);
+    void setImax(float);
+    void setImin(float);
+    unsigned char alertResponse(void);
+    unsigned char getStatus(void);
+    
+    
+    private:
+    
+    I2C i2c;
+    Serial pc;
+    float rsense;
+    float prescaler;
+    char datar[25];
+    char dataw[3];
+    int address;
+    };
+
+
+