# Self-made motor controller: Design & Layout
The design of the self-made motor controller is based on the hardware files [1] of the BOOSTXL-DRV8301 motor driver released by Texas Instruments. I have tested the BOOSTXL-DRV8301 motor driver with the motor used in my leg-mechanism, but the motor driver dose not fit in with my application. To meet the requirements of my application, the motor driver needs some improvements, such as: (i)adding a reliable CAN-bus transmitting module, (ii)adding a magnetic encoder module for motor position sensing, and (iii)increasing its peak current to 28A. The 28A peak current is the saturation current of the motor used in my leg-mechanism. The self-made motor controller with those improvements are completed and tested.
## Hardware Design & Schematics
### 1. CAN-bus transmitting module
The schematic of the CAN-bus module is shown below. It is a typical CAN-bus module with Transient Voltage Suppression and Split Termination. The R57, C61, and C62 are optional. The R57 is for grounding the shield of CAN-bus cables. The capacitor values of C61 and C62 depend on the voltage ripple of the CAN-bus signal; the C61 and C62 are unnecessary for a CAN-bus signal with low noise.

### 2. Magnetic encoder module
The schematic of the magnetic encoder module is shown below. It is exactly the circuit recommended by AS5147P datasheet. AS5147P chip is a 14-Bit magnetic rotary position sensor, which supports not only ABI and UVW interfaces but also SPI interface. The programmable SPI interface allows a master MUC (motor controller chip in this case) to set AS5147P configurations, such as: zero position, resolution, and hysteresis.

### 3. Increasing peak current to 28A
To improve the peak current capacity of my motor controller, I designed the motor controller in two ways: (i)compatibility with the phase current sensing circuit of the motor driver and (ii)thermal limitation.
#### (i)compatibility with the phase current sensing circuit
The phase current sensing circuit of TI's BOOSTXL-DRV8301 motor driver are shown below. In my motor controller, I redesigned two parts of the circuit. The first one is that I replaced the R36 with a 3W 0.0025 $\Omega$ shunt resistor. The second one is that I changed the resistor values of R43 and R47 to 20k $\Omega$. With those alternative design, the phase current sensing circuit is compatible with 28A peak current.
$$
I_{peak} = 28.28 A \Rightarrow I_{rms} = 20 A
$$
In the first part of my redesign, I choose the 3W 0.0025 $\Omega$ shunt resistor because power loss on the shunt resistor sholud be less than its power rating (3W). For the design mentioned above, the power loss is 1W.
$$
P = I_{rms}^2R_{shunt} = 20^2 \times 0.0025 = 1 W
$$

In the second part, the voltage output range ($\Delta V_{ICFB}$) of the phase current sensing circuit should be fit in with the working range of controller's ADC. For my motor controller chip, Texas Instruments TMS320F28069M, the working voltage range of ADC is 3.3 V. The $\Delta V_{ICFB}$ of my motor controller is 2.828 V. It is compatible with the ADC of TMS320F28069M.
$$
\Delta V_{ICFB} = \Delta I_{peak}R_{shunt}{R43 \over R44} = \pm28.28 \times 0.0025 \times 20 = \pm1.414 V
$$

#### (ii)thermal limitation
Even though, in my motor controller, the phase current sensing circuit is well-designed to fit the saturation current of the motor and the voltage range of the ADC, the power transistors in the motor controller would be overheated and broken without proper cooling conditions. To solve the problem, I select CSD18540, Power MOSFET produced by Texas Instruments, for my motor controller rather than CSD18533 in BOOSTXL-DRV8301. CSD18540 could hold higher current because it have lower Drain-to-Source On Resistance than CSD18533. According to the datasheet of CSD18540, the Continuous Drain Current could be 29A on a $6.45cm^2$ and 2oz copper pad; the area and thickness of the copper pad should be one of the PCB layout rules for my motor controller board.
## PCB Layout
The PCB of my motor controller is a 4-layer board with 2oz copper on both Top layer and Bottom layer. The four layers are Top layer, Vcc layer, Gnd layer, and Bottom layer. The layout of the Top layer and Bottom layer are shown below. For default PCB layout, general layout rules are 8mil minimal line width and 10mil minimal gap width. For the high power section (24Vdc bus voltage), the rules are 12mil minimal line width and 24mil minimal gap width. Furthermore, for the High/Low side Power MOSFET sections, some specific layout rules have to be followed.


### Layout of the High/Low Power MOSFET sections
In the Power MOSFET sections, which are enclosed by the black lines and the green lines, the width of copper traces and the number of VIA holes are constrained by $I_{rms} = 20 A$. Under such constraint, the width of copper traces should be at least 5.9mm; the number of VIA hols should not be less than 10 because a single VIA hole with 0.3mm diameter could bear 2.2A. Likewise, the total area of green/black section is limited by the thermal limitation of CSD18540 Power MOSFET. As mentioned above, my motor controller needs $6.45cm^2$ of copper area for a single CSD18540. In both the High and the Low side Power MOSFET sections, there are three CSD18540. I must layout a $20cm^2$ copper area for the both sections.
## PCB Soldering
Sent the gerber files of my motor controller to a PCB factory and Got the PCBs.
Checking out the hole sizes for power connector and motor connector.

After exhausting work on soldering, I completed the eight motor controllers for the four 2-Dof leg-mechanisms.

## Reference
[1] http://www.ti.com/tool/BOOSTXL-DRV8301