Dual Brushless Motor ESC, 10-62V, up to 50A per motor. Motors ganged or independent, multiple control input methods, cycle-by-cycle current limit, speed mode and torque mode control. Motors tiny to kW. Speed limit and other parameters easily set in firmware. As used in 'The Brushless Brutalist' locomotive - www.jons-workshop.com. See also Model Engineer magazine June-October 2019.

Dependencies:   mbed BufferedSerial Servo PCT2075 FastPWM

Update 17th August 2020 Radio control inputs completed

Revision:
10:e40d8724268a
Parent:
9:ac2412df01be
Child:
11:bfb73f083009
--- a/F401RE.h	Sat Nov 10 17:08:21 2018 +0000
+++ b/F401RE.h	Tue Jan 15 09:03:57 2019 +0000
@@ -1,41 +1,63 @@
-//  Hoped to select servo functions from user info stored on EEROM. Too difficult. Do not define servo as in and out
+//  Feb 2018 Now using DGD21032 mosfet drivers via 74HC00 pwm gates (low side) - GOOD, works well with auto-tickle of high side drivers
+
+//  Jan 2019    Trying to add two Radio Control inputs on PC_14 and PC_15, previously connected to unused LF Xtal. 
+//              Problem - Appears to conflict with serial port used for comms with controller
+//              Earlier efforts to use 'Servo' ports as 'you choose' between I/O failed as pins not capable of use as 'InterruptIn'
+
+//                  Experiment disabling RC inputs to see if clearing serial conflict is possible
+
+//#define RC1IN
+//#define RC2IN
+
+
 
 //  Port A -> MotorA, Port B -> MotorB
 const   uint16_t
-AUL = 1 << 0,   //  Feb 2018 Now using DGD21032 mosfet drivers via 74HC00 pwm gates (low side) - GOOD, works well with auto-tickle of high side drivers
-AVL = 1 << 6,   //  These are which port bits connect to which mosfet driver
-AWL = 1 << 4,
+//  This is where port bits get assigned to motor output phase switches.
+//  Phases are U, V and W.
+//  Each phase uses two bits, one for the low side switch, one for the high side switch.
+//MotorN_port_bits[] =  {UL, VL, WL, UH, VH, WH},   //  Order must be as shown - 3 low side switches U,V,W followed by 3 high side switches U,V,W
+MotorA_port_bits[] =    {0,  6,  4,  1,  7,  8},    //  List of port A bits used to drive motor A UL, VL, WL, UH, VH, WH
+MotorB_port_bits[] =    {0,  1,  2, 10, 12, 13},    //  List of port B bits used to drive motor B UL, VL, WL, UH, VH, WH
+//  Using port bit info in the two lines above, the compiler sorts all this into creation of lookup table
+//  to provide correct energisation sequencing as motors rotate.
+//  You need concern yourself no further about any of this.
+
 
-AUH = 1 << 1,
-AVH = 1 << 7,
-AWH = 1 << 8,
+AUL = (1 << MotorA_port_bits[0]),
+AVL = (1 << MotorA_port_bits[1]),   //  These are which port bits connect to which mosfet driver
+AWL = (1 << MotorA_port_bits[2]),
 
-AUV =   AUH | AVL,  //  Each of 6 possible output energisations made up of one hi and one low
-AVU =   AVH | AUL,
-AUW =   AUH | AWL,
-AWU =   AWH | AUL,
-AVW =   AVH | AWL,
-AWV =   AWH | AVL,
+AUH = (1 << MotorA_port_bits[3]),
+AVH = (1 << MotorA_port_bits[4]),
+AWH = (1 << MotorA_port_bits[5]),
+
+AUHVL =   AUH | AVL,  //  Each of 6 possible output energisations made up of one hi and one low
+AVHUL =   AVH | AUL,
+AUHWL =   AUH | AWL,
+AWHUL =   AWH | AUL,
+AVHWL =   AVH | AWL,
+AWHVL =   AWH | AVL,
 
 KEEP_L_MASK_A   = AUL | AVL | AWL,
 KEEP_H_MASK_A   = AUH | AVH | AWH,
 
 BRA = AUL | AVL | AWL,  //  All low side switches on (and all high side off) for braking
 
-BUL = 1 << 0,   //  Likewise for MotorB but different port bits on different port
-BVL = 1 << 1,
-BWL = 1 << 2,
+BUL = (1 << MotorB_port_bits[0]),   //  Likewise for MotorB but different port bits on different port
+BVL = (1 << MotorB_port_bits[1]),
+BWL = (1 << MotorB_port_bits[2]),
 
-BUH = 1 << 10,
-BVH = 1 << 12,
-BWH = 1 << 13,
+BUH = (1 << MotorB_port_bits[3]),
+BVH = (1 << MotorB_port_bits[4]),
+BWH = (1 << MotorB_port_bits[5]),
 
-BUV =   BUH | BVL,
-BVU =   BVH | BUL,
-BUW =   BUH | BWL,
-BWU =   BWH | BUL,
-BVW =   BVH | BWL,
-BWV =   BWH | BVL,
+BUHVL =   BUH | BVL,
+BVHUL =   BVH | BUL,
+BUHWL =   BUH | BWL,
+BWHUL =   BWH | BUL,
+BVHWL =   BVH | BWL,
+BWHVL =   BWH | BVL,
 
 KEEP_L_MASK_B   = BUL | BVL | BWL,
 KEEP_H_MASK_B   = BUH | BVH | BWH,
@@ -54,7 +76,14 @@
 InterruptIn   Temperature_pin   (PC_13);//  Pin 2   June 2018 - taken for temperature sensor - hard wired to T1 due to wrong thought T1 could be InterruptIn
 
 
-//  Pin 3   PC14-OSC32_IN   NET O32I
+#ifdef  RC1IN
+InterruptIn     RC_1_in (PC_14);    //New Dec 2018 tryiing to find pins to use for servo in
+#endif
+#ifdef  RC2IN
+InterruptIn     RC_2_in (PC_15);    //Yes, PC_14 and PC_15 do work
+#endif
+
+//  Pin 3   PC14-OSC32_IN   NET O32I    Xtal chucked off these pins, now needed for RC inputs
 //  Pin 4   PC15-OSC32_OUT  NET O32O
 //  Pin 5   PH0-OSC_IN      NET PH1
 //  Pin 6   PH1-OSC_OUT     NET PH1
@@ -133,9 +162,12 @@
 //  Pin 60  BOOT0
 
 //  Servo pins, 2 off. Configured as Input to read radio control receiver
+//      ** Update December 2018 **
+//  These pins can not be used as InterruptIn.
+//  Can be used as outputs by 'Servo'
 //  If used as servo output, code gives pin to 'Servo' - seems to work
-InterruptIn Servo1_i    (PB_8); //  Pin 61  to read output from rc rx
-InterruptIn Servo2_i    (PB_9); //  Pin 62  to read output from rc rx
+//InterruptIn Servo1_i    (PB_8); //  Pin 61  to read output from rc rx
+//InterruptIn Servo2_i    (PB_9); //  Pin 62  to read output from rc rx
 //  *** NOTE *** Above InterruptIn Servo using PB pins seems not to work, probably due to other Port B pins used as PortOut (try PortInOut?)
 //  Nov 2018 - Yet to try using PC14, PC15, free now as 32k768 xtal not fitted