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
brushless_motor.h@17:cc9b854295d6, 2020-08-16 (annotated)
- Committer:
- JonFreeman
- Date:
- Sun Aug 16 14:13:19 2020 +0000
- Revision:
- 17:cc9b854295d6
- Parent:
- 16:d1e4b9ad3b8b
August 2020. Checked Radio Control input ops.
Who changed what in which revision?
User | Revision | Line number | New 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 | 13:ef7a06fa11de | 9 | #include "STM3_ESC.h" |
JonFreeman | 12:d1d21a2941ef | 10 | #include "FastPWM.h" |
JonFreeman | 10:e40d8724268a | 11 | |
JonFreeman | 10:e40d8724268a | 12 | class brushless_motor |
JonFreeman | 10:e40d8724268a | 13 | { |
JonFreeman | 11:bfb73f083009 | 14 | int32_t angle_cnt; |
JonFreeman | 12:d1d21a2941ef | 15 | uint32_t Hall_index[2], encoder_error_cnt, motor_poles, current_sense_rs_offset; |
JonFreeman | 12:d1d21a2941ef | 16 | uint32_t Hall_total, // Incremented on every Hall sensor transition |
JonFreeman | 12:d1d21a2941ef | 17 | Hall_previous, |
JonFreeman | 13:ef7a06fa11de | 18 | visible_mode, // One of MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE, MOTOR_REGENBRAKE |
JonFreeman | 12:d1d21a2941ef | 19 | inner_mode; |
JonFreeman | 12:d1d21a2941ef | 20 | uint32_t direction; |
JonFreeman | 16:d1e4b9ad3b8b | 21 | double RPM_filter; //, dv_by_dt; |
JonFreeman | 12:d1d21a2941ef | 22 | bool moving_flag; |
JonFreeman | 12:d1d21a2941ef | 23 | const uint16_t * lut; |
JonFreeman | 11:bfb73f083009 | 24 | AnalogIn Motor_I; |
JonFreeman | 12:d1d21a2941ef | 25 | FastPWM maxV, maxI; |
JonFreeman | 12:d1d21a2941ef | 26 | InterruptIn H1, H2, H3; // Inputs for motor Hall sensors |
JonFreeman | 12:d1d21a2941ef | 27 | PortOut OP; |
JonFreeman | 16:d1e4b9ad3b8b | 28 | void motor_voltage_refresh () ; |
JonFreeman | 12:d1d21a2941ef | 29 | void Hall_change () ; |
JonFreeman | 16:d1e4b9ad3b8b | 30 | uint32_t read_Halls () ; // Returns 3 bits of latest Hall sensor outputs |
JonFreeman | 16:d1e4b9ad3b8b | 31 | // uint32_t max_rpm ; |
JonFreeman | 12:d1d21a2941ef | 32 | double V_clamp ; // Used to limit top speed |
JonFreeman | 16:d1e4b9ad3b8b | 33 | // double numof_current_sense_rs; |
JonFreeman | 16:d1e4b9ad3b8b | 34 | double last_V, last_I, current_scale; |
JonFreeman | 10:e40d8724268a | 35 | public: |
JonFreeman | 12:d1d21a2941ef | 36 | uint32_t tickleon; |
JonFreeman | 12:d1d21a2941ef | 37 | double Idbl; |
JonFreeman | 16:d1e4b9ad3b8b | 38 | double dRPM, dMPH; |
JonFreeman | 13:ef7a06fa11de | 39 | |
JonFreeman | 11:bfb73f083009 | 40 | // brushless_motor () {} ; // can not use this with exotic elements PortOut, FastPWM etc |
JonFreeman | 17:cc9b854295d6 | 41 | 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 |
JonFreeman | 16:d1e4b9ad3b8b | 42 | bool poles (uint32_t) ; // Set number of motor poles - 4, 6, or 8 |
JonFreeman | 16:d1e4b9ad3b8b | 43 | void set_V_limit (double) ; // Sets max motor voltage |
JonFreeman | 16:d1e4b9ad3b8b | 44 | void set_I_limit (double) ; // Sets max motor current |
JonFreeman | 16:d1e4b9ad3b8b | 45 | void motor_set () ; // Energise Port with data determined by Hall sensors |
JonFreeman | 16:d1e4b9ad3b8b | 46 | void set_direction (uint32_t) ; // sets 'direction' with bit pattern to eor with MOTOR_FORWARD or MOTOR_REVERSE in set_mode |
JonFreeman | 16:d1e4b9ad3b8b | 47 | void brake (double brake_effort) ; |
JonFreeman | 16:d1e4b9ad3b8b | 48 | // uint32_t get_direction () ; |
JonFreeman | 16:d1e4b9ad3b8b | 49 | bool set_mode (uint32_t); // sets mode to MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE or MOTOR_REGENBRAKE |
JonFreeman | 16:d1e4b9ad3b8b | 50 | uint32_t get_mode () ; |
JonFreeman | 16:d1e4b9ad3b8b | 51 | bool is_moving () ; // Returns true if one or more Hall transitions within last 31.25 milli secs |
JonFreeman | 16:d1e4b9ad3b8b | 52 | void speed_monitor_and_control () ; // call this once per main loop pass (32Hz) to keep count = edges per sec |
JonFreeman | 16:d1e4b9ad3b8b | 53 | void high_side_off () ; |
JonFreeman | 12:d1d21a2941ef | 54 | // void low_side_on () ; |
JonFreeman | 16:d1e4b9ad3b8b | 55 | void sniff_current () ; // Call this every 200us to update Idbl |
JonFreeman | 16:d1e4b9ad3b8b | 56 | void I_scale (double); |
JonFreeman | 16:d1e4b9ad3b8b | 57 | bool exists () ; // New May 2020 - reports presence or absence of motor |
JonFreeman | 10:e40d8724268a | 58 | } ; //MotorA, MotorB, or even Motor[2]; |
JonFreeman | 10:e40d8724268a | 59 | |
JonFreeman | 10:e40d8724268a | 60 | #endif |