Due PWM Dimming Resolution Only 8 bit?

Hello All,
I'm running some tests on the Due PWM resolution and frequency capabilities for an LED project and though I've set the analogWriteResolution() to 12 bits and can send 12bit (0-4095) counts to the write function, when I measure the duty cycle on a scope it only shifts every 16 counts. This works out to 256 levels of dimming or 8 bits. I also played with the pwm01 library and was able to change the frequency with no problems however, even though using the pwm_set_resolution(16) function allowed me to write 16 bit counts, the PWM duty cycle shift again only worked out to be 256 levels of dimming.
I've searched the forum for confirmation of this and think I found a thread in Italian that touches on it but I'd like to confirm it.
Is this the case and is there a method out there to get true 12 or 16 bit resolution PWM dimming from the Due without buying an external device?
Thanks,
DD

http://arduino.cc/en/Reference/AnalogWriteResolution

Thanks for the link, Mark. I did read that and I set analogWriteResolution() to 12 bits. It doesn't change the 256 dimming levels of the PWM output though. Instead of shifting the duty cycle every count, it shifts every 16 (12 bit) counts. Same resolution...
Fortunately I've found a solution. I am able to get full 12 bit PWM dimming resolution using the adafruit 12 bit servo driver board.
Thanks,
Dave

I've noticed the same behavior on my Due. Even though I've set 12 bits of resolution with the analogWriteResolution(12) function, I'm only getting an effective 8 bits resolution.

I know the ATSAM3x is capable of much more, why does this only pretend to give higher resolution?

I was a bit glib in my previous posting - it seems the Due implementation still
has only 8-bit PWM_RESOLUTION
(PWM_RESOLUTION is #defined in variant.h, btw - you could tailor you
distribution by changing it - I believe I've commented on here before that
is ought to be a variable, not a #define, anyway).

I'd also check to see if there's a good PWM library for the Due - its entirely possible
someone has created one.

I did read that and I set analogWriteResolution() to 12 bits.

That only works on the two true A/D outputs, it does not refer to the PWM output as people have pointed out for many years is very badly named.

The comments in the code make it clear that the call is meant to apply to analogWrite
as well as analogRead.... In fact it will work if the PWM_RESOLUTION #define is
changed to 12 as the code calls mapResolution() for PWM and TC pins as well as
for DACC.

Of course changing the PWM_RESOLUTION would also need changes to some of the
other parameters to avoid slowing down default PWM frequency.

So a little quick check - seems to work at 12 bit resolution with these definitions
replacing the old ones in variant.h:

/*
 * PWM
 */
#define PWM_INTERFACE		PWM
#define PWM_INTERFACE_ID	ID_PWM
#define PWM_FREQUENCY		1000
#define PWM_MAX_DUTY_CYCLE	0xFFF  // changed from 255
#define PWM_MIN_DUTY_CYCLE	0
#define PWM_RESOLUTION		12  // changed from 8

/*
 * TC
 */
#define TC_INTERFACE        TC0
#define TC_INTERFACE_ID     ID_TC0
#define TC_FREQUENCY        1000
#define TC_MAX_DUTY_CYCLE   0xFFF  // changed from 255
#define TC_MIN_DUTY_CYCLE   0
#define TC_RESOLUTION	    12  // changed from 8

Path to variant.h:
/hardware/arduino/sam/variants/arduino_due_x/variant.h

Hello Everyone

am using Due with 12-bit Servos :slight_smile:
i need to set servo PWM frequency to 333Hz
also i need to set servo PWM RESOLUTION to 12-bit
but how :frowning:
do i need to change variant.h :slight_smile:
or what !

Best,,