Dual Brushless Motor ESC, 10-62V, up to 50A per motor. Motors ganged or independent, multiple control input methods, cycle-by-cycle current limit, speed mode and torque mode control. Motors tiny to kW. Speed limit and other parameters easily set in firmware. As used in 'The Brushless Brutalist' locomotive - www.jons-workshop.com. See also Model Engineer magazine June-October 2019.

Dependencies:   mbed BufferedSerial Servo PCT2075 FastPWM

Update 17th August 2020 Radio control inputs completed

Revision:
16:d1e4b9ad3b8b
Parent:
14:acaa1add097b
Child:
17:cc9b854295d6
--- a/brushless_motor.h	Sat Nov 30 18:40:30 2019 +0000
+++ b/brushless_motor.h	Tue Jun 09 09:20:19 2020 +0000
@@ -18,45 +18,43 @@
                 visible_mode,       //  One of MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE, MOTOR_REGENBRAKE
                 inner_mode; 
     uint32_t    direction;
-    int         temp_tick;
-    double      RPM_filter, dv_by_dt;
-    double      target_speed;
+    double      RPM_filter;     //, dv_by_dt;
     bool        moving_flag;
     const       uint16_t * lut;
     AnalogIn    Motor_I;
     FastPWM     maxV,   maxI;
     InterruptIn H1, H2, H3;     //  Inputs for motor Hall sensors
     PortOut     OP;
+    void        motor_voltage_refresh   ()  ;
     void        Hall_change ()  ;
-    int         read_Halls  ()  ;           //  Returns 3 bits of latest Hall sensor outputs
-    uint32_t    max_rpm ;
+    uint32_t    read_Halls  ()  ;           //  Returns 3 bits of latest Hall sensor outputs
+//    uint32_t    max_rpm ;
     double      V_clamp ;   //  Used to limit top speed
-    double      numof_current_sense_rs;
+//    double      numof_current_sense_rs;
+    double      last_V, last_I, current_scale;
 public:
-#ifdef  USING_DC_MOTORS     //  deprecated
-    bool    dc_motor;
-#endif
     uint32_t    tickleon;
     double      Idbl;
-    double      last_V, last_I;
-    double      dRPM, dMPH, 
-                sdbl[8];        //  Filter coefficients for filtering RPM and MPH reading stuff, I think!
-                                //  Used in brushless_motor::speed_monitor_and_control   ()
+    double      dRPM, dMPH;
                                 
 //    brushless_motor   ()  {}   ;  //  can not use this with exotic elements PortOut, FastPWM etc
-    brushless_motor   (PinName iadc, PinName pwv, PinName pwi, const uint16_t *, PinName h1, PinName h2, PinName h3, PortName, int, uint32_t)   ;   //  Constructor
-    bool    poles       (int)   ;   //  Set number of motor poles - 4, 6, or 8
-    void    set_speed   (double)    ;   //  Sets target_speed
-    void    set_V_limit (double)    ;  //  Sets max motor voltage
-    void    set_I_limit (double)    ;  //  Sets max motor current
-    void    motor_set   ()  ;           //  Energise Port with data determined by Hall sensors
-    void    direction_set   (int)  ;    //  sets 'direction' with bit pattern to eor with MOTOR_FORWARD or MOTOR_REVERSE in set_mode
-    bool    set_mode    (int);          //  sets mode to MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE or MOTOR_REGENBRAKE
-    bool    is_moving   ()  ;           //  Returns true if one or more Hall transitions within last 31.25 milli secs
-    void    speed_monitor_and_control   ()  ;  //  call this once per main loop pass (32Hz) to keep count = edges per sec
-    void    high_side_off   ()  ;
+    brushless_motor   (PinName iadc, PinName pwv, PinName pwi, const uint16_t *, PinName h1, PinName h2, PinName h3, PortName, uint16_t, uint32_t)   ;   //  Constructor
+    bool        poles       (uint32_t)   ;   //  Set number of motor poles - 4, 6, or 8
+    void        set_V_limit (double)    ;  //  Sets max motor voltage
+    void        set_I_limit (double)    ;  //  Sets max motor current
+    void        motor_set   ()  ;           //  Energise Port with data determined by Hall sensors
+    void        set_direction   (uint32_t)  ;    //  sets 'direction' with bit pattern to eor with MOTOR_FORWARD or MOTOR_REVERSE in set_mode
+    void        brake   (double brake_effort)    ;
+//    uint32_t    get_direction   ()  ;
+    bool        set_mode    (uint32_t);          //  sets mode to MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE or MOTOR_REGENBRAKE
+    uint32_t    get_mode    ()    ;
+    bool        is_moving   ()  ;           //  Returns true if one or more Hall transitions within last 31.25 milli secs
+    void        speed_monitor_and_control   ()  ;  //  call this once per main loop pass (32Hz) to keep count = edges per sec
+    void        high_side_off   ()  ;
 //    void    low_side_on     ()  ;
-    void    sniff_current   ()  ;           //  Call this every 200us to update Idbl
+    void        sniff_current   ()  ;           //  Call this every 200us to update Idbl
+    void        I_scale (double);
+    bool        exists  ()  ;       //  New May 2020 - reports presence or absence of motor
 }   ;   //MotorA, MotorB, or even Motor[2];
 
 #endif