Sunday, September 14, 2014

MechEtroller-the barebones brushed motor controller

With Obligatory 3d printer awaiting yet more parts before commencing construction, I'd like to take a break to introduce a new project that has been in the works for a few weeks. Introducing MechEtroller: the alarming result of a mechanical engineering major attempting to build his first motor controller. Living true to its name, version 1 has successfully trolled a certain MechE from the get go.


Before diving in, I'll call attention to my last electronics endeavor, Mini ATmega328 board. Started way back in Freshman year, this board was my first PCB, first introduction to SMD soldering, and first real introduction to the world of embedded hardware. It failed due to a laughable mistake shorting logic power to ground when the reset pin was pulled down. Development did not continue on that board, but it inspired me to keep playing around with electronics for the last two years. While there are now enough inexpensive Arduino clones to render the economics argument behind making the board void, I don't think the same can be said for brushed motor controllers.

Most of the hobby motor controllers I've used in the past have been expensive and occasionally unreliable (case in point: Sabertooth 2x60). I won't pretend to think I can produce the same quality of motor controller for less, but it does make the idea of a custom motor controller that much more tempting. After a year of playing around with H-bridges and releasing smoke from MOSFETs, I decided to try and get serious with this.

MechEtroller is relatively simple as far a motor controllers go: an H-bridge based DC brushed motor controller in the 20 amp range. I don't do many projects above 36 volts outside of RPI Hybrid, so I set an input voltage range of 12-36 volts as my goal. This is low enough that I can find a pair of linear voltage regulators to bring it down to gate drive and logic levels without too much trouble. I'm also making life easy by choosing a relatively low gate drive voltage such that I don't have to boost the 12 volt lower limit. The microcontroller is a typical ATMega 328 smd chip, which will either run an Arduino bootloader or be programmed in Atmel C if I want to get lower level with some of the functionality. An FTDI header is on the board to allow programming, and ICSP flashing of the chip with happen with this sweet pogo pin programmer.

That's pretty much all there is to the logic side of things. A couple of resistors provide current limiting for LEDs and pull down for inputs. Most of the tiny caps on the board are for the voltage rregulators with the exception of the huge capacitor footprint at the top, which is for decoupling the battery power line. The board allows TTL serial, I2C, and analog voltages for inputs.




Moving onto the power electronics, I've selected the PSMN3R3-40YS MOSFET for the first revision of the board. While my research has indicated that the LFPAK enclosure is less than ideal for dissipating heat, I wanted to aim for the cheap end of the MOSFET spectrum. Given the brand new nature of the board, these FETs had a 100% likelihood of death, so there was no point in splurging for nicer ones. In figure 9 of the PSMN3R3-40YS datasheet you can see a very nice graph of Rds vs Vgs. This was the other motivation behind the PSMN3R3-40YS; it has (almost) minimized its on-state resistance with only 12 volts on the gate pin. 4 mOhms of resistance still leaves something to be desired, but it's acceptable for my needs!

To drive the FETs, I picked out the FAN 3111E gate driver. It meets all of the voltage and current requirements and comes in an easy to solder SOT-23 package.

 Board design proved to be the most challenging aspect of the project. A tight budget and dislike of unused board space lead me to use the smallest trace width allowed by OSH Park. This was also my first time routing a board from scratch. It took a while to get the hang of, but eventually I began to improve. Despite this, the final routing ended up very ugly and inefficient. Experienced PCB designers please avert your eyes:


This was also the first board I have ever done using copper pours. After quickly realizing that standard traces on 2-oz copper were not going to meet the current requirements of the MOSFETs, I eventually determined a configuration of the FETs that minimized the distance between component and plated hole. Connecting to the gate pins still proved tricky, but some tiny routing allowed them to sneak in. I attempted to generally confine logic and battery voltages to different sides of the board. While I wasn't completely successful, overall I was pleased with how the board layout came out. Certain component footprints were definitely pushing the limit for space (such as the reset button), but I found no issues with the placement or soldering process when the boards arrived.

The boards looked excellent on arrival from OSH Park (as usual). As I began soldering the board together, I made my first mistake. Instead of staring with the voltage regulators and logic circuit and then testing, I over eagerly soldered the entire board. While I intend to use solder paste for the FETs in the future, for the first test I just used lots of flux and heat and pre tinned the pads on the underside.

For the moment of truth, I started out on a lab power supply at 14 volts. The microcontroller was unprogrammed, so I was just looking to see the power LED turn on. Instead, I noticed that the MOSFETs immediately began heating and remelting their solder. Oops.

Thinking I had shorted two pins, I desoldered one side of the FETS so that no current could pass through the "high voltage" side. Now upon applying power, the board immediately smoked. Closer inspection revealed a voltage regulator had gone. I was suspicious of this, and mistakenly thinking I must have swapped the 12 and 5 volt regulators, resoldered two new versions in the opposite spots. No smoke this time, but an immediate and uncontrolled heating of the 328 microcontroller. Fairly confident the microcontroller was toast, I just focused on the voltage regulators. Measuring the output pin against ground revealed that the full 14 volts was flowing through the entire board. This was odd, because checking the schematic confirmed that they were in the correct orientation and properly grounded. Or were they?

After another round of regulator replacement and destruction, I tried measuring the resistance between the voltage regulator ground and power supply ground. This finally revealed the truth: my board ground appeared to not be connected to anything. In the absence of a reference ground, the poor regulators couldn't do anything to save the board. While this partially solved the puzzle, I was confused by the fact that my schematic showed all the grounds to be connected. It wasn't until closer inspection that I realized by mistake. In Eagle, you can either use a GND symbol from the component library, or simply label a line GND. In my ignorance, I attempted to use both, some on certain parts, and some on others, These two do not automatically connect, and thus there were no connections between one half of my board and the other. 

In a last ditch effort, I attempted to solder a wire from one ground to the other, and replace any components I had left:


Unfortunately, I believe that too many components were still damaged. I got one more pop noise upon applying voltage, and then unregulated voltage upon measuring the Vreg output. The fate of the first board was disappointing, but at least the error originated from labeling in Eagle, rather than a fundamental issue with the circuit design, MechEtroller will return with a new fixed board and probably some better routing. The new DigiKey parts have arrived, it's just a matter of finding the time to revise the Eagle design and send out a new OSH Park order. For future versions, I'd also like to investigate adding some cool features, like encoder input and current limiting functions.

That's all for now, check back soon for a new build update on the 3d printer.