Brushed Motor ESC

27 November 2005

This project documents how to build and construct your own Brushed Motor ESC using a Microchip 12F675 PIC and a small number of standard components. Various test systems are also described that allow the investigation of how ESCs function.

The ESC descibed here is primarily for aircraft. There is an associated project that is designed for cars and boats with features that are similar to commercial ESCs for this application.

Important Note

This information is provided on a 'as-is' basis. Model aircraft are not toys. Construction, and use, of this device is at the users own risk.

Most simple PIC programmers do not verify that the device has been programmed correctly by using high and low supply voltages to the PIC. This type of programmer is not normally considered a production environment programmer and there is a risk that the PIC has not been correctly programmed even when the software says it has been.


There are a number of other projects that have been documented for brushed motor ESCs. The good starting point for other ESCs is this rcgroups thread. The information in the Microchip AN847 is also very useful.

Most of these designs are very similar, the variation between designs is typically in the PIC used to control the ESC, the precise FETs used, and the number of features that the ESC offers. Some variation is also probably due to the availability and cost of parts.

There were two main reasons that I embarked on this project:

Why build your own ESC

Some of the reasons that you may consider using the information here include:

Why not to build your own

There are a number of very good reasons why you should not build and fly your own ESC. These reasons wouldn't stop you from playing with this idea to learn how it all works.

What this ESC offers

This ESC design offers the following features:

Low Voltage Cutoff

The ESC monitors the battery supply voltage and turns off the motor when the supply voltage drops below a preset point. The code as supplied operates the cutoff at 6V, this is considered a relatively safe point. The LM2940 BEC will operate down to 5.6V so stopping the motor at 6V leaves some margin for error. Once the cutoff has detected 6V or less the throttle must be reset to idle before the motor will operate.

The ESC checks the battery voltage every time a servo control pulse is received, or about every 20msec. These readings are averaged over 4 consecutive samples to get a more stable battery voltage reading. Under high load conditions it is possible to obtain a very low reading as the FET switches on, the averaging reduces the chance of a false voltage reading triggering the LVC. If desired the sample size can be increased. An alternative would be to increase the filter capacitor on the voltage sense input, however a software solution permits the filtering parameters to be changed without a hardware change.

The ESC can be configured with two different low voltage points. In this mode the GP3 input (jumper W1) selects which cutoff voltage is in effect.

Automatic low and high throttle setting

When the ESC is powered on the throttle is assumed to be in the 'low' position. After power on you must move the throttle to 'high' and then back to 'low'. The ESC will then arm and sound two short 'beeps' via the motor. This feature assumes that the 'high' setting has a longer servo pulse width than the 'low' setting. So Futaba transmitters will still require servo reverse on the throttle channel.

After the 'beeps' have sounded (1.5 seconds) the ESC enters normal operating mode and will wait for 'low' throttle. This means that if the throttle is advanced during the 'beeps' the ESC will not spin up the motor. So throttle should not be advanced until the 'beeps' have finished.

Slow Start

The slow start operates by advancing the throttle 1 step every time the received throttle setting is higher than the current setting. In practice the means that to go from idle to full throttle takes about 1.2sec (64 * 0.02sec). If the received throttle is lower than the current ESC setting the ESC will wait until two consecutive lower throttles and then immediately reduce the throttle to the selected value.

This behaviour stops one faulty receiver pulse from 'blipping' the engine. With slow start a faulty 'low' throttle causes the ESC to have to build up to the correct setting using the slow start, for smooth flight this is to be avoided where possible. A single pulse filter appears to significantly reduce this problem.

If desired the ESC can be constructed with the slow start turned off. In this case the the ESC will raise the throttle immediately a higher throttle setting is received.

Soft Brake

The soft-brake option uses the throttle PWM engine to gradually applying the brake one step every time the idle throttle is received (about every 20ms). This means it takes approximately 1.2sec for the brake to be fully applied. Flight testing shows that this works well with the gearbox not being subject to sudden changes in motor speed.

Brake Enable

The brake enable/disable via a jumper is an option of this ESC software. This is provided mainly to demonstrate that control of the ESC features via a jumper is possible. One possible use of a jumper is for disabling the brake. It may be convienent to disable the brake without changing the PIC in some aircraft or possibly when testing and evaluating the brake.

Programmable Throttle Response Curves

Most standard ESCs convert the throttle setting into PWM rates using a simple linear mapping. So that 50% throttle corresponds to a 50% PWM. However, a 50% PWM rate is actually delivering only 25% of the full power to the motor. This is the standard configuration of this ESC also.

