Avatar

MY OPEN SOURCE ESC

Jul 05th, 2019 | by: ELECTRONOOBS
Views 774
I've been trying to make a good ESC for years. My first prototype 3 years ago was working "good". It was very big and the BEMF was not that good. It could reach decent speeds and you ahve that tutorial here on this page. Now, with my final version I have all taht I wanted. High speed, good BEMF detection and that means good torque, PWM control of the speed and small size. The board is programed in Arduino.

1. Intro


So what is an ESC? Well, electronic speed controllers are used to control brushless motors, in thisc ase the motor has a triple phase input. To control this input, the ESC must apply a special sequence of LOWs and HIGHs signals in a predefined order. It has to conmutate very fast and by taht rotate the rotor of the motor. In this tutorial we will see how to control the rotation, the speed, detect the BEMF and by that know when to make the switch to the next step of the sequence. So this is a sensorless brushless motor speed controller since it uses no sensor to detect the rotor position. We will learn: 

  • - The schematic and why we need each part
  • - Triple phase MOSFET bridge control
  • - BEMF detection and 0 cross
  • - Interrumprions and internal comparator of ATMEGA328
  • - PWM control

2. Schematic


Now the schematic might look complicated but is not. First things first, we have a power block. This is a buck converter circuit that will give 5V for all the digital parts. The main input could be from 11 to 18V but this block will aloways give 5V. The next block is the triple phase bridge. These are 6 MOSFETs in a bridge configurations that are used to energise the coils of the motor. Each of these MOSFETs has a driver control with the IR2101 which is a dual driver so it could control both the high and low sides of the bridge.
We have the BEMF voltage dividers block. The voltage from the motor will be higher than the maximum voltage that the ATmega328 could tahe as input, in this case 5V. So for that, using some resistors of 10K and 33K we lower the voltage so the analog input of the ATmega328 could read that. This inputs will be used to detect the position of the rotor and know when to switch to next step of the rotating sequence. We also have the ATmega328 microcontroller, the CH340 programmer so we could upload codes with the USB connector and a few more extra components such as buzzer, LEDs and pads.
Schematic

3. The PCB


The PCB I've designed is 60 by 35 mm. In the photo below you can see the first version of the PCB in red but also the final version with black soldermask. The V1.0 had some errors such as some bad GND connections, wrong pin for the Buzzer and also the power tracks were covered by the soldermask. For version V2.0 now all the problems are fixed and the big tracks are exposed so I could fill those with solder for more current. You can download the gerber files from below. When you will download the GERBERS file above you will have a .zip file. Go to JLCPCB or any other professional PCB manufacturer, uplaod the .zip file and order your boards. In my case 10 PCBs cost me just 2 dollars plus shipping which for spain was 6 more dollars. I 7 days, I receive the next boards with a great look. You have silklayer for all the components so soldering the components should be easy. The PCB thickness is 1.6mm, signal tracks are 0.2mm and power tracks are 2mm. This red board has no exposed power tracks but the GERBER file you can download from above, is with the final version so don't worry.
The PCB
FILES TO DOWNLOAD FOR THIS STEP
ESC GERBERs V2  DOWNLOAD

4.1 Soldering parts - Buck cconverter


The first part we solder is the power block. This will be a buck converter circuit that will lower the voltage from 12V to 5V for the microcontroller and other digital parts. Why we do this part first? Well, if we first solder the digital part and then the power block and by mistake the output of the buck converter is not 5V but 12V, well, taht will burn all the digital part.
Buck converter circuit

4.2 Soldering parts - The ATmega328


Second step is to solder the microcontroller basic configuration. That is the ATmega328p-AU chip, the 16MHz crystal, the R23 resistor of 1M ohm, the R1 resistor of 10K ohm, the C6 capacitor of 100nF. These components are mandatory for the microcontroller to work. Once you've soldered all these parts, we can test if we can upload something to the chip.

