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 11:bfb73f083009 1 #include "mbed.h"
JonFreeman 11:bfb73f083009 2
JonFreeman 11:bfb73f083009 3 #ifndef MBED_DUALBLS_H
JonFreeman 11:bfb73f083009 4 #define MBED_DUALBLS_H
JonFreeman 11:bfb73f083009 5
JonFreeman 2:04761b196473 6 const int HANDBRAKE = 0,
JonFreeman 2:04761b196473 7 FORWARD = 8,
JonFreeman 2:04761b196473 8 REVERSE = 16,
JonFreeman 2:04761b196473 9 REGENBRAKE = 24;
JonFreeman 3:ecb00e0e8d68 10
JonFreeman 5:ca86a7848d54 11 const int TIMEOUT_SECONDS = 30;
JonFreeman 5:ca86a7848d54 12
JonFreeman 5:ca86a7848d54 13 /* Please Do Not Alter these */
JonFreeman 8:93203f473f6e 14 const int PWM_PRESECALER_DEFAULT = 5,
JonFreeman 8:93203f473f6e 15 VOLTAGE_READ_INTERVAL_US = 50, // Interrupts timed every 50 micro sec, runs around loop performing 1 A-D conversion per pass
JonFreeman 5:ca86a7848d54 16 MAIN_LOOP_REPEAT_TIME_US = 31250, // 31250 us, with TACHO_TAB_SIZE = 32 means tacho_ticks_per_time is tacho_ticks_per_second
JonFreeman 5:ca86a7848d54 17 MAIN_LOOP_ITERATION_Hz = 1000000 / MAIN_LOOP_REPEAT_TIME_US,
JonFreeman 5:ca86a7848d54 18 CURRENT_SAMPLES_AVERAGED = 100, // Current is spikey. Reading smoothed by using average of this many latest current readings
JonFreeman 8:93203f473f6e 19 PWM_HZ = 15000, // chosen to be above cutoff frequency of average human ear
JonFreeman 8:93203f473f6e 20 MAX_PWM_TICKS = (SystemCoreClock / (PWM_HZ * PWM_PRESECALER_DEFAULT)),
JonFreeman 5:ca86a7848d54 21 TICKLE_TIMES = 100 ,
JonFreeman 5:ca86a7848d54 22 WATCHDOG_RELOAD = (TIMEOUT_SECONDS * 8); // WatchDog counter ticked down in 8Hz loop
JonFreeman 5:ca86a7848d54 23
JonFreeman 5:ca86a7848d54 24 /* End of Please Do Not Alter these */
JonFreeman 3:ecb00e0e8d68 25 const double PI = 4.0 * atan(1.0),
JonFreeman 3:ecb00e0e8d68 26 TWOPI = 8.0 * atan(1.0);
JonFreeman 5:ca86a7848d54 27
JonFreeman 11:bfb73f083009 28 enum {COM_SOURCES, COM1, COM2, HAND, RC_IN1, RC_IN2,THEEND} ;
JonFreeman 11:bfb73f083009 29
JonFreeman 8:93203f473f6e 30 //enum {MOTADIR, MOTBDIR, GANG, SVO1, SVO2, COMM_SRC, ID, WHEELDIA, MOTPIN, WHEELGEAR} ; // Identical in TS and DualBLS
JonFreeman 8:93203f473f6e 31 enum {MOTADIR, MOTBDIR, GANG, SVO1, SVO2, COMM_SRC, ID, WHEELDIA, MOTPIN, WHEELGEAR, BOGHUNWAT, FUT1, FUT2, FUT3, FUT4, FUT5} ; // Identical in TS and DualBLS
JonFreeman 5:ca86a7848d54 32 struct optpar {
JonFreeman 5:ca86a7848d54 33 int min, max, def; // min, max, default
JonFreeman 5:ca86a7848d54 34 const char * t; // description
JonFreeman 5:ca86a7848d54 35 } ;
JonFreeman 5:ca86a7848d54 36 struct optpar const option_list[] = {
JonFreeman 5:ca86a7848d54 37 {0, 1, 1, "MotorA direction 0 or 1"},
JonFreeman 5:ca86a7848d54 38 {0, 1, 0, "MotorB direction 0 or 1"},
JonFreeman 5:ca86a7848d54 39 {0, 1, 1, "gang 0 for separate control (robot mode), 1 for ganged loco bogie mode"},
JonFreeman 5:ca86a7848d54 40 {0, 2, 2, "Servo1 0, 1, 2 = Not used, Input, Output"},
JonFreeman 5:ca86a7848d54 41 {0, 2, 2, "Servo2 0, 1, 2 = Not used, Input, Output"},
JonFreeman 5:ca86a7848d54 42 {1, 5, 2, "Command source 0 Invalid, 1 COM1, 2 COM2, 3 Pot, 4 Servo1, 5 Servo2"},
JonFreeman 5:ca86a7848d54 43 {'1', '9', '0', "Alternative ID ascii '1' to '9'"}, // defaults to '0' before eerom setup for first time
JonFreeman 8:93203f473f6e 44 {50, 253, 98, "Wheel diameter mm"}, // New 01/06/2018
JonFreeman 7:6deaeace9a3e 45 {10, 253, 27, "Motor pinion"}, // New 01/06/2018
JonFreeman 8:93203f473f6e 46 {50, 253, 85, "Wheel gear"}, // New 01/06/2018
JonFreeman 8:93203f473f6e 47 {1, 20, 4, "Bogie power closest hundreds of Watt"}, // New 22/06/2018
JonFreeman 8:93203f473f6e 48 {0, 100, 0, "Future 1"},
JonFreeman 8:93203f473f6e 49 {0, 100, 0, "Future 2"},
JonFreeman 8:93203f473f6e 50 {0, 100, 0, "Future 3"},
JonFreeman 8:93203f473f6e 51 {0, 100, 0, "Future 4"},
JonFreeman 8:93203f473f6e 52 {0, 100, 0, "Future 5"},
JonFreeman 5:ca86a7848d54 53 } ;
JonFreeman 6:f289a49c1eae 54 const int numof_eeprom_options = sizeof(option_list) / sizeof (struct optpar);
JonFreeman 5:ca86a7848d54 55
JonFreeman 6:f289a49c1eae 56 struct single_bogie_options {
JonFreeman 6:f289a49c1eae 57 char motoradir, motorbdir, gang, svo1, svo2, comm_src, id, wheeldia, motpin, wheelgear, spare;
JonFreeman 6:f289a49c1eae 58 } ;
JonFreeman 10:e40d8724268a 59
JonFreeman 10:e40d8724268a 60 //const double SERVOIN_PWR_BENDER = 1.5; // Used to change servo_in stick at centre position to match pot approx 1/3 braking 2/3 driving
JonFreeman 11:bfb73f083009 61 #endif
JonFreeman 11:bfb73f083009 62