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

Committer:
JonFreeman
Date:
Sat Jan 19 11:45:01 2019 +0000
Revision:
11:bfb73f083009
Parent:
10:e40d8724268a
Child:
12:d1d21a2941ef
Tidied class parameter passing, serial problem fixed (was hardware)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 10:e40d8724268a 1 /* mbed brushless_motor library
JonFreeman 10:e40d8724268a 2 Jon Freeman
JonFreeman 10:e40d8724268a 3 December 2018
JonFreeman 10:e40d8724268a 4 */
JonFreeman 10:e40d8724268a 5 #ifndef MBED_BRUSHLESSMOTOR_H
JonFreeman 10:e40d8724268a 6 #define MBED_BRUSHLESSMOTOR_H
JonFreeman 10:e40d8724268a 7
JonFreeman 10:e40d8724268a 8 #include "mbed.h"
JonFreeman 11:bfb73f083009 9 #include "DualBLS.h"
JonFreeman 10:e40d8724268a 10
JonFreeman 10:e40d8724268a 11 class brushless_motor
JonFreeman 10:e40d8724268a 12 {
JonFreeman 11:bfb73f083009 13 int32_t angle_cnt;
JonFreeman 11:bfb73f083009 14 uint32_t Hall_index[2], encoder_error_cnt;
JonFreeman 10:e40d8724268a 15 uint32_t Hall_total, visible_mode, inner_mode, edge_count_table[MAIN_LOOP_ITERATION_Hz]; // to contain one seconds worth
JonFreeman 10:e40d8724268a 16 uint32_t latest_pulses_per_sec, Hall_tab_ptr, direction, ppstmp;
JonFreeman 10:e40d8724268a 17 bool moving_flag;
JonFreeman 10:e40d8724268a 18 const uint16_t * lut;
JonFreeman 10:e40d8724268a 19 uint16_t ttabl[34];
JonFreeman 11:bfb73f083009 20 FastPWM maxV;
JonFreeman 11:bfb73f083009 21 FastPWM maxI;
JonFreeman 11:bfb73f083009 22 InterruptIn H1;
JonFreeman 11:bfb73f083009 23 InterruptIn H2;
JonFreeman 11:bfb73f083009 24 InterruptIn H3;
JonFreeman 11:bfb73f083009 25 PortOut OP;
JonFreeman 11:bfb73f083009 26 AnalogIn Motor_I;
JonFreeman 11:bfb73f083009 27 void Hall_change () ;
JonFreeman 11:bfb73f083009 28 int read_Halls () ; // Returns 3 bits of latest Hall sensor outputs
JonFreeman 10:e40d8724268a 29 public:
JonFreeman 10:e40d8724268a 30 bool dc_motor;
JonFreeman 10:e40d8724268a 31 struct currents {
JonFreeman 10:e40d8724268a 32 uint32_t max, min, ave;
JonFreeman 10:e40d8724268a 33 } I;
JonFreeman 10:e40d8724268a 34 uint32_t current_samples[CURRENT_SAMPLES_AVERAGED]; // Circular buffer where latest current readings get stored
JonFreeman 11:bfb73f083009 35 uint32_t cs_ptr;
JonFreeman 11:bfb73f083009 36 uint32_t RPM, PPS, tickleon;
JonFreeman 10:e40d8724268a 37 double last_V, last_I;
JonFreeman 11:bfb73f083009 38 // brushless_motor () {} ; // can not use this with exotic elements PortOut, FastPWM etc
JonFreeman 11:bfb73f083009 39 brushless_motor (PinName iadc, PinName pwv, PinName pwi, const uint16_t *, PinName h1, PinName h2, PinName h3, PortName, int) ; // Constructor
JonFreeman 10:e40d8724268a 40 void set_V_limit (double) ; // Sets max motor voltage
JonFreeman 10:e40d8724268a 41 void set_I_limit (double) ; // Sets max motor current
JonFreeman 10:e40d8724268a 42 void motor_set () ; // Energise Port with data determined by Hall sensors
JonFreeman 10:e40d8724268a 43 void direction_set (int) ; // sets 'direction' with bit pattern to eor with FORWARD or REVERSE in set_mode
JonFreeman 10:e40d8724268a 44 bool set_mode (int); // sets mode to HANDBRAKE, FORWARD, REVERSE or REGENBRAKE
JonFreeman 10:e40d8724268a 45 bool is_moving () ; // Returns true if one or more Hall transitions within last 31.25 milli secs
JonFreeman 10:e40d8724268a 46 void current_calc () ; // Updates 3 uint32_t I.min, I.ave, I.max
JonFreeman 10:e40d8724268a 47 uint32_t pulses_per_sec () ; // call this once per main loop pass to keep count = edges per sec
JonFreeman 10:e40d8724268a 48 bool motor_is_brushless ();
JonFreeman 10:e40d8724268a 49 void high_side_off () ;
JonFreeman 10:e40d8724268a 50 void low_side_on () ;
JonFreeman 10:e40d8724268a 51 void raw_V_pwm (int);
JonFreeman 11:bfb73f083009 52 void sniff_current () ;
JonFreeman 10:e40d8724268a 53 } ; //MotorA, MotorB, or even Motor[2];
JonFreeman 10:e40d8724268a 54
JonFreeman 10:e40d8724268a 55 #endif