Once you have soldered all the parts for the basic configuration connect the FTDI external programmer to the RX DTR and TX pads but also Vcc and GND. Now open Arduino IDE and uplaod the next test code that will increas the "x" value each second and print that on the serial monitor. If you can see the number increasing, that means the IC was well soldered and it is working with no problem.
Add the microcontroller
0069006e0074002000780020003d00200030003b003c00620072003e0076006f00690064002000730065007400750070002800290020007b003c00620072003e0026006e006200730070003b002000530065007200690061006c002e0062006500670069006e002800390036003000300029003b003c00620072003e007d003c00620072003e003c00620072003e0076006f006900640020006c006f006f0070002800290020007b003c00620072003e0026006e006200730070003b002000780020003d002000780020002b00200031003b003c00620072003e0026006e006200730070003b002000530065007200690061006c002e007000720069006e0074006c006e002800780029003b003c00620072003e0026006e006200730070003b002000640065006c00610079002800310030003000300029003b003c00620072003e007d0020003c00620072003e

4.3 SOLDERING PARTS - FTDI CH340


Once the voltage is 5V and the ATmega chip is working, we can keep soldering parts. Next part is the CH340 FTDI programmer. This chip will make the connection between and USB connector from a PC and our ATmega chip. So solder the CH340C, the C7 capacitor and the R18 aND R19 resitors of 1k. Also solder the USB connector. Make sure the FTDI chip is the CH340C not the CH340G, because that will also need a crystal. Once you solder the chip and the connector, try to upload the same code as before but this time with the USB connector on the board. If it works we are good to go.
UART connection

4.4 SOLDERING PARTS - Solder the rest


Now that everything works, we can solder the BEMF resistors, the MOSFET drivers with the diode and capacitors and the MOSFETs on the back for the triple phase bridge. Also solder the LEDs and the buzzer. Finally, we solder 3 wires with female connectors to the GND, Vcc and PWM pads. These will be the input signal from the radio receiver, just as any other commercial ESC.
All components

5. Code


Now the code is a bit long and difficult to understand. That's why each line has a comment. So download the code from the link below. Then read each line in order to understand why I do each part. The code will have the main.ino but also s secondary code for the EEPROM write/read. The code starts by defining the variables to use in the code. In the Setup loop we first check if the first position of the EEPROM memory is 1. If not that means it is the first time we run the code so we save the min and max values of the PWM input signal and also write a "1" on the first EEPROM adress.

Then, still in the Setup loop we configure all the registers. We set the pins as outputs/inputs, we set the PWM registers and alos set digital pin D8 to be able to create pin state change interrumptions. This pin is used to read the input PWM width in microseconds.


After the register configuration there are some loops that will detect if the ESC should enter configuration mode or not. If the input PWM signal is above a certain value when the ESC is powered on, then it should enter config mode where you could set the max and min range of the PWM input. If not, it will jump to the motor rotation loop.

