STM3 ESC dual brushless motor controller. 10-60v, motor power rating tiny to kW. Ganged or independent motor control As used in 'The Brute' locomotive - www.jons-workshop.com

Dependencies:   mbed BufferedSerial Servo FastPWM

Files at this revision

API Documentation at this revision

Comitter:
JonFreeman
Date:
Wed Mar 07 08:29:18 2018 +0000
Parent:
0:435bf84ce48a
Child:
2:04761b196473
Commit message:
About to start testing twin bldc motor controller board STM2;

Changed in this revision

24LC64_eeprom.cpp Show annotated file Show diff for this revision Revisions of this file
MPL3115A2b.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/24LC64_eeprom.cpp	Thu Mar 01 11:29:28 2018 +0000
+++ b/24LC64_eeprom.cpp	Wed Mar 07 08:29:18 2018 +0000
@@ -88,6 +88,7 @@
 }
 
 int check_24LC64   ()  {     //  Call from near top of main() to init i2c bus
+//    i2c.frequency(400000);      //  Speed 400000 max.
     i2c.frequency(400000);      //  Speed 400000 max.
     int last_found = 0, q;      //  Note address bits 3-1 to match addr pins on device
     for (int i = 0; i < 255; i += 2)    {   //  Search for devices at all possible i2c addresses
--- a/MPL3115A2b.lib	Thu Mar 01 11:29:28 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/teams/MSS/code/MPL3115A2/#12223b4c88b1
--- a/main.cpp	Thu Mar 01 11:29:28 2018 +0000
+++ b/main.cpp	Wed Mar 07 08:29:18 2018 +0000
@@ -2,7 +2,6 @@
 #include "DualBLS.h"
 #include "BufferedSerial.h"
 #include "FastPWM.h"
-#include "MPL3115A2.h"
 /*  STM32F401RE - compile using NUCLEO-F401RE
 //  PROJECT -   Dual Brushless Motor Controller -   March 2018.
 
@@ -139,10 +138,6 @@
 I2C i2c                     (PB_7, PB_6);   //  Pins 58, 59 For 24LC64 eeprom
 //  Pin 60  BOOT0
 
-//MPL3115A2(PinName sda, PinName scl, int addr) ;
-//MPL3115A2 PressureSensor    (PB_7, PB_6, 0xa0) ;
-//double  PressureSensor.getPressure  ();
-
 #ifdef  SERVO1_IN
 InterruptIn Servo1_i    (PB_8); //  Pin 61  to read output from rc rx
 #endif
@@ -347,7 +342,7 @@
     PortOut * Motor_Port;
 public:
     uint32_t    current_samples[CURRENT_SAMPLES_AVERAGED];  //  Circular buffer where latest current readings get stored
-    uint32_t    index;
+    uint32_t    Hindex;
     motor   ()  {}  ;   //  Default constructor
     motor   (PortOut * , FastPWM * , FastPWM * , const uint16_t * )  ;
     void    set_V_limit (double)    ;  //  Sets max motor voltage
@@ -356,6 +351,7 @@
     bool    set_mode    (int);
     void    current_calc    ()  ;
     uint32_t    pulses_per_sec   ()  ;    //  call this once per main loop pass to keep count = edges per sec
+    int     read_Halls  ()  ;
 }   ;   //MotorA, MotorB;
 
 motor   MotorA  (&MotA, &A_MAX_V_PWM, &A_MAX_I_PWM, A_tabl);
@@ -366,7 +362,7 @@
     maxV = _maxV_;
     maxI = _maxI_;
     Hall_total = mode = 0;  //  mode can be only 0, 8, 16 or 24, lut row select for Handbrake, Forward, Reverse, or Regen Braking
-    index = 0;
+    Hindex = 0;
     Hall_tab_ptr = 0;
     latest_pulses_per_sec = 0;
     for (int i = 0; i < MAIN_LOOP_ITERATION_Hz; i++)
@@ -386,6 +382,10 @@
     lut = lutptr;
 }
 
+int     motor::read_Halls  ()  {
+    return  Hindex;
+}
+
 void    motor::current_calc ()
 {
     I.min = 0x0fffffff; //  samples are 16 bit
@@ -453,91 +453,91 @@
 {
     Hall_total++;
     mode &= 0x038L; //  safety
-    *Motor_Port = lut[mode + index];
+    *Motor_Port = lut[mode + Hindex];
 }
 void    MAH1r    ()
 {
-    MotorA.index = 1;
-    if  (MAH2 != 0) MotorA.index |= 2;
-    if  (MAH3 != 0) MotorA.index |= 4;
+    MotorA.Hindex = 1;
+    if  (MAH2 != 0) MotorA.Hindex |= 2;
+    if  (MAH3 != 0) MotorA.Hindex |= 4;
     MotorA.Hall_change  ();
 }
 void    MAH1f    ()
 {
-    MotorA.index = 0;
-    if  (MAH2 != 0) MotorA.index |= 2;
-    if  (MAH3 != 0) MotorA.index |= 4;
+    MotorA.Hindex = 0;
+    if  (MAH2 != 0) MotorA.Hindex |= 2;
+    if  (MAH3 != 0) MotorA.Hindex |= 4;
     MotorA.Hall_change  ();
 }
 void    MAH2r    ()
 {
-    MotorA.index = 2;
-    if  (MAH1 != 0) MotorA.index |= 1;
-    if  (MAH3 != 0) MotorA.index |= 4;
+    MotorA.Hindex = 2;
+    if  (MAH1 != 0) MotorA.Hindex |= 1;
+    if  (MAH3 != 0) MotorA.Hindex |= 4;
     MotorA.Hall_change  ();
 }
 void    MAH2f    ()
 {
-    MotorA.index = 0;
-    if  (MAH1 != 0) MotorA.index |= 1;
-    if  (MAH3 != 0) MotorA.index |= 4;
+    MotorA.Hindex = 0;
+    if  (MAH1 != 0) MotorA.Hindex |= 1;
+    if  (MAH3 != 0) MotorA.Hindex |= 4;
     MotorA.Hall_change  ();
 }
 void    MAH3r    ()
 {
-    MotorA.index = 4;
-    if  (MAH1 != 0) MotorA.index |= 1;
-    if  (MAH2 != 0) MotorA.index |= 2;
+    MotorA.Hindex = 4;
+    if  (MAH1 != 0) MotorA.Hindex |= 1;
+    if  (MAH2 != 0) MotorA.Hindex |= 2;
     MotorA.Hall_change  ();
 }
 void    MAH3f    ()
 {
-    MotorA.index = 0;
-    if  (MAH1 != 0) MotorA.index |= 1;
-    if  (MAH2 != 0) MotorA.index |= 2;
+    MotorA.Hindex = 0;
+    if  (MAH1 != 0) MotorA.Hindex |= 1;
+    if  (MAH2 != 0) MotorA.Hindex |= 2;
     MotorA.Hall_change  ();
 }
 
 void    MBH1r    ()
 {
-    MotorB.index = 1;
-    if  (MBH2 != 0) MotorB.index |= 2;
-    if  (MBH3 != 0) MotorB.index |= 4;
+    MotorB.Hindex = 1;
+    if  (MBH2 != 0) MotorB.Hindex |= 2;
+    if  (MBH3 != 0) MotorB.Hindex |= 4;
     MotorB.Hall_change  ();
 }
 void    MBH1f    ()
 {
-    MotorB.index = 0;
-    if  (MBH2 != 0) MotorB.index |= 2;
-    if  (MBH3 != 0) MotorB.index |= 4;
+    MotorB.Hindex = 0;
+    if  (MBH2 != 0) MotorB.Hindex |= 2;
+    if  (MBH3 != 0) MotorB.Hindex |= 4;
     MotorB.Hall_change  ();
 }
 void    MBH2r    ()
 {
-    MotorB.index = 2;
-    if  (MBH1 != 0) MotorB.index |= 1;
-    if  (MBH3 != 0) MotorB.index |= 4;
+    MotorB.Hindex = 2;
+    if  (MBH1 != 0) MotorB.Hindex |= 1;
+    if  (MBH3 != 0) MotorB.Hindex |= 4;
     MotorB.Hall_change  ();
 }
 void    MBH2f    ()
 {
-    MotorB.index = 0;
-    if  (MBH1 != 0) MotorB.index |= 1;
-    if  (MBH3 != 0) MotorB.index |= 4;
+    MotorB.Hindex = 0;
+    if  (MBH1 != 0) MotorB.Hindex |= 1;
+    if  (MBH3 != 0) MotorB.Hindex |= 4;
     MotorB.Hall_change  ();
 }
 void    MBH3r    ()
 {
-    MotorB.index = 4;
-    if  (MBH1 != 0) MotorB.index |= 1;
-    if  (MBH2 != 0) MotorB.index |= 2;
+    MotorB.Hindex = 4;
+    if  (MBH1 != 0) MotorB.Hindex |= 1;
+    if  (MBH2 != 0) MotorB.Hindex |= 2;
     MotorB.Hall_change  ();
 }
 void    MBH3f    ()
 {
-    MotorB.index = 0;
-    if  (MBH1 != 0) MotorB.index |= 1;
-    if  (MBH2 != 0) MotorB.index |= 2;
+    MotorB.Hindex = 0;
+    if  (MBH1 != 0) MotorB.Hindex |= 1;
+    if  (MBH2 != 0) MotorB.Hindex |= 2;
     MotorB.Hall_change  ();
 }
 
@@ -703,10 +703,13 @@
             j++;
             if  (j > 6)    {   //  Send some status info out of serial port every second and a bit or thereabouts
                 j = 0;
-//double  pres = PressureSensor.getPressure  ();
+            uint8_t stat;
+            stat = PressureSensor.getFstatus();
+double  pres = PressureSensor.getPressure  ();
+//double  tmpr = PressureSensor.getTemperature  ();
 //double  pres = PressureSensor.getTemperature  ();
-                pc.printf   ("Apps %d, Bpps %d, sys_timer %d\r\n", Apps, Bpps, sys_timer);
-//                pc.printf   ("Apps %d, Bpps %d, sys_timer %d, pressure %.2f\r\n", Apps, Bpps, sys_timer, pres);
+//                pc.printf   ("Apps %d, Bpps %d, sys_timer %d\r\n", Apps, Bpps, sys_timer);
+                pc.printf   ("Apps %d, Bpps %d, sys_timer %d, status %d, pressure %.2f\r\n", Apps, Bpps, sys_timer, stat, pres);
                 //            pc.printf   ("V=%+.1f, I=%+.1f, CtrlOut %.3f, RPM %d, %s\r\n", Read_BatteryVolts(), AmpsReading, ControlOut, ReadEngineRPM(), engine_warm ? "Running mode" : "Startup mode");
             }
         }   //  End of if(flag_8Hz)