Arduino + ESC

Hello all,

Is the arduino duemilanove or the arduino Mega capable of a square wave output that has an on time of 60us and an off time of 450us and limiting the high voltage to 3.6V? I am trying to interface the arduino with a particular electric motor speed control that simultaneously controls four motors with just two wires. An on time of 60us will run the motors at a slow speed. The speed will increase as the high duration of the square wave increases until the line is held high at full throttle.

Please feel free to suggest alternative ways of producing such a square wave.

Thank you for your replies, Calaway_21

I don't think the high voltage can be limited to anything below 5V (for a 5V board, which includes the Duemilanove and the Mega) without some external circuitry. As far as generating the square wave, that can be done without too much trouble. The Servo library may do what you want. If not, download the datasheet for the ATMega168 or ATMega328P (for the Deumilanove) or the ATMega1280 (for the Mega) from Atmel and look at the pages on the timers in PWM mode. You'll have to set some configuration registers, but the datasheet is very clear.

The voltage may not be so important as I am now finding. However, what is it that I should be looking for in the datasheet? For the atmega1280 the datasheet is 400 pages. :o

Will I have to change any hardware? Or can the timing be achieved through software alone?

Thank you for your replies, Calaway_21

For the atmega1280 the datasheet is 400 pages

But the section on PWM is much shorter.

You need a PWM frequency of 1961 Hz (should be easy to get close) - is this critical, or is the mark/space ratio the critical thing?

Can you show the spec of the ESC?

The timing can be achieved through software alone. The datasheets are a bit intimidating at first, but in general you only need to read about 10 pages to get any one thing done. :D You're looking for the Timer/Counter modules. Basically, this is how it works. A timer/counter has a register that it increments each time the clock cycles without interfering with your code. You can set a value at which the timer/counter will reset itself. By working out a little formula which should be in the datasheet, you can figure out the period between timer/counter resets based on how fast your clock is (in this case, 16MHz). The next step is to make the timer/counter trigger the value of a pin when it resets itself. It can do this automatically in hardware by using PWM (Pulse Width Modulation) mode. Basically, you tell it which pin to turn on and off and how high to count between pin toggles and you've got it. The ananlogWrite() function and the Servo library both do this for you. I would recommend just trying both of those and varying the value you pass until you get what you want from it. If that doesn't work, then you can delve into the datasheet and figure out what exact values will have to be set in order to get the precise timing you want.

Be careful about the maximum voltage you apply at the control inputs to the ESC. If the ESC specifications don't say that it is 5V tolerant then it NOT safe to assume that it is and you could damage it by using a 5V square wave.

The reason is that there are internal protection diodes on the input pins on almost all semiconductor ICs, going from the signal line to both supply rails. The diodes are there to protect the device against low energy transients (eg ringing on signal edges) by clipping any voltage on the input that goes above or below the device supply (eg 3.6V or 0V) to a diode forward voltage drop (0.7V) above or below the supply rails (eg total of 4.3V or -0.7V) in order to prevent malfunction, internal latch up or damage to the internals of the device.

These kind of transients are normally do not persist for very long and so protection diodes are not usually designed to handle large amounts of energy. If you directly feed an input on a 3.6V device with a 5V signal the protection diode will try and source as much current as it can from the driving signal and try and to pull it down to 4.2V. This can be many 10s of mA of current, which can potentially damage the device driving the signal as well as cause the internal protection diode to dissipate more energy than it is designed to and eventually burn out, which can take the device out with it.

These kind of faults may not occur immediately, but may take a while to appear as the continual exceeding of the limits of the devices can eventually cause them to randomly fail months down the track.

Some low voltage devices are designed to be 5V tolerant and their data sheets will will tell you it is. Unless a low voltage device is guaranteed to be 5V tolerant, you should consider at least a series current limiting resistor or some kind of voltage level translation device or divider circuit between all 5V devices driving devices on lower voltage power supplies.

So the moral of the story when dealing with devices with mixed supply voltages is to always make sure the data sheet for the lower voltage device say that it can handle what the higher voltage devices dish out.

If you do a voltage divider with a 3.3K to the digital pin, and 6.8K to ground, you'll get about 3.5V out.

But you need to make sure that the ESC has a high-impedance input (which it probably, but not certainly, does). See if you can get a datasheet for the ESC that tells you what the input high and low currents are. It's probably on the order of a few microAmps, so you'll get a "close enough" voltage.

If the input needs more current, you'll need to scale down the voltage divider resistors so they're small compared to the input impedance of the ESC. Or you can just go to a 330 and 680, waste a few mA, and be almost certain you'll get the right voltage.

Ran