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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers brushless_motor.h Source File

brushless_motor.h

00001 /*  mbed brushless_motor library
00002     Jon Freeman
00003     December 2018
00004 */
00005 #ifndef MBED_BRUSHLESSMOTOR_H
00006 #define MBED_BRUSHLESSMOTOR_H
00007 
00008 #include "mbed.h"
00009 #include "STM3_ESC.h"
00010 #include "FastPWM.h"
00011 
00012 class   brushless_motor
00013 {
00014     int32_t     angle_cnt;
00015     uint32_t    Hall_index[2], encoder_error_cnt, motor_poles, current_sense_rs_offset;
00016     uint32_t    Hall_total,         //  Incremented on every Hall sensor transition
00017                 Hall_previous,
00018                 visible_mode,       //  One of MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE, MOTOR_REGENBRAKE
00019                 inner_mode; 
00020     uint32_t    direction;
00021     double      RPM_filter;     //, dv_by_dt;
00022     bool        moving_flag;
00023     const       uint16_t * lut;
00024     AnalogIn    Motor_I;
00025     FastPWM     maxV,   maxI;
00026     InterruptIn H1, H2, H3;     //  Inputs for motor Hall sensors
00027     PortOut     OP;
00028     void        motor_voltage_refresh   ()  ;
00029     void        Hall_change ()  ;
00030     uint32_t    read_Halls  ()  ;           //  Returns 3 bits of latest Hall sensor outputs
00031 //    uint32_t    max_rpm ;
00032     double      V_clamp ;   //  Used to limit top speed
00033 //    double      numof_current_sense_rs;
00034     double      last_V, last_I, current_scale;
00035 public:
00036     uint32_t    tickleon;
00037     double      Idbl;
00038     double      dRPM, dMPH;
00039                                 
00040 //    brushless_motor   ()  {}   ;  //  can not use this with exotic elements PortOut, FastPWM etc
00041     brushless_motor   (PinName iadc, PinName pwv, PinName pwi, const uint16_t *, PinName h1, PinName h2, PinName h3, PortName, const uint16_t, const uint32_t)   ;   //  Constructor
00042     bool        poles       (uint32_t)   ;   //  Set number of motor poles - 4, 6, or 8
00043     void        set_V_limit (double)    ;  //  Sets max motor voltage
00044     void        set_I_limit (double)    ;  //  Sets max motor current
00045     void        motor_set   ()  ;           //  Energise Port with data determined by Hall sensors
00046     void        set_direction   (uint32_t)  ;    //  sets 'direction' with bit pattern to eor with MOTOR_FORWARD or MOTOR_REVERSE in set_mode
00047     void        brake   (double brake_effort)    ;
00048 //    uint32_t    get_direction   ()  ;
00049     bool        set_mode    (uint32_t);          //  sets mode to MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE or MOTOR_REGENBRAKE
00050     uint32_t    get_mode    ()    ;
00051     bool        is_moving   ()  ;           //  Returns true if one or more Hall transitions within last 31.25 milli secs
00052     void        speed_monitor_and_control   ()  ;  //  call this once per main loop pass (32Hz) to keep count = edges per sec
00053     void        high_side_off   ()  ;
00054 //    void    low_side_on     ()  ;
00055     void        sniff_current   ()  ;           //  Call this every 200us to update Idbl
00056     void        I_scale (double);
00057     bool        exists  ()  ;       //  New May 2020 - reports presence or absence of motor
00058 }   ;   //MotorA, MotorB, or even Motor[2];
00059 
00060 #endif