STM3 Twin Brushless Motor Electronic Speed Controller

Dependencies:   BufferedSerial FastPWM Servo mbed

Committer:
JonFreeman
Date:
Sun Jun 17 06:59:37 2018 +0000
Revision:
7:6deaeace9a3e
Parent:
6:f289a49c1eae
Firmware for STM3 Twin Brushless Motor Electronic Speed Controller; Snapshot at 17th June 2018

Who changed what in which revision?

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