VESC – Open Source ESC

Post updated 2016-01-22

About this project

I have made many updates to my custom motor controller recently and the old post is getting confusing with notes and updates, I decided to write a new post about it that hopefully is more clear, more complete and easier to follow. This might sound a bit ambitions, but my goal is to make the best ESC available. I really enjoy sharing knowledge, so I want to keep all the hardware and software open.

This is an overview of the schematic (download a complete PDF here):

Schematic-1

This is the front of the PCB:

PCB_Front

The back:

pcb_back

3D render from KiCad:

3D

Some screenshots of the configuration GUI (BLDC Tool):

RT_Data

MCCONF_Limits

APP_PPM

Resources

All files are on github to keep them up to date, so check these links on a regular basis:

Related posts

Forums

Because information about the VESC is scattered all over the internet and a lot of information is in email conversations with me, I have created a forum dedicated to the VESC here.

Live Chat

I have created an IRC channel on freenode where you can live chat with me and other users about VESC and my other projects. Feel free to join: http://webchat.freenode.net/?channels=vedder

Features

  • The hardware and software is open source. Since there are plenty of CPU-resources left, the customization possibilities are almost endless.
  • STM32F4 microcontroller.
  • DRV8302 MOSFET driver / buck converter / current shunt amplifier.
  • IRFS7530 MOEFETs (other FETs in the same package also fit).
  • 5V 1A output for external electronics from the buck converter integrated on the DRV8302.
  • Voltage: 8V – 60V (Safe for 3S to 12S LiPo).
  • Current: Up to 240A for a couple of seconds or about 50A continuous depending on the temperature and air circulation around the PCB.
  • Sensored and sensorless FOC wich auto-detection of all motor parameters is implemented since FW 2.3.
  • Firmware based on ChibiOS/RT.
  • PCB size: slightly less than 40mm x 60mm.
  • Current and voltage measurement on all phases.
  • Regenerative braking.
  • DC motors are also supported.
  • Sensored or sensorless operation.
  • A GUI with lots of configuration parameters
  • Adaptive PWM frequency to get as good ADC measurements as possible.
  • RPM-based phase advance (or timing/field weakening).
  • Good start-up torque in the sensorless mode (and obviously in the sensored mode as well).
  • The motor is used as a tachometer, which is good for odometry on modified RC cars.
  • Duty-cycle control, speed control or current control.
  • Seamless 4-quadrant operation.
  • Interface to control the motor: PPM signal (RC servo), analog, UART, I2C, USB  or CAN-bus.
  • Wireless wii nunchuk (Nyko Kama) control through the I2C port. This is convenient for electric skateboards.
  • Consumed and regenerated amp-hour and watt-hour counting.
  • Optional PPM signal output. Useful when e.g. controlling an RC car from a raspberry pi or an android device.
  • The USB port uses the modem profile, so an Android device can be connected to the motor controller without rooting. Because of the servo output, the odometry and the extra ADC inputs (that can be used for sensors), this is perfect for modifying an RC car to be controlled from Android (or raspberry pi).
  • Adjustable protection against
    • Low input voltage
    • High input voltage
    • High motor current
    • High input current
    • High regenerative braking current (separate limits for the motor and the input)
    • Rapid duty cycle changes (ramping)
    • High RPM (separate limits for each direction).
  • When the current limits are hit, a soft back-off strategy is used while the motor keeps running. If the current becomes way too high, the motor is switched off completely.
  • The RPM limit also has a soft back-off strategy.
  • Commutation works perfectly even when the speed of the motor changes rapidly. This is due to the fact that the magnetic flux is integrated after the zero crossing instead of adding a delay based on the previous speed.
  • When the motor is rotating while the controller is off, the commutations and the direction are tracked. The duty-cycle to get the same speed is also calculated. This is to get a smooth start when the motor is already spinning.
  • All of the hardware is ready for sensorless field-oriented control (FOC). Writing the software is the remaining part. However, I’m not sure if FOC will have many benefits for low inductance high-speed motors besides running a bit quieter. Sensored and sensorless FOC is fully implemented since FW 2.3.

Continue reading