The design of the software for this ESC makes it very easy to alter the mapping from throttle to PWM rate so that 50% throttle corresonds to 50% motor power.

Of course, other throttle response curves are also possible. Because the generation of the PWM engine is performed by a Perl program you do not need to be able to program PIC assembler to try out your own throttle response curves. (You do however need to be able to write Perl code that converts the throttle value between 0 and 1 into a PWM on rate between 0 and 1.)

The throttle response curve also determines when the brake is applied (if the ESC is configured with a brake). This permits applications where some of the throttle positions have the motor off and the brake off, and other positions have the motor off and brake on.

Braking and non-braking zero throttle positions

The ESC supports motor off settings with and without the brake applied. (This may be of use on R/C car applications.)

Typically the throttle at its lowest setting has the motor off and brake on, then as the throttle is increased it changes to motor off and brake off, and then increasing further powers up the motor. When the throttle is reduced from the motor on setting it first enters a region where the motor will coast (ie. motor off and brake off) and then if the throttle is reduced further the brake will then be applied.

Lost Model Alarm

The LMA is triggered by either loss of throttle input from the receiver for more that 10 seconds or the throttle input being set to a sufficiently negative input (ie. the throttle trim moved as low as possible).

Suggested hardware for the alert is a simple Piezo Transducer the ESC will produce the appropriate AC drive for the transducer. Alternaticly a piezo transducer with inbuilt siren can be used and the ESC produces a simple on/off output. Depending on the volume level that you require the piezo can be driven directly from the PIC, or via a buffer transistor from the unregulated battery voltage.

The LMA siren is driven out of the GP1 pin on the PIC with an active high siren signal.

Glitch counter

The glitch counter can be selected as long as there are no other options using the GP3 input (jumper W1) to the PIC.

The glitch counter counts the number of faulty receiver pulses and 'beeps' the count out on either the motor, or piezo sizen if the LMA facility is configured.

Reverse Output

The reverse output is available when there is a spare output pin on the PIC. This reverse implementation is a simple reverse function that is designed primarily for cars (or boats). As such the reverse facility should only be enabled with the the car throttle map (THROTTLEMAP = 3).

The reverse output will toggle state when the throttle is held in the brake position for more that 5 seconds. The output can be used to drive a relay, or could be used as a control input to an H-bridge for electronic reverse.

The output signal (GP1) is low (0 volts) for 'forward' and high (+5 volts) for 'reverse'.

Why use the 12F675?

The Microchip 12F675 offers a number of interesting facilities that are used in this design. These facilities permit a much better ESC to be designed than is possible with a 12C5xx PIC, without the complexity of designs using larger PICs.

ESC Challenges

There are a number of important challenges in designing an ESC:

Accurate timing

Radio control control pulses are 1.500msec wide at the centre position and with a swing of approximately 0.500msec in either direction for full stick movement. A reasonable assumption for throttle controls is that throttle 'off' is a pulse width of 1.150msec and 'full on' is 1.850msec.

If you wish to obtain 64 possible motor speed settings then each motor speed represents 0.012msec of control pulse width and the ESC must measure the pulse with sufficient accuracy and resolution to permit determination of the throttle position.

There are two main techniques for measuring the throttle pulse width: a software counter or a hardware counter. If a software counter is used great care needs to be taken to ensure that there is sufficient measurement resolution, and operating a software PWM at a reasonable rate at the same time is almost impossible. The best method is to use a hardware counter, and in this case the 12F675 offers an externally gateable 16-bit counter with 0.001msec resolution.

Software PWM

The major difficulty with performing PWM in software is obtaining an accurate stable frequency while the PIC is performing other tasks. Normally interrupts would be used to obtain reasonable accuracy, however, interrupt response and entry/exit overheads make it difficult to use interrupts when either the FET on or off time is short.

This ESC uses a combination of software timing and timer based interrupts to generate the PWM.

This is achieved by having the PWM code written by another piece of software. A Perl program contains all the details regarding the processor timing and generates PIC code to implement the PWM engine. This permits the selection of PWM frequency on a continuously variable basis, and also the implementation of user designed throttle profiles.

Further details regarding this PWM generation software is below.

The PWM engine uses software timing to generate short pulses and the timer with interrupts to generate long pulses. This permits the main ESC application to be written without concern for precise timing.

Is it any less expensive?

Under some circumstances there are considerable savings to be had by building your own ESC, however, most of the time there isn't much cost advantage.

