STM3 Twin Brushless Motor Electronic Speed Controller

Dependencies:   BufferedSerial FastPWM Servo mbed

DualBLS.h

Committer:
JonFreeman
Date:
4 weeks ago
Revision:
7:6deaeace9a3e
Parent:
6:f289a49c1eae

File content as of revision 7:6deaeace9a3e:

const   int     HANDBRAKE   = 0,
                FORWARD     = 8,
                REVERSE     = 16,
                REGENBRAKE  = 24;

const   int     TIMEOUT_SECONDS = 30;

/*  Please Do Not Alter these */
const   int     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              = 16000,    //  chosen to be above cutoff frequency of average human ear
                MAX_PWM_TICKS       = (SystemCoreClock / PWM_HZ),
                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
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
    {20, 253, 98,  "Wheel diameter mm"},   //  New 01/06/2018
    {10, 253, 27,  "Motor pinion"},   //  New 01/06/2018
    {20, 253, 85,  "Wheel gear"},   //  New 01/06/2018
}   ;
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;
}   ;