Connecting a programmer/debugger to my custom STM32 PCBs

When I make custom STM32 PCBs (such as my RF-mote or my ESC), I use an SWD connector for programming and debugging the microcontroller. The connector is a 6-pin micro-jst connector with 2mm pitch, which easily can be found by searching on ebay. An STM32 discovery board with stlinkv2 works perfectly for programming and debugging, and can be connected as shown here (click on the picture to get a larger version where the wire colors can be seen):

DiscoveryBoards_text

Notice that I have removed two jumpers on the discovery board to disconnect the SWD from the microcontroller. The pins in the jst connector are ordered in the same way as on the discovery board, but the outermost (green) cable is connected to 3V or VDD.

There are also some small and inexpensive stlinkv2 programmers available on ebay (just search for stlink v2), such as this one which I have soldered a micro-jst cable to:

EbayStlink_small

Update:

I had some problems with too long JST cables. If uploading the program does not work for you, try shortening the JST cable.

Chosing the right BLDC motor and battery setup for an electric skateboard

Recently, I have been involved with the electric skateboard community because of my custom ESC. I get many questions about motor kv, gear ratio, current, voltage and efficiency. In this post, I will try to explain how things are connected and how to chose the right setup. I will try to keep things simple and not involve too many equations to provide a good intuition for the DIY community. The assumption in this post is that we are using an 50mm-60mm hobby outrunner motor.

Continue reading

Startup torque on sensorless BLDC motors

One of the major challenges when working on my custom open source ESC was to get good startup torque and low-speed performance with sensorless motors. This challenge has been addressed in several places around the net:

Techniques I used

In order to get a smooth and quick startup without sensors I used several tricks, namely:

  • There are no hardware low-pass filters that introduce phase delay. Such filters can be avoided because the ADC samples are synchronized to the PWM timer and adjusted dynamically every time the duty cycle or switching frequency is changed.
  • After a zero crossing, the area under the voltage is integrated until a threshold for commutation based on the motor parameters. This integration is robust agaist acceleration and provides good SNR since an integrator is a low-pass filter.
  • There is a parameter that defines the voltage coupling between the windings when measuring the back-emf. This make a huge difference when running at low speeds with low duty cycle. This compensation has a RPM dependence though, which is something I tried to avoid where possible because the RPM estimation has a delay and thus causes problems during acceleration.
  • To get better voltage samples, the switching frequency is adaptive and proportional to the duty cycle. This is because the back-EMF only can be sampled during the ON-time of the PWM cycle and low duty cycles have short ON time. Since the motor is running slowly on low duty cycles, sampling and switching does not have to be as fast to keep up with the motor which makes this less of a problem. Lower switching frequency also decreases switching losses, which is a positive side-effect.
  • When the motor is un-driven, the back-emf on all phases is analysed to track the position, direction and speed of the motor. So when the motor is already spinning, the algorithm will begin in the exact state of the motor (position, duty-cycle, direction).
  • I have also used some hack-ish conditions based on trial and error to improve the startup.
  • Closed loop operation is used from the first commutation, since the measured values are clean enough when using these techniques.

This is a video where I demonstrate how this works on a scorpion outrunner and an electric longboard:

Some examples with plots

** Note that all the plots show the voltages samples captured by the motor controller, which are synchronized to the PWM timer. It would look different on an oscilloscope since the switching distorts the signal. **

This is what the phase voltage for a typical startup sequence looks like, where the duty cycle is set to 5%:

start_d5_almost_auto_voltage

Even though the duty cycle is only 5%, the waveform is clean. This is because the switching frequency is low at this speed and the on-time is long enough to get good samples. The first commutation is a bit off at first since the motor is not perfectly aligned, but the second commutation already looks perfect.

Continue reading

Testing my custom motor controller

I have been working more on my motor controller recently, and this is a brief update on the progress. One of my test rigs is my 1:8 RC car. With this one, I can test the startup torque, the braking and many of the safety functions, e.g. the transitions and currents when going from full forward to full reverse. Here is a video of the tests:


Continue reading

A custom BLDC motor controller (a custom ESC)

================= IMPORTANT UPDATE =================

