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
Diff: brushless_motor.h
- Revision:
- 10:e40d8724268a
- Child:
- 11:bfb73f083009
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/brushless_motor.h Tue Jan 15 09:03:57 2019 +0000
@@ -0,0 +1,73 @@
+/* mbed brushless_motor library
+ Jon Freeman
+ December 2018
+*/
+#ifndef MBED_BRUSHLESSMOTOR_H
+#define MBED_BRUSHLESSMOTOR_H
+
+#include "mbed.h"
+
+class brushless_motor
+{
+ uint32_t Hall_total, visible_mode, inner_mode, edge_count_table[MAIN_LOOP_ITERATION_Hz]; // to contain one seconds worth
+ uint32_t latest_pulses_per_sec, Hall_tab_ptr, direction, ppstmp;
+ bool moving_flag;
+ const uint16_t * lut;
+ uint16_t ttabl[34];
+ FastPWM * maxV, * maxI;
+ PortOut * Motor_Port;
+ InterruptIn * Hall1, * Hall2, * Hall3;
+public:
+ bool dc_motor;
+ struct currents {
+ uint32_t max, min, ave;
+ } I;
+ int32_t angle_cnt;
+ uint32_t current_samples[CURRENT_SAMPLES_AVERAGED]; // Circular buffer where latest current readings get stored
+ uint32_t Hindex[2], tickleon, encoder_error_cnt;
+ uint32_t RPM, PPS;
+ double last_V, last_I;
+ brushless_motor () {} ; // Default constructor
+/**
+ brushless_motor (PortOut * , FastPWM * , FastPWM * , const uint16_t *, InterruptIn **) ;
+
+ PortOut * is &MotA where MotA has been declared as below where PORT_A_MASK identifies which 6 bits of 16 bit port are used to energise motor
+ PortOut MotA (PortA, PORT_A_MASK); // Activate output ports to motor drivers
+
+ FastPWM * are e.g. &A_MAX_V_PWM, &A_MAX_I_PWM
+
+ const uint16_t * is e.g. A_tabl defining which port bits set to which level
+const uint16_t A_tabl[] = { // Origial table
+ 0, 0, 0, 0, 0, 0, 0, 0, // Handbrake
+ 0, AWV,AVU,AWU,AUW,AUV,AVW,AUW, // Forward 0, WV1, VU1, WU1, UW1, UV1, VW1, 0, // JP, FR, SG, PWM = 1 0 1 1 Forward1
+ 0, AVW,AUV,AUW,AWU,AVU,AWV,AWU, // Reverse 0, VW1, UV1, UW1, WU1, VU1, WV1, 0, // JP, FR, SG, PWM = 1 1 0 1 Reverse1
+ 0, BRA,BRA,BRA,BRA,BRA,BRA,BRA, // Regenerative Braking
+ KEEP_L_MASK_A, KEEP_H_MASK_A // [32 and 33]
+} ;
+
+InterruptIn ** is e.g. AHarr pointer to array of addresses of InterruptIns connected to Hall sensors
+InterruptIn * AHarr[] = {
+ &MAH1,
+ &MAH2,
+ &MAH3
+} ;
+
+*/
+ brushless_motor (PortOut * , FastPWM * , FastPWM * , const uint16_t *, InterruptIn **) ;
+ void set_V_limit (double) ; // Sets max motor voltage
+ void set_I_limit (double) ; // Sets max motor current
+ void Hall_change () ; // Called in response to edge on Hall input pin
+ void motor_set () ; // Energise Port with data determined by Hall sensors
+ void direction_set (int) ; // sets 'direction' with bit pattern to eor with FORWARD or REVERSE in set_mode
+ bool set_mode (int); // sets mode to HANDBRAKE, FORWARD, REVERSE or REGENBRAKE
+ bool is_moving () ; // Returns true if one or more Hall transitions within last 31.25 milli secs
+ void current_calc () ; // Updates 3 uint32_t I.min, I.ave, I.max
+ uint32_t pulses_per_sec () ; // call this once per main loop pass to keep count = edges per sec
+ int read_Halls () ; // Returns 3 bits of latest Hall sensor outputs
+ bool motor_is_brushless ();
+ void high_side_off () ;
+ void low_side_on () ;
+ void raw_V_pwm (int);
+} ; //MotorA, MotorB, or even Motor[2];
+
+#endif