The following table shows some current (7 December 2003) prices for commercial ESCs (purchased by mail order) and DIY prices.

Purchase 18A ESC (JETI JES-180) A$50
Purchase 8A ESC (GWS-ICS-300) A$30
Build 13A ESC no brake (1A BEC) A$24
Build 13A ESC with brake (1A BEC) A$30
Build 25A ESC no brake (1A BEC) A$30
Build 25A ESC with brake (1A BEC) A$36

As can be seen there isn't a lot of saving, and the DIY version is probably heavier and may be less reliable and crash-proof.

The major cost item are the FETs, and the ability to obtain good quality (ie. low resistance, high current) FETs at a reasonable price is the most important issue.

Software Development Environment

This software was developed with the MPLAB IDE from MicroChip.

If you plan to use this ESC design and build one yourself you will need to download the MPLAB IDE. There are too many ESC options for all the versions to be available on this Web page. Common versions are provided here, but it is almost certain that you will want to adjust some of the parameters to suit your requirements - after all that is half of the reason for building your own ESC.

After you have installed the MPLAB IDE proceed as follows:

The MPLAB IDE has full support for simulation that permits you to fully check the operation of the ESC. However, the use of these facilities is beyond the scope of this document. Users who just want to build a 'custom' version by modifying standard parameters of the ESC should have no problem just using the IDE to assemble the code.

Note: when the code is assembled the appropriate circuit type (one of ESCA, ESCB or ESCC) will be placed as text into the .HEX file along with the software version and the module name. This text is intended to be visible when you load the .HEX file into the PIC programmer software and allows you to check that the PIC is configured for the circuit type you have.

The ESC Software

The PWM Engine Generator

This ESC uses a software PWM engine that is machine generated by a Perl program. The source code for this program is available as part of this design. Users with Windows systems may want to consider using ActivePerl to run this application.

You don't need to understand, or be able to run, this program in order to use the ESC. The PIC assembler code that is provided will do everything that most people require. You only need to be able to run this program to generate custom throttle profiles, adjust PWM rates or make similar changes.

Important Note: if the soft brake feature of the ESC is used then the soft brake uses the same PWM engine as the throttle. Thus, the brake will be gradually applied with the same duty cycles as the throttle.

The program contains some documentation concerning the constants that you can modify.

Main ESC module

The main ESC module contains all of the ESC application, with the exception of the PWM engine file. This source file contains a number of constants at the top that you can modify so suit your application.

Linear PWM engine

A linear (ie. throttle position proportional to percentage duty cycle) PWM include file is available that implements the 'basic' ESC.

Power PWM engine

A power (ie. throttle position proportional to engine power) PWM include file is available.

Car Power PWM engine

A power (ie. throttle position proportional to engine power) PWM include file is available that is suitable for car use. This throttle map has a zero throttle region and a brake region so that the brake is only applied when the throttle drops below the zero throttle region.


Test Circuits

There are 3 test circuits provided that show how to configure the PIC and a handful of parts to demonstrate the capabilities of the ESC software.

Production Circuits

There are 2 production circuits available that show the ESC in its intended configuration. All production circuits provided include low voltage cutoff. Operation of an ESC without such a cutoff is considered too dangerous in a model aircraft environment.

Where is everything?

The files available for download are:

File Name Description Ver 1.9: Perl program to compute PIC code to implement PWM functions and the mapping of throttle position to PWM duty cycle.
esc.asm Ver 1.12: PIC 12F675 Assembler Source Ver 1.8: PIC 12F675 Assembler Include File Ver 1.5: PIC 12F675 Assembler Include File Ver 1.4: PIC 12F675 Assembler Include File
esca.hex, esca.lst Assembled ESC code and listing for use where circuits call for 12F675-ESCA (linear throttle map)
escb.hex, escb.lst Assembled ESC code and listing for use where circuits call for 12F675-ESCB (linear throttle map). Note: this version has the hard brake.
escbs.hex, escbs.lst Assembled ESC code and listing for use where circuits call for 12F675-ESCB (linear throttle map). Note: this version has the soft brake.
escc.hex, escc.lst Assembled ESC code and listing for use where circuits call for 12F675-ESCC (linear throttle map). Note: this version has the hard brake.
esccs.hex, esccs.lst Assembled ESC code and listing for use where circuits call for 12F675-ESCC (linear throttle map). Note: this version has the soft brake.
esccsp.hex, esccsp.lst Assembled ESC code and listing for use where circuits call for 12F675-ESCC (power throttle map). Note: this version has the soft brake and power throttle map.
testrig.gif Rev C: Circuit diagrams for various test configurations
escnobrake.gif Rev D: Circuit diagram for production ESC without brake
escbrake.gif Rev I: Circuit diagram for production ESC with brake
esccar.gif Rev A: Circuit diagram for production car ESC with brake and no LVC
boardtop.gif Rev B: Suggested veroboard/versa strip layout for production ESC with brake - top view
boardbot.gif Rev B: Suggested veroboard/versa strip layout for production ESC with brake - bottom view