I have written a new post about my open ESC on this page and also updated the hardware significantly. If you haven’t built it yet and if you are planning to order parts for it, please refer to that page. I will only leave this page for reference in case you have built it before I wrote the new post and updated the hardware. Also, If you have built the ESC before, the tutorial and software on the new page also applies to the old hardware.

=====================================================

Updated 2014-12-08

For about three years I have been working on a custom BLDC motor controller (also known as an ESC). I have spent hundreds of hours on writing code and I have made many minor and four major revisions of the printed circuit board (PCB). Now I finally have something that I can publish. The code can still be cleaned up a lot, especially the latest parts that I wrote in a hurry, but I don’t want to delay the release forever.

The features of this BLDC controller are:

  • The hardware and software is open source.
  • A STM32F4 microcontroller.
  • A DRV8302 MOSFET driver / buck converter / current shunt amplifier.
  • IRFS3006 MOEFETs.
  • 5V 1A output for external electronics from the buck converter integrated on the DRV8302.
  • Voltage: 8V – 60V.
  • Current: Up to 240A for a couple of seconds or about 50A continuous depending on the cooling.
  • PCB size: slightly less than 40mm x 60mm.
  • Current and voltage measurement on all phases.
  • Regenerative braking.
  • Sensored or sensorless commutation.
  • Adaptive PWM frequency to get as good ADC measurements as possible.
  • RPM-based phase advance.
  • Good start-up torque in the sensorless mode (and obviously in the sensored mode as well).
  • The motor is used as a tachometer, which is good for odometry on modified RC cars.
  • Duty-cycle control, speed control or current control.
  • Seamless 4-quadrant operation.
  • Interface to control the motor: servo signal, analog, UART, I2C, USB  or CAN (with a transceiver). Some of these modes need a bit more code to work, but not much.
  • Servo signal output. Good when e.g. controlling an RC car from a raspberry pi or an android device.
  • The USB port uses the modem profile, so an Android device can be connected to the motor controller without rooting. Because of the servo output, the odometry and the extra ADC inputs (that can be used for sensors), this is perfect for modifying a RC car to be controlled from Android (or raspberry pi).
  • Adjustable protection against
    • Low input voltage
    • High input voltage
    • High motor current
    • High input current
    • High regenerative braking current (separate limits for the motor and the input)
    • Rapid duty cycle changes (ramping)
    • High RPM (separate limits for each direction).
  • When the current limits are hit, a soft back-off strategy is used while the motor keeps running.
  • The RPM limit also has a soft back-off strategy.
  • The commutation works perfectly even when the speed of the motor changes rapidly. This is due to the fact that the magnetic flux is integrated after the zero crossing instead of adding a delay based on the previous speed.
  • When the motor is rotating while the controller is off, the commutations and the direction are tracked. The duty-cycle to get the same speed is also calculated. This is to get a smooth start when the motor is already spinning.
  • All of the hardware is ready for sensorless field-oriented control (FOC). Writing the software is the remaining part.

This is a photo of the front of the assembled PCB (please ignore the soldering quality…):

Front

Continue reading

A Contiki port for my custom cc2520+stm32f4-boards

Previously, I have designed a small circuit board with a cc2520 rf-tranceiver and a stm32f4 microcontroller (see this post). After porting the driver for the cc2520 to ChibiOS for a few tests, I decided to port Contiki to support this platform as well. As this is the first time that I work with Contiki, uipv6 and 6LoWPAN, this was quite a challenge for me. Nevertheless, I managed to make the following features work:

  • The cc2520 radio
  • The RPL border router using the USB connector
  • RIME
  • IPv6
  • LEDs
  • printf for debugging
  • Many applications, such as the webserver, telnet, udp
  • I made a driver for ws2811 LEDs that uses DMA and a timer

In this post, I will describe what the essential steps were to port Contiki to this board and how to use my port. I have uploaded the Contiki port together with a few example applications to github. You can download it here.

Continue reading

CC2520 and STM32 RF boards

I have made a small PCB with an STM32F4 microcontroller and a TI CC2520 radio transceiver. There are many mote modules available already, but I wanted one optimized for performance as opposed to power consumption. I also wanted to try making a PCB with some RF-parts since I haven’t done that before.