Then we have a bunch of functions and ISRs to detect the PWM input value, to change the pins for the MOSFET drivers to high or low or to PWM or not PWM and also to change the comparator input on pin D6. With this input we read the BEMF and on each step of the sequence we need to change that input from BEMF_A, to BEMF_B or BEMF_C. The Armega328 has this comparator on pin D6. The negative input if this comparator will be the COM line, which is the summ of all back electromotive foces of A, B and C. Then the positive input of the comparator will then be selected in the code with the line:
FILES TO DOWNLOAD FOR THIS STEP
ESC BEMF code V3.3  DOWNLOAD
0026006e006200730070003b002000440044005200440026006e006200730070003b0020007c003d0020004200300030003000310031003100300030003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0020002f002f00200043006f006e006600690067007500720065002000700069006e007300200032002c0020003300200061006e0064002000340020006100730020006f007500740070007500740073003c00620072003e0026006e006200730070003b00200050004f0052005400440026006e006200730070003b0020003d0020004200300030003000300030003000300030003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0020002f002f00700069006e00730020003000200074006f00200037002000730065007400200074006f0020004c004f0057003c00620072003e0026006e006200730070003b002000440044005200420026006e006200730070003b0020007c003d0020004200300030003000300031003100310030003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0020002f002f00200043006f006e006600690067007500720065002000700069006e007300200039002c00200031003000200061006e00640020003100310020006100730020006f007500740070007500740073003c00620072003e0026006e006200730070003b00200050004f0052005400420026006e006200730070003b002000260061006d0070003b003d0020004200300030003100310030003000300031003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0020002f002f0042003000300031003100300030003000310026006e006200730070003b0026006e006200730070003b0026006e006200730070003b002000440039002c002000440031003000200061006e0064002000440031003100200074006f0020004c004f0057003c00620072003e0026006e006200730070003b0020002f002f002000540069006d006500720031003c00620072003e0026006e006200730070003b00200054004300430052003100410020003d00200030003b003c00620072003e0026006e006200730070003b00200054004300430052003100420020003d00200030007800300031003b003c00620072003e0026006e006200730070003b0020002f002f002000540069006d006500720032003c00620072003e0026006e006200730070003b00200054004300430052003200410020003d00200030003b003c00620072003e0026006e006200730070003b00200054004300430052003200420020003d00200030007800300031003b003c00620072003e0026006e006200730070003b0020002f002f00200043006f006d00700061007200610074006f00720020006f006e002000700069006e002000440036003c00620072003e0026006e006200730070003b002000410043005300520026006e006200730070003b0026006e006200730070003b0020003d00200030007800310030003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0020002f002f00200043006c00650061007200200066006c0061006700200063006f006d00700061007200610074006f007200200069006e0074006500720072007500700074003c00620072003e0026006e006200730070003b0020002f002f0053006500740020004400380020002800500057004d00200069006e002900200074006f0020007400720069006700670065007200200069006e0074006500720072007500700074002000280077006500200075007300650020007400680069007300200074006f00200072006500610064002000500057004d00200069006e0070007500740029003c00620072003e0026006e006200730070003b0020005000430049004300520020007c003d00200028003100200026006c0074003b0026006c0074003b0020005000430049004500300029003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0020002f002f0065006e00610062006c0065002000500043004d0053004b00300020007300630061006e0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b00200026006e006200730070003b003c00620072003e0026006e006200730070003b002000500043004d0053004b00300020007c003d00200028003100200026006c0074003b0026006c0074003b0020005000430049004e005400300029003b0026006e006200730070003b0020002f002f005300650074002000700069006e0020004400380020007400720069006700670065007200200061006e00200069006e00740065007200720075007000740020006f006e0020007300740061007400650020006300680061006e00670065002e0026006e006200730070003b0026006e006200730070003b0026006e006200730070003b0020003c00620072003e

Test


Once you uploaded the code and connected power, the motor and the PWN input we can test this. Make sure the PWM joystick is low and then connect power. When you increase the PWM signal the motor should spin. If you want to set a new range of PWM and calibrate the ESC, just put the joystick in the middle position before powering the ESC. Power the ESC and you will hear the config beeps. After the beeps put the joystick to the maximum value and then to the minimum value and it will get stored to the EEPROM. That's it.

2 Comments

  • David Morreres Viladegut

    about 11 months ago

    Hola amigo, Recienteme he visto la versión española de este proyecto y me asalta una duda que seguro me podrás aclarar. Como se hace en easyEda para que no te serigrafie por encima de las pistas que soportan más corriente para poder reforzarlas con estaño. Seguro que es muy fácil pero no encuentro la manera de hacerlo. Gracias de antemano.

  • Ricardo Salazar 1983

    about 7 months ago

    Hola amigo he probado tu primer sieno con los ir2301 y los mosfet irf3205 pero no me jala he puesto el codigo el arduino y no logro sacar nada por los transitores lo he simulado en proteus y no me fuciona

Login or Sign Up to post comments on this tutorial.