Glitch filtering

The ESC provides glitch filtering to stop the occasional input glitch from affecting the ESC outputs. Users may wish to alter these filter values to fit their preferences. This note explains how to do this.

From the ESC's viewpoint there are two types of glitches: those that represent a lower throttle setting than that which is currently in effect and those that represent a higher throttle setting that the current one. These two types of glitch are handled differently.

With the slow start option selected glitches for higher throttle settings are managed by the slow start code. A single glitch for a higher throttle setting will cause the ESC to increase the throttle by 1 step - this is the normal slow start operation. A single step throttle increase is not noticable in most situations and so no special processing is required.

With the fast start option selected glitches to higher throttle settings would cause an immediate increase and can result in noticeable changes in throttle. For this reason the ESC requires a number of consecutive input pulses before the throttle is changed. By default this value is set to 4, so 4 consecutive input pulses are required to increase the throttle. This value can be changed by altering the constant (uppulse) in the Main parameter section of esc.asm.

Similarly glitches to lower throttle settings require a filter to ensure that the throttle is not decreased erroneously. Coupled with the soft start option an eroneous throttle decrease causes a significant problem. For this reason the ESC requires a number of consecutive input pulses before the throttle is changed. By default this value is set to 4, so 4 consecutive input pulses are required to decrease the throttle. This value can be changed by altering the constant (downpulse) in the Main parameter section of esc.asm.

Other versions

There are many versions of the ESC software that can be generated from the source files, far too many versions to have all of them appear on this web page. However, the following versions are provided as some typical useful configurations.

ESC with power throttle map, soft brake and 6V/9V selectable LVC

This is software version suitable for the full ESCC circuit that provides the following:


ESC with power throttle map for car use

This is software version suitable for the full ESCC circuit that provides the following:


If you do not require a low voltage cutoff in an R/C car the ESC can be configured without an LVC. In this configuration the ESCB circuit will be used.


If you require a reverse option for a R/C car application the ESC can be configured as follows: In this configuration the ESCC circuit will be used, regardless of whether the LVC is enabled.


How to build one

So after all that you would like to try constructing one of these, what do you do?

Here is a suggested method of constructing a ESC with brake and low voltage cutout using standard components. This procedure will work for the basic ESC without a brake - however, the component layout is left as an exercise to the reader!

Similarly you can delete components such as the brake off jumper if you wish. Deleting the brake off jumper permits the board to be made smaller - see the construction examples at the end.

This layout with standard components weighs 25gms when assembled (this is without the power connectors and heatshrink, however, it does include 25mm of power cables, a switch and 300mm servo lead). With the heatshrink and a pair of Deans Ultra connectors the ESC weighs 32gms.

Note: The images shown in this procedure are using the Rev A layout, your layout will be slightly different - just follow the procedure and the diagrams.

Think First!

Before commencing construction give some consideration to the cooling of the LM2940 regulator used for the BEC. The TO-220 package has a metal tab that is connected to ground (0V). This device can dissipate some power without any heatsink, however the the amount of power dissipated is a function of the battery voltage and the power consumption.

The LM2940 specifications show a 60 degree C per watt package temperature rise in still air. With careful construction there will be some ventilation with air flow, and some heatsink via the PCB and this will tend to reduce package temperature. In practice 1W power dissipation should represent no problem. Where higher power dissipation is expected consideration should be given to cooling the LM2940 regulator.

For example, using an 8-cell pack (say 10V) powering the ESC, two HS-81 servos, receiver and an Aiptek pencam (total 200mA at idle, 500mA peak) the idle power dissipation is 1W ((10V - 5V) * 0.2A), peak dissipation would be 2.5W. This combination operates fine with no special heatsinking provision.

If you elect to leave out some of the features, for example the brake off jumper or the power switch, you may well be able to reduce the size of the veroboard.

Step 1

