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 May 29 16:36:34 2018 +0000
Revision:
5:ca86a7848d54
Parent:
3:ecb00e0e8d68
Child:
6:f289a49c1eae
Adding temperature sensor and fw\re input from possible hand held control box

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 5:ca86a7848d54 24 struct optpar {
JonFreeman 5:ca86a7848d54 25 int min, max, def; // min, max, default
JonFreeman 5:ca86a7848d54 26 const char * t; // description
JonFreeman 5:ca86a7848d54 27 } ;
JonFreeman 5:ca86a7848d54 28 struct optpar const option_list[] = {
JonFreeman 5:ca86a7848d54 29 {0, 1, 1, "MotorA direction 0 or 1"},
JonFreeman 5:ca86a7848d54 30 {0, 1, 0, "MotorB direction 0 or 1"},
JonFreeman 5:ca86a7848d54 31 {0, 1, 1, "gang 0 for separate control (robot mode), 1 for ganged loco bogie mode"},
JonFreeman 5:ca86a7848d54 32 {0, 2, 2, "Servo1 0, 1, 2 = Not used, Input, Output"},
JonFreeman 5:ca86a7848d54 33 {0, 2, 2, "Servo2 0, 1, 2 = Not used, Input, Output"},
JonFreeman 5:ca86a7848d54 34 {1, 5, 2, "Command source 0 Invalid, 1 COM1, 2 COM2, 3 Pot, 4 Servo1, 5 Servo2"},
JonFreeman 5:ca86a7848d54 35 {'1', '9', '0', "Alternative ID ascii '1' to '9'"}, // defaults to '0' before eerom setup for first time
JonFreeman 5:ca86a7848d54 36 } ;
JonFreeman 5:ca86a7848d54 37 const int numofopts = sizeof(option_list) / sizeof (struct optpar);
JonFreeman 5:ca86a7848d54 38