I2C PWM MOTOR Control for DRV8830

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
oguro
Date:
Thu Mar 09 02:34:25 2017 +0000
Commit message:
I2C PWM Motor Control

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 7d2d296b12e6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 09 02:34:25 2017 +0000
@@ -0,0 +1,133 @@
+#include "mbed.h"
+ 
+// Read temperature from LM75BD
+Serial pc(USBTX,USBRX);
+I2C i2c(PB_9, PB_8);
+AnalogIn V_adc(PB_1);
+
+const int addr = 0xC8;
+int i0=1,i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
+float Vr_adc;
+
+DigitalIn  H1(PA_15);
+DigitalIn  H2(PB_3);
+DigitalIn  H3(PB_10);
+unsigned short  U,V,W;
+ 
+int main() {
+     pc.baud(128000);
+    char cmd[2];
+        cmd[0] = 0x0;
+        cmd[1] = 0x65;
+       
+        i2c.write(addr,cmd, 2);
+       
+        cmd[0] = 0x1;
+        cmd[1] = 0x80;
+        
+        i2c.write(addr,cmd, 2);
+        
+        while(1){
+            cmd[0] = 0x1;
+            cmd[1] = 0x80;
+            i2c.write(addr,cmd, 2);
+            
+             Vr_adc=V_adc.read();
+        if((Vr_adc>0.05f)&&(Vr_adc<=0.1f)&&(i0==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0x25;  //0.72V
+              i0=0;
+              i1=1;
+              i2c.write(addr,cmd, 2);
+              }
+        if((Vr_adc>0.1f)&&(Vr_adc<=0.2f)&&(i1==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0x35;  //1.04V
+              i0=1;
+              i1=0;
+              i2=1;
+              i2c.write(addr,cmd, 2);
+              }
+        if((Vr_adc>0.2f)&&(Vr_adc<=0.3f)&&(i2==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0x4D;  //1.53V
+              i1=1;
+              i2=0;
+              i3=1;
+              i2c.write(addr,cmd, 2);
+              }
+       if((Vr_adc>0.3f)&&(Vr_adc<=0.4f)&&(i3==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0x65;  //2.01V
+              i1=1;
+              i2=1;
+              i3=0;
+              i4=1;
+              i2c.write(addr,cmd, 2);
+              }
+        if((Vr_adc>0.4f)&&(Vr_adc<=0.5f)&&(i4==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0x7D;  //2.48V
+              i1=1;
+              i2=1;
+              i3=1;
+              i4=0;
+              i5=1;
+              i2c.write(addr,cmd, 2);
+              }
+       if((Vr_adc>0.5f)&&(Vr_adc<=0.6f)&&(i5==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0x99;  //3.05V
+              i1=1;
+              i2=1;
+              i3=1;
+              i4=1;
+              i5=0;
+              i6=1;
+              i2c.write(addr,cmd, 2);
+              }   
+       if((Vr_adc>0.6f)&&(Vr_adc<=0.7f)&&(i6==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0xB1;  //3.53V
+              i1=1;
+              i2=1;
+              i3=1;
+              i4=1;
+              i5=1;
+              i6=0;
+              i7=1;
+              i2c.write(addr,cmd, 2);
+              }
+      if((Vr_adc>0.7f)&&(Vr_adc<=0.8f)&&(i7==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0xC9;  //4.02V
+              i1=1;
+              i2=1;
+              i3=1;
+              i4=1;
+              i5=1;
+              i6=1;
+              i7=0;
+              i8=1;
+              i2c.write(addr,cmd, 2);
+              }   
+      if((Vr_adc>0.8f)&&(i8==1)){
+              cmd[0] = 0x0;
+              cmd[1] = 0xE1;  //4.50V
+              i1=1;
+              i2=1;
+              i3=1;
+              i4=1;
+              i5=1;
+              i6=1;
+              i7=1;
+              i8=0;  
+              i2c.write(addr,cmd, 2);
+              } 
+              
+              U=H1; V=H2; W=H3;
+              pc.printf("%d,%d,%d \r" ,U,V,W); 
+            }
+ 
+    
+}
diff -r 000000000000 -r 7d2d296b12e6 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 09 02:34:25 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/176b8275d35d
\ No newline at end of file