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
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 7:6deaeace9a3e 1 // Hoped to select servo functions from user info stored on EEROM. Too difficult. Do not define servo as in and out
JonFreeman 7:6deaeace9a3e 2
JonFreeman 7:6deaeace9a3e 3 // Port A -> MotorA, Port B -> MotorB
JonFreeman 7:6deaeace9a3e 4 const uint16_t
JonFreeman 7:6deaeace9a3e 5 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
JonFreeman 7:6deaeace9a3e 6 AVL = 1 << 6, // These are which port bits connect to which mosfet driver
JonFreeman 7:6deaeace9a3e 7 AWL = 1 << 4,
JonFreeman 7:6deaeace9a3e 8
JonFreeman 7:6deaeace9a3e 9 AUH = 1 << 1,
JonFreeman 7:6deaeace9a3e 10 AVH = 1 << 7,
JonFreeman 7:6deaeace9a3e 11 AWH = 1 << 8,
JonFreeman 7:6deaeace9a3e 12
JonFreeman 7:6deaeace9a3e 13 AUV = AUH | AVL, // Each of 6 possible output energisations made up of one hi and one low
JonFreeman 7:6deaeace9a3e 14 AVU = AVH | AUL,
JonFreeman 7:6deaeace9a3e 15 AUW = AUH | AWL,
JonFreeman 7:6deaeace9a3e 16 AWU = AWH | AUL,
JonFreeman 7:6deaeace9a3e 17 AVW = AVH | AWL,
JonFreeman 7:6deaeace9a3e 18 AWV = AWH | AVL,
JonFreeman 7:6deaeace9a3e 19
JonFreeman 7:6deaeace9a3e 20 KEEP_L_MASK_A = AUL | AVL | AWL,
JonFreeman 7:6deaeace9a3e 21 KEEP_H_MASK_A = AUH | AVH | AWH,
JonFreeman 7:6deaeace9a3e 22
JonFreeman 7:6deaeace9a3e 23 BRA = AUL | AVL | AWL, // All low side switches on (and all high side off) for braking
JonFreeman 7:6deaeace9a3e 24
JonFreeman 7:6deaeace9a3e 25 BUL = 1 << 0, // Likewise for MotorB but different port bits on different port
JonFreeman 7:6deaeace9a3e 26 BVL = 1 << 1,
JonFreeman 7:6deaeace9a3e 27 BWL = 1 << 2,
JonFreeman 7:6deaeace9a3e 28
JonFreeman 7:6deaeace9a3e 29 BUH = 1 << 10,
JonFreeman 7:6deaeace9a3e 30 BVH = 1 << 12,
JonFreeman 7:6deaeace9a3e 31 BWH = 1 << 13,
JonFreeman 7:6deaeace9a3e 32
JonFreeman 7:6deaeace9a3e 33 BUV = BUH | BVL,
JonFreeman 7:6deaeace9a3e 34 BVU = BVH | BUL,
JonFreeman 7:6deaeace9a3e 35 BUW = BUH | BWL,
JonFreeman 7:6deaeace9a3e 36 BWU = BWH | BUL,
JonFreeman 7:6deaeace9a3e 37 BVW = BVH | BWL,
JonFreeman 7:6deaeace9a3e 38 BWV = BWH | BVL,
JonFreeman 7:6deaeace9a3e 39
JonFreeman 7:6deaeace9a3e 40 KEEP_L_MASK_B = BUL | BVL | BWL,
JonFreeman 7:6deaeace9a3e 41 KEEP_H_MASK_B = BUH | BVH | BWH,
JonFreeman 7:6deaeace9a3e 42
JonFreeman 7:6deaeace9a3e 43 BRB = BUL | BVL | BWL,
JonFreeman 7:6deaeace9a3e 44
JonFreeman 7:6deaeace9a3e 45 PORT_A_MASK = AUL | AVL | AWL | AUH | AVH | AWH, // NEW METHOD FOR DGD21032 MOSFET DRIVERS
JonFreeman 7:6deaeace9a3e 46 PORT_B_MASK = BUL | BVL | BWL | BUH | BVH | BWH;
JonFreeman 7:6deaeace9a3e 47
JonFreeman 7:6deaeace9a3e 48 PortOut MotA (PortA, PORT_A_MASK); // Activate output ports to motor drivers
JonFreeman 7:6deaeace9a3e 49 PortOut MotB (PortB, PORT_B_MASK);
JonFreeman 7:6deaeace9a3e 50
JonFreeman 7:6deaeace9a3e 51 // Pin 1 VBAT NET +3V3
JonFreeman 7:6deaeace9a3e 52
JonFreeman 7:6deaeace9a3e 53 //DigitalIn J3 (PC_13, PullUp);// Pin 2 Jumper pulls to GND, R floats Hi
JonFreeman 7:6deaeace9a3e 54 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
JonFreeman 7:6deaeace9a3e 55
JonFreeman 7:6deaeace9a3e 56
JonFreeman 7:6deaeace9a3e 57 // Pin 3 PC14-OSC32_IN NET O32I
JonFreeman 7:6deaeace9a3e 58 // Pin 4 PC15-OSC32_OUT NET O32O
JonFreeman 7:6deaeace9a3e 59 // Pin 5 PH0-OSC_IN NET PH1
JonFreeman 7:6deaeace9a3e 60 // Pin 6 PH1-OSC_OUT NET PH1
JonFreeman 7:6deaeace9a3e 61 // Pin 7 NRST NET NRST
JonFreeman 7:6deaeace9a3e 62 AnalogIn Ain_DriverPot (PC_0); // Pin 8 Spare Analogue in, net SAIN fitted with external pull-down
JonFreeman 7:6deaeace9a3e 63 AnalogIn Ain_SystemVolts (PC_1); // Pin 9
JonFreeman 7:6deaeace9a3e 64 AnalogIn Motor_A_Current (PC_2); // Pin 10
JonFreeman 7:6deaeace9a3e 65 AnalogIn Motor_B_Current (PC_3); // Pin 11
JonFreeman 7:6deaeace9a3e 66 // Pin 12 VSSA/VREF- NET GND
JonFreeman 7:6deaeace9a3e 67 // Pin 13 VDDA/VREF+ NET +3V3
JonFreeman 7:6deaeace9a3e 68 // Pin 14 Port_A AUL
JonFreeman 7:6deaeace9a3e 69 // Pin 15 Port_A AUH
JonFreeman 7:6deaeace9a3e 70 // Pins 16, 17 BufferedSerial pc
JonFreeman 7:6deaeace9a3e 71 BufferedSerial pc (PA_2, PA_3, 512, 4, NULL); // Pins 16, 17 tx, rx to pc via usb lead
JonFreeman 7:6deaeace9a3e 72 // Pin 18 VSS NET GND
JonFreeman 7:6deaeace9a3e 73 // Pin 19 VDD NET +3V3
JonFreeman 7:6deaeace9a3e 74 // Pin 20 Port_A AWL
JonFreeman 7:6deaeace9a3e 75 // Pin 21 DigitalOut led1(LED1);
JonFreeman 7:6deaeace9a3e 76 DigitalOut LED (PA_5); // Pin 21
JonFreeman 7:6deaeace9a3e 77 // Pin 22 Port_A AVL
JonFreeman 7:6deaeace9a3e 78 // Pin 23 Port_A AVH
JonFreeman 7:6deaeace9a3e 79 InterruptIn MBH2 (PC_4); // Pin 24
JonFreeman 7:6deaeace9a3e 80 InterruptIn MBH3 (PC_5); // Pin 25
JonFreeman 7:6deaeace9a3e 81 // Pin 26 Port_B BUL
JonFreeman 7:6deaeace9a3e 82 // Pin 27 Port_B BVL
JonFreeman 7:6deaeace9a3e 83 // Pin 28 Port_B BWL
JonFreeman 7:6deaeace9a3e 84 // Pin 29 Port_B BUH
JonFreeman 7:6deaeace9a3e 85 // Pin 30 VCAP1
JonFreeman 7:6deaeace9a3e 86 // Pin 31 VSS
JonFreeman 7:6deaeace9a3e 87 // Pin 32 VDD
JonFreeman 7:6deaeace9a3e 88 // Pin 33 Port_B BVH
JonFreeman 7:6deaeace9a3e 89 // Pin 34 Port_B BWH
JonFreeman 7:6deaeace9a3e 90 DigitalOut T4 (PB_14); // Pin 35
JonFreeman 7:6deaeace9a3e 91 DigitalOut T3 (PB_15); // Pin 36
JonFreeman 7:6deaeace9a3e 92 // BufferedSerial com2 pins 37 Tx, 38 Rx
JonFreeman 7:6deaeace9a3e 93 BufferedSerial com2 (PC_6, PC_7); // Pins 37, 38 tx, rx to XBee module
JonFreeman 7:6deaeace9a3e 94 FastPWM A_MAX_V_PWM (PC_8, 1), // Pin 39 pwm3/3
JonFreeman 7:6deaeace9a3e 95 A_MAX_I_PWM (PC_9, 1); // pin 40, prescaler value pwm3/4
JonFreeman 7:6deaeace9a3e 96 //InterruptIn MotB_Hall (PA_8); // Pin 41
JonFreeman 7:6deaeace9a3e 97 // Pin 41 Port_A AWH
JonFreeman 7:6deaeace9a3e 98 // BufferedSerial com3 pins 42 Tx, 43 Rx
JonFreeman 7:6deaeace9a3e 99 //InterruptIn tryseredge (PA_9);
JonFreeman 7:6deaeace9a3e 100 BufferedSerial com3 (PA_9, PA_10); // Pins 42, 43 tx, rx to any aux module
JonFreeman 7:6deaeace9a3e 101 // PA_9 is Tx. I wonder, can we also use InterruptIn on this pin to generate interrupts on tx bit transitions ? Let's find out !
JonFreeman 7:6deaeace9a3e 102 // No.
JonFreeman 7:6deaeace9a3e 103
JonFreeman 7:6deaeace9a3e 104 // Feb 2018 Pins 44 and 45 now liberated, could use for serial or other uses
JonFreeman 7:6deaeace9a3e 105 //BufferedSerial extra_ser (PA_11, PA_12); // Pins 44, 45 tx, rx to XBee module
JonFreeman 7:6deaeace9a3e 106 DigitalOut T2 (PA_11); // Pin 44
JonFreeman 7:6deaeace9a3e 107 // was DigitalOut T1 (PA_12); // Pin 45
JonFreeman 7:6deaeace9a3e 108
JonFreeman 7:6deaeace9a3e 109
JonFreeman 7:6deaeace9a3e 110 //InterruptIn T1 (PA_12); // Pin 45 now input counting pulses from LMT01 temperature sensor
JonFreeman 7:6deaeace9a3e 111 // InterruptIn DOES NOT WORK ON PA_12. Boards are being made, will have to wire link PA12 to PC13
JonFreeman 7:6deaeace9a3e 112 DigitalIn T1 (PA_12);
JonFreeman 7:6deaeace9a3e 113 ////InterruptIn T1 (PC_13); // Pin 45 now input counting pulses from LMT01 temperature sensor
JonFreeman 7:6deaeace9a3e 114
JonFreeman 7:6deaeace9a3e 115
JonFreeman 7:6deaeace9a3e 116
JonFreeman 7:6deaeace9a3e 117 // Pin 46 SWDIO
JonFreeman 7:6deaeace9a3e 118 // Pin 47 VSS
JonFreeman 7:6deaeace9a3e 119 // Pin 48 VDD
JonFreeman 7:6deaeace9a3e 120 // Pin 49 SWCLK
JonFreeman 7:6deaeace9a3e 121
JonFreeman 7:6deaeace9a3e 122 //Was DigitalOut T5 (PA_15); // Pin 50
JonFreeman 7:6deaeace9a3e 123 DigitalIn T5 (PA_15); // Pin 50 now fwd/rev from remote control box if fitted
JonFreeman 7:6deaeace9a3e 124 InterruptIn MAH1 (PC_10); // Pin 51
JonFreeman 7:6deaeace9a3e 125 InterruptIn MAH2 (PC_11); // Pin 52
JonFreeman 7:6deaeace9a3e 126 InterruptIn MAH3 (PC_12); // Pin 53
JonFreeman 7:6deaeace9a3e 127 InterruptIn MBH1 (PD_2); // Pin 54
JonFreeman 7:6deaeace9a3e 128 DigitalOut T6 (PB_3); // Pin 55
JonFreeman 7:6deaeace9a3e 129 FastPWM B_MAX_V_PWM (PB_4, 1), // Pin 56 pwm3/3
JonFreeman 7:6deaeace9a3e 130 B_MAX_I_PWM (PB_5, 1); // pin 57, prescaler value pwm3/4
JonFreeman 7:6deaeace9a3e 131
JonFreeman 7:6deaeace9a3e 132 I2C i2c (PB_7, PB_6); // Pins 58, 59 For 24LC64 eeprom
JonFreeman 7:6deaeace9a3e 133 // Pin 60 BOOT0
JonFreeman 7:6deaeace9a3e 134
JonFreeman 7:6deaeace9a3e 135 // Servo pins, 2 off. Configured as Input to read radio control receiver
JonFreeman 7:6deaeace9a3e 136 // If used as servo output, code gives pin to 'Servo' - seems to work
JonFreeman 7:6deaeace9a3e 137 InterruptIn Servo1_i (PB_8); // Pin 61 to read output from rc rx
JonFreeman 7:6deaeace9a3e 138 InterruptIn Servo2_i (PB_9); // Pin 62 to read output from rc rx
JonFreeman 7:6deaeace9a3e 139
JonFreeman 7:6deaeace9a3e 140 // Pin 63 VSS
JonFreeman 7:6deaeace9a3e 141 // Pin 64 VDD
JonFreeman 7:6deaeace9a3e 142 // SYSTEM CONSTANTS
JonFreeman 7:6deaeace9a3e 143