I’ve recently started a project to build a quadcopter using discrete parts off Amazon, however it hasn’t quite been going according to plan. For starters, the four “El Cheapo” Mystery Cloud 30A electronic speed controllers (ESCs) I purchased were a epic failure after they would randomly turn off if throttled down too quickly.

Now these ‘puppies’ come with zero documentation – no surprises there given the price – but after quite a bit of digging around I managed to find a document here describing how to program them. Unfortunately this only served to confirm how basic these devices were, since I could find no option in there which would change the unwanted behaviour.

Further research seemed to indicate non-quadcopter ESCs generally expected PWM signals at a rate of about 50 Hz, and anything faster than this just gets averaged out by the firmware. My quadcopter uses a KKMultiCopter V5.5 flight controller board running the XCopter v2.9 XXControl Korean firmware from Minsoo Kim. It generates a 495 Hz PWM signal to the ESC – I was able to verify this with my scope – and they seem to be unable to cope with rapid changes in pulse width. Generally the solution to this is to replace the stock ESC firmware with SimonK firmware (assuming your ESC is supported) to get it to accept the 495 Hz PWM signal. So naturally this was my next move.

I checked out the device compatibility chart and found that my Mystery Cloud 30A was supported *screams and claps* by the Tower Pro build of the firmware (tp.hex). Luckily I got a USBasp in-system programming (ISP) adapter with my KKmulticopter board – which I had already successfully used to update the firmware – so I figured it was just a matter of following the SimonK instructions on how to strip open my ESC and reflash the firmware. But no, not quite so simple.
ISP-pad-pin-connectorFor starters, my ESCs did not come equipped with any pin-header connector for attaching my ISP adapter – why the bastards – but rather a 2 x 3 (6 wire) cluster of terminals could be clearly seen printed onto the board so first I needed to find a way of interfacing with terminals, and I wasn’t going to take temporarily soldered wires as an option. Several failed attempts, 1 eraser and 6 ball head pins later, I came up with the contraction shown here which had to be held in place by PCB holder so that it was perfectly positioned over the ISP pads of the ESC board while it sat snug in a bench vice.

So you can imagine my anguish after I was finally able to flash the SimonK firmware onto my ESCs, only to discover I that it wouldn’t work because my Mystery Cloud 30A board (probably as of a recent version 2) was fitted with the new and improved Atmega88 microcontroller, whereas SimonK firmware was only supported on Atmega8 based ESCs!!!

But all hope wasn’t lost yet. After spending a bit of time reading Atmel’s replacement guide to understand just how different these two chips were, I realised that it might not take that much effort to port the SimonK firmware to the Atmega88. A week later and I’ve finally done it and the ported code works fine on my Atmega88 based ESC. I’ve provided a diff patch here for anyone willing to try it (at their own risk of course). Admittedly, my current patch is quick and nasty. It breaks support for Atmega8 and since I haven’t gotten around to patching the bootloader code, I’ve also had to disable this for now. In the interest of contributing back to the SimonK project I’m planning to tidy up my changes at some point so that Atmega88 support just becomes a build configuration, and also port the bootloader code, and then submit these for integration into the SimonK project (if they want it).

The following steps briefly describe how to apply the patch and assume (for simplicity) the build is being done on a Ubuntu machine although all the tools used are available under other O/Ses and Linux distributions. So here’s what you’ll need to install if you don’t have it already:

[code language=”bash”]
sudo apt-get install git
sudo apt-get install avra
sudo apt-get install avrdude
[/code]

Now let’s get the source, patch it and build the firmware binaries:

[code language=”bash”]
# clone the SimonK source repository
git clone https://github.com/sim-/tgy
cd tgy

# ensure we’re patching the right revision/commit level
git reset –hard 2e13dfa

# get the patch
wget https://simonk-m88-patch.googlecode.com/git/tgy.asm.diff

# apply the patch
git apply –ignore-whitespace tgy.asm.diff

# get a local copy of m88def.inc from avra install
cp /usr/share/avra/m88def.inc .

# build the firmware *.hex files
make
[/code]

Assuming that all went well you now need to flash the appropriate *.hex firmware file for your ESC. At this point it would be great if we could just use the KKMulticopter Flash Tool which is a user-friendly GUI wrapper around avrdude for choosing your programmer, firmware file and flashing your ESC, however it currently appears to only support flashing “Atmega 8-based brushless ESCs” which wouldn’t work for Atmega 88-based ESCs as the device signatures won’t match. So instead I had to just use avrdude directly from the commandline:

[code language=”bash”]
$ avrdude -p m88 -P usb -c usbasp -e -U flash:w:tp.hex:i

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0xffffff
avrdude: Yikes! Invalid device signature.
avrdude: Expected signature for ATmega88 is 1E 93 0A
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "tp.hex"
avrdude: writing flash (8192 bytes):

Writing | ################################################## | 100% 2.52s

avrdude: 8192 bytes of flash written
avrdude: verifying flash memory against tp.hex:
avrdude: load data flash data from input file tp.hex:
avrdude: input file tp.hex contains 8192 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.05s

avrdude: verifying …
avrdude: 8192 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.
[/code]

Not show above as a precaution is the “-F” override flag I needed to use since in my case the device signature wasn’t even preprogrammed into the Atmega88 of my Mystery Cloud 30A ESC (i.e. it was set to all F’s). However it’s best to try flashing your ESC without that flag set initially, because apparently incorrectly wiring your programmer to the ESC can also give a bad device signature.

4 thought on “SimonK ESC firmware on Atmega88”
    1. Hi Delfer,

      Thanks for the feedback, you actually made me realise I had missed a step in my instructions regarding adding the m88def.inc to the source directory.

      Your Atmega48 has half the flash/ram/eeprom of the Atmega88 but I had a look at one of the generated Intel hex files and it seems the SimonK firmware is only about 2.6KiB in size and only uses 48 bytes of ram so it should fit okay. Also your Atmega48 doesn’t support a bootloader so I had to remove the reference to the THIRDBOOTSTART address in the source.

      I’ve provided the patched source files here: https://drive.google.com/file/d/0B7sC7PM99Y-OMnhYQUktNlBWc3M/view?usp=sharing

      Hopefully it works and resolves your watchdog timer reset issues. 🙂

      Cheers,
      Kris

Leave a Reply