Avatar
MY OPEN SOURCE ESC
Nov 01st, 2023 | by: ELECTRONOOBS | Views 9367
Views 9367

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 for this project V2.0
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.

PCB for the project
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.


int x = 0;

void setup() {

Serial.begin(9600);

}

void loop() {

x = x + 1;

Serial.println(x);

delay(1000);

}


Add the microcontroller
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:


  DDRD  |= B00011100;           // Configure pins 2, 3 and 4 as outputs
  PORTD  = B00000000;           //pins 0 to 7 set to LOW
  DDRB  |= B00001110;           // Configure pins 9, 10 and 11 as outputs
  PORTB  &= B00110001;          //B00110001    D9, D10 and D11 to LOW
  // Timer1
  TCCR1A = 0;
  TCCR1B = 0x01;
  // Timer2
  TCCR2A = 0;
  TCCR2B = 0x01;
  // Comparator on pin D6
  ACSR   = 0x10;           // Clear flag comparator interrupt
  //Set D8 (PWM in) to trigger interrupt (we use this to read PWM input)
  PCICR |= (1 << PCIE0);    //enable PCMSK0 scan                                                 
  PCMSK0 |= (1 << PCINT0);  //Set pin D8 trigger an interrupt on state change.								

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.

New title

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.

46 Comments

  • David Morreres Viladegut

    about 5 years 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.

    Noob 19129

    about 1 year ago

    Please try a hrefhttpswwwgooglecomGooglea before asking about a hrefhttpswww63gametopforumphpmodviewthreadtid289700pid433480page1extrapid433480Top Rated Product Websitea 579875

    Noob 19129

    about 10 months ago

    Please try a hrefhttpswwwgooglecomGooglea before asking about a hrefhttpsbonuscloudclubviewtopicphpf52t5283p273296p273296Great Product Guidea aa023d9

    Noob 19129

    about 10 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpelymbmxcommybbshowthreadphptid354pid6810pid6810New Product Infourl 23d94c5

    Noob 19129

    about 9 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttplieyanjicomforumphpmodviewthreadtid13086pid6827427page1extrapid6827427High Rated Product Guideurl a705798

    Noob 19129

    about 9 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpsbiomedtalkorgshowthreadphptid5642pid38071pid38071High Rated Product Guideurl 5f79e0b

    Noob 19129

    about 8 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpstalad2marketcomindexphptopic1588newnewBest Product Blogurl 4c5f79e

    Noob 19129

    about 7 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpcalaveroorgshowthreadphptid149945pid952190pid952190Excellent Product Guideurl 59a7057

    Noob 19129

    about 6 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpforuml2endlesscomshowthreadphptid7553pid23257pid23257Top Product Websiteurl 3d94c5f

    Noob 19129

    about 5 months ago

    In response to the guy inquiring about win1000x login no slot game bet slot win1000x slot login casino idn game slot yang gacor judi slot gacor game slot apa slot game website game slot jackpot I highly recommend this urlhttpssergioxflp92457newsblogercom28361245toptipstoselectingtajir4dsitescheck this out about tajir4d login adviceurl or bonus judi slot apa nama situs judi slot online web judi online slot virtual game judi apa itu judi slot online judi slot no 1 game judi online slot slot web game slot login on top of this urlhttpsjudahwbef84949xzblogscom69309888recommendednewsonselectingtajir4dsitesread full article on tajir4d tipsurl not to mention online slot indonesia slot game indonesia casino idn web gacor online idn slots games slot online indonesia idn slot game apa itu slot judi apa slot itu judi game slot judi on top of this urlhttpselliottbmwb19631xzblogscom69317060newinfoforchoosingtajir4dloginwebsiteshelpful resources about tajir4d login infourl which is also great Also have a look at this urlhttpslanefpwc57913wikidirectivecom6760094freetipstodecidingontajir4dloginwebsitesread review on tajir4d login urlurl as well as web slot online judi gacor judi slot gacor online judi indonesia game slot game judi slot anti rungkad judi slot indonesia website judi apa judi slot indo judi slot not to mention this urlhttpsricardodpaj28775ziblogscom27935714topfactsonselectingtajir4dwebsitescool training about tajir4d urlurl with slot online jackpot judi slots bonanza 100x slot fire login judi slot game gacor judi slot online indonesia game slot link website game slot online slot yg gacor for good measure Check more urlhttpswwwelektrofahrradtestsdeforumsshowthreadphptid94348pid252094pid252094Awesome Accident Lawyer Tipsurl 99f6c4a

    Noob 19129

    about 4 months ago

    In response to the people inquiring about slot gameplay web judi gacor judi slot indonesia game slot idn promo judi slot online game slot web apa game slot game slot login slot judi gacor slot game judi I highly recommend this urlhttpssoundsocialcomstory7444118situsslotpalinggacorandpermainanslotsee post for WIN1000X infourl or judi online game slot online indonesia gacor slots provider slot online slot online login gacor game slot game login cara login slot online game slot88 online daftar slots alongside all this urlhttpsbookmarksknotcomstory19100159situsresmislotandbesarslotgo to the website about WIN1000X linkurl not to mention judi ol slot live stream web slot game website judi win1000x login slot online judi game judi online game gacor slot indonesia online slot game website not to mention this urlhttpslabratoriescommemberphpactionprofileuid24awesome WIN1000X infourl which is also great Also have a look at this urlhttpswecantoUserMellyslotshigh rated WIN1000X siteurl not to mention judi slot indonesia slot game website web gacor online slot apa yang gacor game slot gacor terbaik judi online game provider slot online indo judi slot game website judi slot online and dont forget this urlhttpsforumiscev2024camemberphpactionprofileuid21cool WIN1000X infourl with provider slot online judi indo slot website game slot judi slot game indo judi slot kaya judi online indonesia gacor judi slot slot game game judi jackpot for good measure Check more urlhttpsuokananetmybbshowthreadphptid640447pid1448317pid1448317High Rated online casino games Tipsurl 3d94c5f

  • Ricardo Salazar 1983

    about 5 years 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

  • Noob 19290

    about 11 months ago

    Papa's Pizzeria is a simulation game where you assume control of the restaurant operations in Papa's absence and offer delectable pizzas. https://papaspizzeriagame.io

  • Noob 22221

    about 11 months ago

    hi

  • Noob 22221

    about 11 months ago

    Delhi Escorts are quite sensual, and you may cuddle up with them on your lap. If you’re up for some other kind of experiment, you can have it your way with our sweetest and still the hottest Escort in Delhi . Only you and I will make me incredibly happy. It’s important to keep in mind that all the females in Delhi are just like oneself women looking to have a great time if you take it easy and trust us, they’ll take you somewhere quiet where you and your lover may gaze at the stars in pleasure.

  • Noob 22221

    about 11 months ago

    Delhi Escorts are quite sensual, and you may cuddle up with them on your lap. If you’re up for some other kind of experiment, you can have it your way with our sweetest and still the hottest Escort in Delhi . Only you and I will make me incredibly happy. It’s important to keep in mind that all the females in Delhi are just like oneself women looking to have a great time if you take it easy and trust us, they’ll take you somewhere quiet where you and your lover may gaze at the stars in pleasure.

  • Noob 22221

    about 11 months ago

    Delhi Escorts are quite sensual, and you may cuddle up with them on your lap. If you’re up for some other kind of experiment, you can have it your way with our sweetest and still the Escort in Delhi . Only you and I will make me incredibly happy. It’s important to keep in mind that all the females in Delhi are just like oneself women looking to have a great time if you take it easy and trust us, they’ll take you somewhere quiet where you and your lover may gaze at the stars in pleasure.

  • Noob 26229

    about 10 months ago

    I appreciate you writing such a fantastic article. I’m eagerly anticipating your next posts. Visiting this blog is a pleasurable experience. I appreciate you telling me that. gacha life game

  • Noob 26606

    about 10 months ago

    [Google](https://www.google.com) google3 [http://www.google.com|google4 ] [http://www.google.com google5 ] [url=https://www.google.com]google[/url] [google7|http://www.google.com] "google8":www.google.com FF [google10](http://www.google.com/) [http://www.google.com|google11] [Lighthouse12](http://lighthouseapp.com/ "Lighthouse12") [13google->http://www.google.com/] [google14]url:http://www.google.com

  • Noob 26606

    about 10 months ago

    Are you guys seeking young, gorgeous female companions in the capital region, Aerocity? We ask this because we are eligible to conduct high-profile and beautiful Escort in Aerocity for your enjoyment. Your time has started if you have been alone for a long time. We are here to introduce the most essential services in Aerocity to you. Yes, we are discussing escort services in Aerocity, which has an empire of the cutest girls in the town.

  • Noob 21717

    about 10 months ago

    A student portal provides an immersive learning environment as it serves as a central hub for all applications, data, and content. All the information required for your online courses is provided by UNICCM

  • KAMAL SHAKIL

    about 6 months ago

    Welcome to Kamal Azfar & Asad Shakil Law Firm! Led by Senior Advocate Kamal Azfar, along with Advocates Asad Shakil and Zain Mustafa Soomro, we specialize in service matters, property law, accountability law, and criminal law. With decades of experience and a track record of success, our team is committed to providing top-notch legal representation tailored to your needs. Contact us today for expert assistance! https://azfarandasad.com/

  • Noob 33442

    about 6 months ago

    Evidence collection methods for nvq level 6 equivalent include direct observation, questioning, and work products. Learners showcase competency effectively through varied assessment criteria.

  • 2048 cupcakes

    about 5 months ago

    It's so cool. I often play the super cool game https://2048-game.io/too

  • 2048 cupcakes

    about 5 months ago

    It's so cool. I often play the super cool game https://2048-game.io/too

  • 2048 cupcakes

    about 5 months ago

    https://2048-game.io/

  • Noob 33442

    about 4 months ago

    There are a set of competencies the Institute of Chartered Surveyors will require you to possess. Having a rics competency guide will ensure you to know what set of skills you possess right now and what to improve.

  • Noob 39044

    about 4 months ago

    Thank you for sharing this article. The ESC project you are developing sounds very interesting and has potential. I wish you success in perfecting and applying your product in practical applications! slope game

  • Jersey Drive Driving School

    about 4 months ago

    https://jerseydrivedrivingschool.com/ Welcome to Jersey Drive Driving School, your premier destination for top-notch driving lessons across New Jersey (middlesex county). Our services include Edison Driving School, Eatontown Driving School, New Brunswick Driving School, Cherry Hill Driving School, and Old Bridge Driving School. We also offer road test preparation services for Eatontown Road Test, New Brunswick Road Test, Cherry Hill Road Test, and Bakers Basin Road Test. We also provide online driving test preparation nj and NJ Driving Test Practice. Join us at Jersey Drive Driving School or driving school edison nj and start your journey to safe driving today.

  • Jersey Drive Driving School

    about 4 months ago

  • Jersey Drive Driving School

    about 4 months ago

    [url=https://jerseydrivedrivingschool.com/]Driving School New Jersey[/url]

  • Noob 41018

    about 3 months ago

    nice

  • Noob 41018

    about 3 months ago

    Thank you the topic is interesting I will know, what else would be good to know is where you can play in India, I wondered about it for a long time until I found this wonderful site - https://1win-india.net/, it is here I really learned what the game is, I can safely recommend it to you, I'm sure you will also like everything!

  • Noob 41018

    about 3 months ago

    Thank you the topic is interesting I will know, what else would be good to know is where you can play in India, I wondered about it for a long time until I found this wonderful site - https://1win-india.net/, it is here I really learned what the game is, I can safely recommend it to you, I'm sure you will also like everything!

  • Noob 40662

    about 3 months ago

    Thank you the topic is interesting I will know https://1deposit.co.nz/

  • Noob 41128

    about 3 months ago

    https://www.stockbossup.com/pages/post/27452/buy-carisoprodol-online-safe-and-discreet-us-otc-delivery

  • Noob 41128

    about 3 months ago

    CLICK HERE ORDER NOW 👉https://easyhealthshop.com/product-categories/buy-carisoprodol-online CLICK HERE ORDER NOW 👉https://easyhealthshop.com/product-categories/buy-hydrocodone-online

  • Noob 42722

    about 3 months ago

    This ad for escort services in Aerocity feels like navigating through a maze in the game google searching for the perfect companion can be just as tricky. If you're feeling lonely, perhaps it's time to explore your options. Just remember to prioritize safety and respect.

  • BJ888 It Com

    about 3 months ago

    Tác giả Hoàng Quốc Anh là cái tên đã quá quen thuộc trong thị trường giải trí, cá cược trực tuyến. Anh là Ceo tài ba của BJ88, giúp nhà cái ngày càng phát triển mạnh như hiện tại. Trong bài viết dưới đây, hãy cùng chúng tôi tìm hiểu kỹ hơn về CEO Quốc Anh và những thành tựu đã đạt được nhé. Xem thêm : https://bj888.it.com/tac-gia/ Địa chỉ: 102 Hoàng Hoa Thám, Phường 7, Bình Thạnh, Hồ Chí Minh, Việt Nam Zip code : 700000 Số điện thoại: 0365511929 Email: bj888itcom@gmail.com #bj888it #bj888itcom #bj88

  • Noob 33442

    about 3 months ago

    Listing a certification or diploma in this field on your CV is invaluable, particularly when you grasp what is an nec contract , as NEC contracts are integral to ensuring excellence in construction projects. Employers look for managers who thoroughly understand what is an nec contract involves, as this expertise translates to improved company performance.

  • Dream Hauz

    about 2 months ago

    Dream Hauz - Home Remodeling Services Dream Hauz is your go-to expert for comprehensive home remodeling services. We specialize in transforming your living spaces into your dream home with precision and creativity. From kitchen and bathroom remodels to full home renovations, our team ensures high-quality craftsmanship and exceptional customer service. At Dream Hauz, we turn your vision into reality, enhancing the beauty, functionality, and value of your home. https://dreamhauz.com/

  • Dream Hauz

    about 2 months ago

    Dream Hauz - Home Remodeling Services Dream Hauz is your go-to expert for comprehensive home remodeling services. We specialize in transforming your living spaces into your dream home with precision and creativity. From kitchen and bathroom remodels to full home renovations, our team ensures high-quality craftsmanship and exceptional customer service. At Dream Hauz, we turn your vision into reality, enhancing the beauty, functionality, and value of your home. https://dreamhauz.com/

  • Noob 40091

    about 2 months ago

    Navigating cryptocurrency taxes can be quite challenging given the complexity of transactions and the evolving regulatory landscape. For those seeking to streamline this process, using specialized crypto tax software is essential https://paybis.com/blog/best-crypto-tax-software/. One standout option is Koinly, which simplifies tax reporting with a user-friendly interface and robust support for various exchanges and wallets. Another excellent choice is CoinTracker, known for its detailed tax reports and seamless integration with numerous platforms.

  • Noob 40091

    about 2 months ago

    Navigating cryptocurrency taxes can be quite challenging given the complexity of transactions and the evolving regulatory landscape. For those seeking to streamline this process, using specialized crypto tax software is essential https://paybis.com/blog/best-crypto-tax-software/. One standout option is Koinly, which simplifies tax reporting with a user-friendly interface and robust support for various exchanges and wallets. Another excellent choice is CoinTracker, known for its detailed tax reports and seamless integration with numerous platforms.

  • Noob 26866

    about 2 months ago

    A common requirement for networking Career paths in IT are CompTIA A+ and Cisco CCNA certifications. Offered online in UNICCM, each certification will serve as your proof of having the necessary expertise to handle network-related concerns.

Login or Sign Up to post comments on this tutorial.