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
DualBLS.h
- Committer:
- JonFreeman
- Date:
- 2019-01-15
- Revision:
- 10:e40d8724268a
- Parent:
- 8:93203f473f6e
- Child:
- 11:bfb73f083009
File content as of revision 10:e40d8724268a:
const int HANDBRAKE = 0, FORWARD = 8, REVERSE = 16, REGENBRAKE = 24; const int TIMEOUT_SECONDS = 30; /* Please Do Not Alter these */ const int PWM_PRESECALER_DEFAULT = 5, VOLTAGE_READ_INTERVAL_US = 50, // Interrupts timed every 50 micro sec, runs around loop performing 1 A-D conversion per pass MAIN_LOOP_REPEAT_TIME_US = 31250, // 31250 us, with TACHO_TAB_SIZE = 32 means tacho_ticks_per_time is tacho_ticks_per_second MAIN_LOOP_ITERATION_Hz = 1000000 / MAIN_LOOP_REPEAT_TIME_US, CURRENT_SAMPLES_AVERAGED = 100, // Current is spikey. Reading smoothed by using average of this many latest current readings PWM_HZ = 15000, // chosen to be above cutoff frequency of average human ear MAX_PWM_TICKS = (SystemCoreClock / (PWM_HZ * PWM_PRESECALER_DEFAULT)), TICKLE_TIMES = 100 , WATCHDOG_RELOAD = (TIMEOUT_SECONDS * 8); // WatchDog counter ticked down in 8Hz loop /* End of Please Do Not Alter these */ const double PI = 4.0 * atan(1.0), TWOPI = 8.0 * atan(1.0); //enum {MOTADIR, MOTBDIR, GANG, SVO1, SVO2, COMM_SRC, ID, WHEELDIA, MOTPIN, WHEELGEAR} ; // Identical in TS and DualBLS enum {MOTADIR, MOTBDIR, GANG, SVO1, SVO2, COMM_SRC, ID, WHEELDIA, MOTPIN, WHEELGEAR, BOGHUNWAT, FUT1, FUT2, FUT3, FUT4, FUT5} ; // Identical in TS and DualBLS struct optpar { int min, max, def; // min, max, default const char * t; // description } ; struct optpar const option_list[] = { {0, 1, 1, "MotorA direction 0 or 1"}, {0, 1, 0, "MotorB direction 0 or 1"}, {0, 1, 1, "gang 0 for separate control (robot mode), 1 for ganged loco bogie mode"}, {0, 2, 2, "Servo1 0, 1, 2 = Not used, Input, Output"}, {0, 2, 2, "Servo2 0, 1, 2 = Not used, Input, Output"}, {1, 5, 2, "Command source 0 Invalid, 1 COM1, 2 COM2, 3 Pot, 4 Servo1, 5 Servo2"}, {'1', '9', '0', "Alternative ID ascii '1' to '9'"}, // defaults to '0' before eerom setup for first time {50, 253, 98, "Wheel diameter mm"}, // New 01/06/2018 {10, 253, 27, "Motor pinion"}, // New 01/06/2018 {50, 253, 85, "Wheel gear"}, // New 01/06/2018 {1, 20, 4, "Bogie power closest hundreds of Watt"}, // New 22/06/2018 {0, 100, 0, "Future 1"}, {0, 100, 0, "Future 2"}, {0, 100, 0, "Future 3"}, {0, 100, 0, "Future 4"}, {0, 100, 0, "Future 5"}, } ; const int numof_eeprom_options = sizeof(option_list) / sizeof (struct optpar); struct single_bogie_options { char motoradir, motorbdir, gang, svo1, svo2, comm_src, id, wheeldia, motpin, wheelgear, spare; } ; //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