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@13:ef7a06fa11de, 2019-09-29 (annotated)
- Committer:
- JonFreeman
- Date:
- Sun Sep 29 16:34:37 2019 +0000
- Revision:
- 13:ef7a06fa11de
- Parent:
- 12:d1d21a2941ef
- Child:
- 14:acaa1add097b
Stable code as at end of 2019 running season
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 | 12:d1d21a2941ef | 21 | int temp_tick; |
| JonFreeman | 12:d1d21a2941ef | 22 | double RPM_filter, dv_by_dt; |
| JonFreeman | 12:d1d21a2941ef | 23 | double target_speed; |
| JonFreeman | 12:d1d21a2941ef | 24 | bool moving_flag; |
| JonFreeman | 12:d1d21a2941ef | 25 | const uint16_t * lut; |
| JonFreeman | 11:bfb73f083009 | 26 | AnalogIn Motor_I; |
| JonFreeman | 12:d1d21a2941ef | 27 | FastPWM maxV, maxI; |
| JonFreeman | 12:d1d21a2941ef | 28 | InterruptIn H1, H2, H3; // Inputs for motor Hall sensors |
| JonFreeman | 12:d1d21a2941ef | 29 | PortOut OP; |
| JonFreeman | 12:d1d21a2941ef | 30 | void Hall_change () ; |
| JonFreeman | 12:d1d21a2941ef | 31 | int read_Halls () ; // Returns 3 bits of latest Hall sensor outputs |
| JonFreeman | 12:d1d21a2941ef | 32 | uint32_t max_rpm ; |
| JonFreeman | 12:d1d21a2941ef | 33 | double V_clamp ; // Used to limit top speed |
| JonFreeman | 12:d1d21a2941ef | 34 | double numof_current_sense_rs; |
| JonFreeman | 10:e40d8724268a | 35 | public: |
| JonFreeman | 12:d1d21a2941ef | 36 | #ifdef USING_DC_MOTORS |
| JonFreeman | 10:e40d8724268a | 37 | bool dc_motor; |
| JonFreeman | 12:d1d21a2941ef | 38 | #endif |
| JonFreeman | 12:d1d21a2941ef | 39 | uint32_t tickleon; |
| JonFreeman | 12:d1d21a2941ef | 40 | double Idbl; |
| JonFreeman | 10:e40d8724268a | 41 | double last_V, last_I; |
| JonFreeman | 13:ef7a06fa11de | 42 | double dRPM, dMPH, |
| JonFreeman | 13:ef7a06fa11de | 43 | sdbl[8]; // Filter coefficients for filtering RPM and MPH reading stuff, I think! |
| JonFreeman | 13:ef7a06fa11de | 44 | // Used in brushless_motor::speed_monitor_and_control () |
| JonFreeman | 13:ef7a06fa11de | 45 | |
| JonFreeman | 11:bfb73f083009 | 46 | // brushless_motor () {} ; // can not use this with exotic elements PortOut, FastPWM etc |
| JonFreeman | 12:d1d21a2941ef | 47 | brushless_motor (PinName iadc, PinName pwv, PinName pwi, const uint16_t *, PinName h1, PinName h2, PinName h3, PortName, int, uint32_t) ; // Constructor |
| JonFreeman | 12:d1d21a2941ef | 48 | bool poles (int) ; // Set number of motor poles - 4, 6, or 8 |
| JonFreeman | 12:d1d21a2941ef | 49 | void set_speed (double) ; // Sets target_speed |
| JonFreeman | 10:e40d8724268a | 50 | void set_V_limit (double) ; // Sets max motor voltage |
| JonFreeman | 10:e40d8724268a | 51 | void set_I_limit (double) ; // Sets max motor current |
| JonFreeman | 10:e40d8724268a | 52 | void motor_set () ; // Energise Port with data determined by Hall sensors |
| JonFreeman | 12:d1d21a2941ef | 53 | void direction_set (int) ; // sets 'direction' with bit pattern to eor with MOTOR_FORWARD or MOTOR_REVERSE in set_mode |
| JonFreeman | 12:d1d21a2941ef | 54 | bool set_mode (int); // sets mode to MOTOR_HANDBRAKE, MOTOR_FORWARD, MOTOR_REVERSE or MOTOR_REGENBRAKE |
| JonFreeman | 10:e40d8724268a | 55 | bool is_moving () ; // Returns true if one or more Hall transitions within last 31.25 milli secs |
| JonFreeman | 12:d1d21a2941ef | 56 | void speed_monitor_and_control () ; // call this once per main loop pass (32Hz) to keep count = edges per sec |
| JonFreeman | 10:e40d8724268a | 57 | void high_side_off () ; |
| JonFreeman | 12:d1d21a2941ef | 58 | // void low_side_on () ; |
| JonFreeman | 12:d1d21a2941ef | 59 | void sniff_current () ; // Call this every 200us to update Idbl |
| JonFreeman | 10:e40d8724268a | 60 | } ; //MotorA, MotorB, or even Motor[2]; |
| JonFreeman | 10:e40d8724268a | 61 | |
| JonFreeman | 10:e40d8724268a | 62 | #endif |