Brushless motor control program with L293D.

Dependencies:   brushlessController_L293D mbed

Revision:
0:06434e97c4f2
Child:
1:46f06c96c5f0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 13 14:10:28 2015 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+/* Digital Outputs */
+DigitalOut out1(p21);
+DigitalOut out2(p22);
+DigitalOut out3(p24);
+
+/* Function Prototype */
+void brushlessControl(bool dir, int delay_time);
+
+int main() 
+{
+    while(1) 
+    {
+        /* It works but slow */
+        brushlessControl(0,100);
+        brushlessControl(1,100);
+    }
+}
+
+void brushlessControl(bool dir, int delay_time)
+{
+    /* Digital outputs are initially zero */
+    out1 = 0; out2 = 0; out3 = 0;
+    
+    /* Magical data_array to drive the brushless motor */
+    bool data_array[]={1,1,0, 1,0,0, 1,0,1, 0,0,1, 0,1,1, 0,1,0};
+    bool data_arrayInv[]={0,1,0, 0,1,1, 0,0,1, 1,0,1, 1,0,0, 1,1,0};
+    
+    if(dir==1)      // if dir = 1, reverse the motor direction
+        for(int k=0; k<18; k++)
+            data_array[k] = data_arrayInv[k];      
+    
+    for (int i=0; i<6; i++)
+    {
+        out1 = data_array[3*i]; 
+        out2 = data_array[3*i+1]; 
+        out3 = data_array[3*i+2];  
+        wait_ms(delay_time);       
+    }   
+}
\ No newline at end of file