# Mega 2560 16 bit pwm enable?

**URL:** <https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616>\
**Category:** Uncategorized\
**Created:** [November 17, 2020, 2:34am UTC](https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616 "2020-11-17T02:34:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnaride](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@magnaride](https://forum.xod.io/u/magnaride)\
**Post date:** [November 17, 2020, 2:34am UTC](https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616/1 "2020-11-17T02:34:15Z")

</div>

Hey Team.

I have a question. I need to get a higher resolution than 255 on pwm channels.

the problem I’m driving a low current coil 1.8 ohms up to 1.1 amps(max 1.98v) from a 14.5volt car power system.

I need to have at least 200 steps from 0-1.98 volts for accurate control. the more the better.

I know i could run a buck converter to drop the voltage. but i’m trying to minimize the parts that i use. on my project.

and it needs to run at a minimum of 20khz to not hear the coil. (this part i already figured out and have my mega running at 31khz)

is there an I2C ADC add on board that will do what i need?

---

<div class="post-metadata">

**Author:** ![gabbapeople](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gabbapeople/32/1517_2.png) [@gabbapeople](https://forum.xod.io/u/gabbapeople)\
**Post date:** [November 18, 2020, 12:15pm UTC](https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616/2 "2020-11-18T12:15:26Z")

</div>

Hi! @magnaride  
The hardware PWM on the Mega is limited to 8 bits (0-255). Try to get the Board extenders. For example cheap based on PCA9685 chip with the 12-bit resolution (0 - 4095).

[https://www.amazon.com/16-Channel-12-bit-Servo-Driver-Interface/dp/B00EIB0U7A/ref=sr\_1\_1?dchild=1&keywords=pwm+12+bit&qid=1605701470&sr=8-1](https://www.amazon.com/16-Channel-12-bit-Servo-Driver-Interface/dp/B00EIB0U7A/ref=sr_1_1?dchild=1&keywords=pwm+12+bit&qid=1605701470&sr=8-1)  
[https://www.amazon.com/Dorhea-PCA9685-Interface-Controller-Raspberry/dp/B07RMTN4NZ/ref=sr\_1\_3?dchild=1&keywords=pwm+12+bit&qid=1605701446&sr=8-3](https://www.amazon.com/Dorhea-PCA9685-Interface-Controller-Raspberry/dp/B07RMTN4NZ/ref=sr_1_3?dchild=1&keywords=pwm+12+bit&qid=1605701446&sr=8-3)

The module works via I2C. I didn’t find a XOD library for this module in our libraries base, so probably you’ll have to write it yourself. The good news is that it’s not complicated at all.

> **[adafruit/Adafruit-PWM-Servo-Driver-Library](https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library)**
>
> Adafruit PWM Servo Driver Library. Contribute to adafruit/Adafruit-PWM-Servo-Driver-Library development by creating an account on GitHub.

  

> **[TeraHz/PCA9685](https://github.com/TeraHz/PCA9685)**
>
> C/C++ Library for PCA9685. Contribute to TeraHz/PCA9685 development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![magnaride](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@magnaride](https://forum.xod.io/u/magnaride)\
**Post date:** [November 18, 2020, 9:52pm UTC](https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616/3 "2020-11-18T21:52:22Z")

</div>

I found that controller and have used it, the issue is now that it only operates at 1.6hz and that is far too low to drive a coil and not hear it

---

<div class="post-metadata">

**Author:** ![gabbapeople](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/gabbapeople/32/1517_2.png) [@gabbapeople](https://forum.xod.io/u/gabbapeople)\
**Post date:** [November 18, 2020, 10:26pm UTC](https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616/4 "2020-11-18T22:26:01Z")

</div>

I have a solution. 16-bit PWM-enabled GPIO expander on STM32 with I2C communication. But I do not know the upper limit for pwm freq. In theory it should be much more than 8KHz

> **[GPIO Expander (Troyka Module)](https://amperka.com/products/troyka-gpio-expander)**
>
> This I²C expander will add nine additional GPIO ports to your controller to be used as digital, or analog, inputs, or outputs. The purpose and function of the pins are specified programmatically, directly in the sketch. 
> The module is built on the...

  

> <https://github.com/amperka/I2CioExpander/blob/master/src/GpioExpander.h>

---

<div class="post-metadata">

**Author:** ![magnaride](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@magnaride](https://forum.xod.io/u/magnaride)\
**Post date:** [November 22, 2020, 2:52am UTC](https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616/5 "2020-11-22T02:52:56Z")

</div>

that looks really interesting, i’m betting we don’t have a node for it yet.

I suppose i could always use a Teensy as well and replace the Mega 2560 all together

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [December 22, 2020, 2:53am UTC](https://forum.xod.io/t/mega-2560-16-bit-pwm-enable/4616/6 "2020-12-22T02:53:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