These are the 2-layer PCBs ordered from OSHPark:

RF_All

Continue reading

Testing a simple sumo program using 3 proximity sensors

During RobotChallenge Sleipner was using 7 proximity sensors, but this did not work very well. The reason for that is that the sensors had 140cm ± 3% range almost regardless of the surface of the object. Most things were closer than that to the dohyo, so most of the matches were quite random.

The tests in the video below are done with only 3 sensors, but no objects are closer to the dohyo than 150cm. As it turns out this is quite enough even with a simple program. One problem is that the sensors are a bit slow, so while the robots turns at high speed small objects such as the can won’t trigger the sensors. Otherwise, the robot should abort the rotation and attack.

Considerations for the next robot

Sensors are among the biggest challenges when building sumo robots. Good sensors are really expensive and… not that good. My plan is to hopefully get some 200+ fps camera sensor and use an FPGA to approximate the position of the other robot. I’m quite familiar with Xilinx FPGAs and VHLD but I have only seen pretty slow camera sensors with a documented interface and an affordable price.

In general I would like to build the robot without spending too much money on it. Firstly because I’m a student and can’t afford too much (not considering sponsors) and secondly because I like the idea of building a great sumo robot without spending 800€ on maxon motors and lots on expensive industrial sensors. The motors I’m using now are normal BLDC RC car motors for 20€ each and I made custom motor controllers myself. The power output is much higher than for maxon DC motors with similar size. The outrunner BLDC motors I’m going to use for the next robot are even cheaper and have twice as high power output and lower RPM compared to the ones I currently use, so they are perfect for this. As the motors are brushless with sensors and I control the commutation myself they are also used as tachometers with 120 pulses per revolution per wheel, giving me an approximation of the current position on the dohyo. This is also used when turning around at the edge; the turn is not decided by a delay like most other robots, but by the angle difference reported from the motor sensors. Combining this with an all-seeing FPGA-based sensor should result in a really powerful sumo robot.

[CRF]Sleipner upgraded for RobotSM 2012

RobotChallenge in Vienna

Me and Vilse from CRF spent about three weeks before RobotChallenge building this robot (the robot is called Sleipner and is an autonomous 3kg sumo robot). As we had other thing going on, such as our usual studies at Chalmers, this was done quite in a rush. The first time we tested the robot autonomously was a few hours before the first matches.

Issues with the design

The competition didn’t go as well as planned. The biggest problems were that the magnets were too far away from the ground and that the blade was really weak. The robots with the better blades always picked up Sleipner in front collisions. Some of them had blades made from really sharp knives. The blade on Sleipner was a 1mm thick sheet of spring steel. Recently I made a few attempts at fixing a few of those issues.

The improvements

Firstly, I milled a new base plate for Sleipner. As the wheels are adjustable in height this allowed the magnets to be placed less than 1mm from the ground. Also, they could be distributed in a way to get a better centre of gravity (or, centre of magnet force in this case). The benefits of this action can clearly be seen in the video below.

The next major improvement was the new blade. I bought a couple of knives for a thickness planer made from HS-steel. This was not tested against another robot, but it is most likely a major improvement.

Watch the video for more details

The next 3kg sumo robot

This robot really has enough power with the BLDC motors, but it would be nice to have motors with lower RPM to avoid the gear boxes and gain 400 (the weight limit is 3kg) grams for more magnets. Brushless outrunner motors are perfect RPM-wise, but they have a major drawback: they are always sensorless. This means that they have to be run in open loop at low RPM and thus have very low torque before they speed up. This is no problem for air planes, but for sumo robots that change direction all the time it is completely useless.

I bought a couple of these outrunner motors and managed to mount hall-effect sensors in them. This works really well and gives the motors great torque at the start. In addition, they are also more powerful than other motors in similar size. The ones I modified are 192 grams heavy and are rated 1000 watts each. Also, the KV (RPM per volt) is perfect to run the motor with a small gear against the gears currently mounted on the wheels, which saves 400 grams in total for the gearboxes on the robot. I will write a bit more about this motor modification in another post soon.