Obtain some FETs. You will need one N-channel and one P-channel FET in TO-220 packaging. The N-channel FET should have an Rds(on) of < 0.010 Ohms at 5 volts Vgs. Make sure that you read the data sheet carefully, the 'headline' figure is often at 10 volts Vgs, you need to look further for the figure that is typically given for 4.5, 4.8 or 5 volts. Suggested N-channel FETS are: IRF2203N, IRF3706, IRL1404. The P-channel (brake) FET is not as critical and something like an IRF9530 or IRF9540 is suitable. The design relies on the Drain/Source diode in the P-channel brake FET to protect the N-channel FET, so if you remove the brake (or use a small FET or large motor) you will need an additional diode as shown in the no brake design.

If is also possible to use SO-8 packaged FETs, such as the IRF7456, however this requires better soldering skills and also a different board layout. For a DIY ESC I would suggest sticking to the TO-220 packaging - they will dissipate plenty of power and are easy to install.

You may also need to obtain a Schottky Diode (D1). This is mandatory for the ESC without a brake and optional for the ESC with a brake. The Schottky diode should be rated at at least 3A for use with motors upto Speed 400 in size (at about 12A maximum motor current), larger motors would require a larger diode.

With the design using a brake it may be sufficient to rely on the diode in the brake FET, however this depends on the rating of your FET. If in doubt install the diode as this will increase the safety margin.

Do not reduce the size of C6 (3.3nF). This capacitor is there to ensure that the brake FET does not turn on due to noise while the motor drive FET is on. If both FETs turn on at the same time it will be catestrophic. If in doubt it is safe to increase this capacitor to 5.6nF or even 22nF to ensure that there is not chance of the brake FET being turned on at the wrong time.

Step 2

Obtain all the other parts. Note that the PN100 can be substituted with a 2N2222, BC549, BC547 or similar. It is important to use a low dropout voltage regulator - stick to the LM2940. It is probably worth using a socket for the 12F675 as you will want to play with the first ESC you build - spend a few extra cents and purchase a 'machined' socket with the round pins.

Step 3

Print off the bottom view of the veroboard layout and cut a piece of board the same size. Note that the outer set of holes on the diagram are designed to be the ones you cut along. I normally cut with a knife along the holes on both sides of the board and then snap along the line I have just cut.

Remove the copper tracks in the positions indicated by the green lines on the bottom view - like this:

Step 4

Now turn the veroboard over and use the top view of the layout, the top wiring is indicated by the blue lines.

Solder the components onto the board in the following order:

You should end up with something like this:

Step 5

Now turn the board over and place the LM2940 and the two FETs on the back of the board. Note that in all cases the metal part of the device is mounted away from the copper side of the veroboard. If you want to you can use a small piece of double sided mounting tape between the package and the board.

Before you attach these components check for solder shorts where they shouldn't be. Try running a sharp blade along the gap between the tracks to ensure that there are no shorts - now is the time to find them!

Then add some additional heavier wire (as indiciated in red) along the +Bat and -Bat connections to the FETs. This can be soldered on the gap between the 1/2 strip left after you cut the board and the first full strip on the veroboard. Then attach the +Bat, -Bat and +Motor wires to the board/wire.

This should look something like this:

Step 6

Turn the board back to the top side and join the two legs of the FETs that are sticking through the board together with some heavy wire. Then attach the -Mot wire to this.

Step 7

Now you should have the entire ESC assembled. So now we can check out the ESC. Proceed as follows:

Step 8

Congratulations - you now have a fully functional ESC.

You should be able to use a short length of 25mm heat shrink to cover the ESC. As you shrink the heat shrink you can cut a hole to allow the brake off jumper pins to be visible. You can also cut a hole for the PIC so you can change the programming. However, make sure the PIC is firmly in place - if it pops out mid-air then you will be flying a glider.

More construction examples

Revision A prototype with switch, brake off jumper. This initial revision had the brake and motor FET mounted 'on the end' of the board.

This is a revision B board under construction. This board does not have the brake off jumper. The bottom view diagram shows how an entire set of holes has been removed and two of the cuts moved. This reduces the length of the ESC by 0.1 inch.

The top view of the assembled Revision B board, note again the deleted set of holes on the top view diagram.

The bottom view of the assembled Revision B board. This view shows the mounting of the LM2940 and FETS.

Final view of the ESC after covering with heat shrink tubing.

The prototype Revision A ESC mounted on an AP Slow Stick. The soft brake works well in this configuration, the prop stops in about 1.5 seconds.

The Revision B ESC mounted on an EZ400G.