analogwrite 4095 does not produce PWM (constant 3,3V)

Hi!

When I write analogWrite(2, 4079) the signal is fine, 500Hz PWM is generated, but when I go higher than 4079 DUE does not generate PWM but gives out constant 3,3V. Why is that so?

I did not know we can write a value bigger than 255 with analogWrite. Is this correct? I think it should be between 0 and 255

Because the granularity defaults to 8 bit, so values 4080 … 4095 map to 255 which is
the maximum duty cycle. There are other threads about this, the PWM hardware can
be programmed in much more flexible ways, I think someone posted a library for this too.

The file variant.h has constants
PWM_MAX_DUTY_CYCLE
PWM_RESOLUTION
TC_MAX_DUTY_CYCLE
TC_RESOLUTION

which you can experiment with - change the resolution to 12 and
the max duty cycles to 4095 (or 0xFFF) and you’ll get 12 bit resolution
on PWM after calling analogWriteResolution(12) ;