View Full Version : Discussion Arduino I2C to PWM converter
13brv3
Apr 25, 2009, 04:00 PM
Greetings,
For a while now, I've had one of my MKs (Mikrokopters) set up with Turnigy Plush 18A ESCs, using Arduino boards to do the I2C to PWM conversion. The programming was so easy that I couldn't resist trying it, and was surprised to see that the ESC didn't seem to have any problems with the 500 Hz update rate.
http://www.radrotary.com/Arduino_pw..._converters.wmv
The MK, and several other multi-copters use special I2C bus motor controllers, rather than the off the shelf PWM variety. The claim is that only the I2C type are fast enough, but that's a very debatable topic. I've always wondered if I could convert the I2C to PWM, just to see how well the normal controllers work, so this was hard to resist.
The MK updates the I2C motor power levels at about a 2ms interval, and the Arduino takes this, then uses the PWM feature of the chip to output at the same rate. Obviously, there's very little time to spare when the throttle is at the max 2ms setting.
There is about a 3 ms delay between the end of the I2C data, and the end of the updated PWM pulse width, which varies a bit. The delay is making me change some of the flight parameters, but even without any changes, it flies pretty well.
The other issue is that there are only about 128 throttle steps available, which definitely results in a bit less throttle precision than the usual 256 from the MK. This is going to be pretty unavoidable when using the PWM function of the Arduino, since it gives 256 steps from 0 to 2ms, and we can only use the part from 1ms to 2ms. Also, the Turnigy Plush seems to only have 128 steps itself. I've heard that there are some ESCs that use 256 steps, but I'd have to use a different method of generating the pulses than the simple PWM function of the Arduino. I don't really really have any plans to pursue that right now.
While this isn't something I highly recommend, if you want to play with it, here's all the info. The board is an Arduino Pro Mini 5V/16MHz from Sparkfun:
http://www.sparkfun.com/commerce/product_info.php?products_id=8991
Unfortunately, I haven't found any way to assign more than one I2C address to the Arduino, so you need one board per motor. It's also likely that the time it would take to process more than one address would push the response time over 2ms, since it's so close already.
A photo with the connections, and the program are attached. You'll have to remove the extra .zip extension that I added to the code file to fool the forum system into uploading it.
Enjoy,
Rusty
jonbev
Apr 26, 2009, 03:05 AM
Thanks for this rusty.
I've not used arduino boards before but looking at the code it does seem very simple.
In the MK thread you said one board cannot be used for more than one ESC, looking at the code and the board I can't see why? I'm sure you can tell me?
Jon
13brv3
Apr 26, 2009, 10:06 AM
Thanks for this rusty.
I've not used arduino boards before but looking at the code it does seem very simple.
In the MK thread you said one board cannot be used for more than one ESC, looking at the code and the board I can't see why? I'm sure you can tell me?
Jon
Hi Jon,
Thanks for reminding me to add that. The Arduino board has to be a slave device with the address of the motor controller that the MK expects to be using. Unfortunately, you can't assign more than one address to the Arduino using the standard wire library.
It was suggested on one of the forums that you could possibly do the I2C functions entirely in software, and perhaps make it work with multiple addresses that way. A programming project like that would be way over my head, so it's not really an option for me.
Rusty
jonbev
Apr 26, 2009, 11:32 AM
Perhaps i'll have a look at the wire lib and see what's going on in there.
To be honest i'm looking at this as a possible cost saving project as the MKEsc's are rather expensive!
Just had a thought about the coax setup you have. Do you run 6 arduino's or just 3? Couldn't you run three and output a slightly lower value to a second output pin to achieve the the power differential that is required to get the best out of the coax arrangement?
13brv3
Apr 26, 2009, 02:49 PM
Just had a thought about the coax setup you have. Do you run 6 arduino's or just 3? Couldn't you run three and output a slightly lower value to a second output pin to achieve the the power differential that is required to get the best out of the coax arrangement?
Interesting thought, but in this case, the top and bottom motors have to be controlled separately (6 arduinos) to control yaw. If you had an even number of arms with a coax arrangement, then you could do what you suggest.
The coax arrangement is sexy, and cool looking, but it's a bad idea unless you work for the marketing department ;)
Rusty
Arthur P.
Apr 26, 2009, 07:31 PM
@Rusty,
Thanks for posting this. Shows there are many ways to skin a cat....
Costwise converting the TowerPros to I2C/TWI is probably very competative as they cost little --about the same or less than each of you additional boards-- so even if you trash 20% you still are saving a bit.
As long as the Mikrokopter, UAVP and others use the lower speed TWI/I2C buss, the debate about the benefits over direct PWM interfacing will continue. Once they would move to higher rates, it will probably be less important.
I think I2C vs PWM for motor control alone really doesn't make much of a difference IF the ESC can handle the high rate PWM. However in the longer run I do see a lot of opportunity for a device addressed bus to interface many different intelligent peripherals for input and output. E.g. on a high speed TWI/I2C bus wiring for a a 12 motor multikopter setup, with GPS, altitude, accelerometer, gyros, proximity sensors, camera on/off, tilt, roll, yaw, zoom and shutter control, retractable landing gear, etc, would really be greatly simplified. At the moment the I2C bus speed used offers minimal benefit over direct PWM and a number of peripherals are interfaced using PWM or different serial interfaces.
Your project for interfacing the ESCs to the I2C bus using a small Arduino board is actually critical in this longer term vision. It would make it possible to eventually interface the GPS, accelerometer, etc, all using this type of simple little stamp like add on. And at the central controler end this could offer advanatages as well as the whole system becomes more message based. As long as a standard message is used between the I2C interface to a sensor or actuator, the rest of the thing becomes a black box.
13brv3
Apr 27, 2009, 12:03 PM
Hi Arthur,
It sounds like you've certainly put in some thought about the future of these systems. I can't really say I've thought about the future designs that much, but I agree that higher speed I2C could certainly allow more convenient options for interfacing all the individual parts of the system.
As for the I2C conversion of the TowerPro ESCs, I think the complexity of the modification is clearly the biggest issue. If you don't mind doing the mod, it's quite a good alternative to the Holgers.
It's a shame that we can't interest one of the ESC manufacturers into offering a reasonably priced I2C ESC. Just imagine if TowerPro offered a special version for us. I'm sure the market is small, but maybe not so insignificant as it used to be.
Cheers,
Rusty
jonbev
Apr 28, 2009, 02:47 PM
Hi Rusty,
Do you know if I can use my mkusb to program the mini pros?
Jon
13brv3
Apr 28, 2009, 03:09 PM
Hi Rusty,
Do you know if I can use my mkusb to program the mini pros?
Jon
Hi Jon,
I sure never thought about it, but the exact same FTDI chip is on the Sparkfun adapter, and the MKUSB. The MKUSB says 5V (with the jumper), and the Sparkfun says 3.3V, but these pro mini boards are supposed to be 5V. I'd be willing to be you could make it work if you can determine the required pinout.
Rusty
Arthur P.
Apr 28, 2009, 03:49 PM
All the ESC manufacturers have to do is:
a) leave SDA and SCL free and provide two soldering pads for connecting to them, and
b) provide pads for connecting to MISO, MOSI, SCK, RST and GND.
Those design and manufacturing changes really don't have to cost anything and they would allow ESCs to be converted very quickly. If they would install the normal firmware with a bootloader it would be even simpler re updating or changing the firmware. Better still they could adapted the firmware to allow control over either PWM or I2C just as is the case with the Holgers (which can also be controled over serial, so 3 modes all accepted by the same firmware).
So far the only I2C (ready) ESC are however the Holgers which can actually use PWM, serial or I2C for control using the same firmware, or the YGE's which however have a somewhat peculiar implementation of the I2C firmware.
As there is essentially no cost involved for making the ESCs PWM+ I2C/TWI + serial bus controlable, I really don't understand their lack of interest. The first manufacturer who comes out with a range of such ESCs at normal/ low prices (thus spreading the cost over all users, not just the multikopter fliers) would certainly make a long lasting name for himself within the communities interested in quadrocopters, but also those interested in other forms of robotics which require efficient high power electric motors.
FredericG
Apr 29, 2009, 02:43 AM
In the meantime, I am very interested in this approach. Rusty has demonstrated that It works very well. In its current implementation the only disadvantage is that one needs one board per motor. IMO it should be possible to make a device that can handle 4 or more motors.
I have been thinking how it could be done with a small PIC I am familiar with. I think it would be a challenge to generate 4 jitter-free pulses that overlap in time. Perhaps this would be a perfect task for a propeller chip. It hosts 8 small controllers. One could listen to the i2c and the other could generate pulses.
Frederic
v800290
May 03, 2009, 04:23 PM
IēC means viceversa communication...
at least when it getīs to Okto- or Decacopter, youīll get into timing-probs with a multi-IēC-to-PWM-Converter...
So i started converting the towerpro-escīs with Quax-firmware...itīs not much work, you save "payload" :D and money...
And: the only escīs wich can handle the 500Hz update rate are those, which can be easily converted because they are using an external resonator at 16MHz...
peter
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.