STM3 ESC dual brushless motor controller. 10-60v, motor power rating tiny to kW. Ganged or independent motor control As used in 'The Brute' locomotive - www.jons-workshop.com

Dependencies:   mbed BufferedSerial Servo FastPWM

Committer:
JonFreeman
Date:
Tue Jun 05 07:19:39 2018 +0000
Revision:
6:f289a49c1eae
Parent:
5:ca86a7848d54
Child:
7:6deaeace9a3e
Migrating towards code for both STM32F401RET (64 pin) and STM32F446ZET7 (144 pin). Should resolve IO conflicts for larger device - getting servo ins and outs working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 2:04761b196473 1 //#define POWER_OF_TWO 12 // Range is 4 to 13, is log2N
JonFreeman 2:04761b196473 2 //typedef float ffty; // Choice of float or double float is HUGELY FASTER than double
JonFreeman 2:04761b196473 3 const int HANDBRAKE = 0,
JonFreeman 2:04761b196473 4 FORWARD = 8,
JonFreeman 2:04761b196473 5 REVERSE = 16,
JonFreeman 2:04761b196473 6 REGENBRAKE = 24;
JonFreeman 3:ecb00e0e8d68 7
JonFreeman 5:ca86a7848d54 8 const int TIMEOUT_SECONDS = 30;
JonFreeman 5:ca86a7848d54 9
JonFreeman 5:ca86a7848d54 10 /* Please Do Not Alter these */
JonFreeman 5:ca86a7848d54 11 const int VOLTAGE_READ_INTERVAL_US = 50, // Interrupts timed every 50 micro sec, runs around loop performing 1 A-D conversion per pass
JonFreeman 5:ca86a7848d54 12 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 13 MAIN_LOOP_ITERATION_Hz = 1000000 / MAIN_LOOP_REPEAT_TIME_US,
JonFreeman 5:ca86a7848d54 14 CURRENT_SAMPLES_AVERAGED = 100, // Current is spikey. Reading smoothed by using average of this many latest current readings
JonFreeman 5:ca86a7848d54 15 PWM_HZ = 16000, // chosen to be above cutoff frequency of average human ear
JonFreeman 5:ca86a7848d54 16 MAX_PWM_TICKS = (SystemCoreClock / PWM_HZ),
JonFreeman 5:ca86a7848d54 17 TICKLE_TIMES = 100 ,
JonFreeman 5:ca86a7848d54 18 WATCHDOG_RELOAD = (TIMEOUT_SECONDS * 8); // WatchDog counter ticked down in 8Hz loop
JonFreeman 5:ca86a7848d54 19
JonFreeman 5:ca86a7848d54 20 /* End of Please Do Not Alter these */
JonFreeman 3:ecb00e0e8d68 21 const double PI = 4.0 * atan(1.0),
JonFreeman 3:ecb00e0e8d68 22 TWOPI = 8.0 * atan(1.0);
JonFreeman 5:ca86a7848d54 23
JonFreeman 6:f289a49c1eae 24 enum {MOTADIR, MOTBDIR, GANG, SVO1, SVO2, COMM_SRC, ID, WHEELDIA, MOTPIN, WHEELGEAR} ; // Identical in TS and DualBLS
JonFreeman 5:ca86a7848d54 25 struct optpar {
JonFreeman 5:ca86a7848d54 26 int min, max, def; // min, max, default
JonFreeman 5:ca86a7848d54 27 const char * t; // description
JonFreeman 5:ca86a7848d54 28 } ;
JonFreeman 5:ca86a7848d54 29 struct optpar const option_list[] = {
JonFreeman 5:ca86a7848d54 30 {0, 1, 1, "MotorA direction 0 or 1"},
JonFreeman 5:ca86a7848d54 31 {0, 1, 0, "MotorB direction 0 or 1"},
JonFreeman 5:ca86a7848d54 32 {0, 1, 1, "gang 0 for separate control (robot mode), 1 for ganged loco bogie mode"},
JonFreeman 5:ca86a7848d54 33 {0, 2, 2, "Servo1 0, 1, 2 = Not used, Input, Output"},
JonFreeman 5:ca86a7848d54 34 {0, 2, 2, "Servo2 0, 1, 2 = Not used, Input, Output"},
JonFreeman 5:ca86a7848d54 35 {1, 5, 2, "Command source 0 Invalid, 1 COM1, 2 COM2, 3 Pot, 4 Servo1, 5 Servo2"},
JonFreeman 5:ca86a7848d54 36 {'1', '9', '0', "Alternative ID ascii '1' to '9'"}, // defaults to '0' before eerom setup for first time
JonFreeman 6:f289a49c1eae 37 {50, 250, 98, "Wheel diameter mm"}, // New 01/06/2018
JonFreeman 6:f289a49c1eae 38 {10, 250, 27, "Motor pinion"}, // New 01/06/2018
JonFreeman 6:f289a49c1eae 39 {50, 250, 85, "Wheel gear"}, // New 01/06/2018
JonFreeman 5:ca86a7848d54 40 } ;
JonFreeman 6:f289a49c1eae 41 const int numof_eeprom_options = sizeof(option_list) / sizeof (struct optpar);
JonFreeman 5:ca86a7848d54 42
JonFreeman 6:f289a49c1eae 43 struct single_bogie_options {
JonFreeman 6:f289a49c1eae 44 char motoradir, motorbdir, gang, svo1, svo2, comm_src, id, wheeldia, motpin, wheelgear, spare;
JonFreeman 6:f289a49c1eae 45 } ;