Compiling SimonK ESC Firmware and Reversing the Motor Direction in Software Instead of Hardware

Discussion in 'Custom Programming' started by alm865, Apr 30, 2015.

  1. alm865

    alm865 Active Member

    I came across this neat trick while building my first quad. Basically instead of going to all the effort of swapping two motor leads you can simply change one bit in the SimonK firmware on your ESC to reverse the motor direction. This is especially useful if you are like me and don't want the extra weight of bullet connectors and have simply soldered and heat shrunk your motor connections.

    Tools Needed (if you've programmed your ESCs before you'll already have this stuff):
    • USBasp ($3 or so from ebay)
    • In-circuit chip programmer (about $30 from HobbyKing, definitely worth the money if you don't have programming pins on your ESC!!)
    • Stanley Knife
    Now carefully cut three sides of the heat shrink around the Atmega chip on your esc to make a flap so that you can easily access the entire chip ready for programming. Remember the red dot on the in circuit programmer lines up with the small embossed circle on the top of the chip.

    NOTE: For anyone who is using Windows and only wants to use tgy.hex without all the hassle of compiling, skip straight to downloading kkMulticopterFlashTool and use my precompiled versions attached to this post.

    Now for the software part, I downloaded the latest SimonK firmware (, see Download as Zip button on right had side), and extracted it.

    I'm using Ubuntu (Linux) and just typed the following in a terminal (from the tgy-master folder that is). If you don't have Linux, just download virtual box and create a virtual machine and install Linux/Ubuntu, or you can even boot straight into Linux from a Linux Install CD without installing anything. Seriously, Linux makes the whole build process child's play.
    • sudo apt-get install avrdude
    • make all (or maybe it was just make, can't remember)
    • avrdude -c usbasp -p m8 -U flash:w:tgy.hex (or which ever .hex file you need to use)
    If you want to reverse the motor direction simply change this line in tgy.hex and recompile using 'make all' then flash again, then PRESTO!! Motor direction reversed:

    '.equ MOTOR_REVERSE = 1 ; Reverse normal commutation direction'

    If anyone has trouble compling the SimonK firmware, here are some compiled versions (you really only need the .hex file for your board, check here, here and here to find out what ESC you have and what .hex file you need)

    tgy-master AM (There should be tgy.hex for normal direction, and tgyReversed.hex for reverse direction, if you need one of the other .hex files please compile them yourselves, of course ask questions if you get stuck!)

    Remember, always make you have the correct .hex file for your ESC otherwise there could be chaos!! and you'll need to re-calibrate your ESCs to your flight controller after flashing your ESCs.

    Attached Files:

  2. alm865

    alm865 Active Member

    I might do a bit of a word doc instruction with some pics later on.
  3. GJH105775

    GJH105775 Avid Linux User, and USAF 1C6 Moderator

    That would be great. I like to see people modifying their firmware to allow diversity. This is the whole reason for the freedom of open-source.
  4. alm865

    alm865 Active Member

    And there is a whole heap of tweaks that SimonK left in there too that can greatly improve the performance of your ESC if you know what you are doing. I noticed there is a variable for dead time, it is set to a very conservative value (understandably) but if you knew exactly what MOSFETs (or more specifically the slew rate or switching speed in microseconds/volt) your board had and the voltage of your battery you could work out the actual dead time which would give you a considerable performance boost at fast speeds.

    SimonK did an awesome job with this firmware, there's nothing I can think of adding because everything I want to change is broken out into variables ready to tweak. You can even turn off that annoying "I'm alive" beeping it does, really everything that should be changeable is handed to you at the start of the code!
  5. GJH105775

    GJH105775 Avid Linux User, and USAF 1C6 Moderator

    Haha, that and comments are the mark of a good programmer. I use a lot of comments, but my arrangement for everything and how I do things is sloppy as crap. xD

Share This Page