PWM resolution


I'm working on a project to use an Arduino board as a significantly less expensive alternative to a PDI box for motor control. I'm relatively inexperienced when it comes to software/electronics, just a heads up. We've got an atmega2560 and we've got the pwm output to 16 bits which is fast enough but we need a higher resolution. The counter currently counts from 0 to 255 but how can I change that to a 16 bit counter if that's possible.


I'm using an mega 2560 by the way. I spent some time sifting through the datasheet for the 2560 and it seems I need to change ICRn or OCRnA to max, whatever that value may be.

We've got an atmega2560 and we've got the pwm output to 16 bits which is fast enough but we need a higher resolution.

If you are performing PWM with 16 bits, that's 32,768 steps of resolution. That's not enough?

What are you controlling that you can see more that 32,768 steps?

To my knowledge we were only getting 8 bits of resolution so 0 to 255. We had the pwm hooked up to an scope to check.

16 bits is 65536 steps, but maybe 4096 steps would do? That would be 12 bits.

The more accuracy the better. How would I go about doing that. I've been pouring over the atmel datasheet for the last day or 2 and have gotten somewhere but haven't figured it out yet

@PaulS 32768 counts would be more than enough. We're doing very precise motor control. Accuracy needs to be at the micron level.

32768 is 15 bits, but your original post said you'd already got 16 bits. I'm confused.

I was shooting for 16 bits of resolution in the duty cycle. Right now its an 8 bit duty cycle resolution.

15 bit would work, we just need significantly higher resolution than 0-255.

My bad on the poor communication.

In my original post, I meant to say the frequency is 62500 hz. But the resolution is too low. Hope that clears it up

What sort of frequency?

pwm frequency*

That doesn't make any sense. Your central heating thermostat operates on PWM, just a low (mHz) frequency.

Now I’m really lost haha. My problem is this. I have the arduino board controlling a motor using PWM. I’m using timer 2, pin 3; a 16 bit timer. I have the prescaler value for the timer set to 1 meaning a PWM frequency of 62500. (i used this The frequency of the PWM signal is fast enough but, we need a higher counter resolution to better control the duty cycle. In this case, we don’t want a duty cycle from 0 to 255, but something larger, hence I said 16 bit because I’m assuming that’s the cap. On the atmega 2560 datasheet, the MAX value for the counter is 0xFFFF which is what I want to set it to. But I don’t know how, which is what I’m inquiring about.

Take a look at the PWM library,117425.0.html