pwm-12-bits.ino
Due PWM pins 2-13 accept software resolution up to 12 bits: the ramp becomes perfectly continuous, no visible steps. One of the few practical gains of moving AVR → Due.
Hardware required
An Arduino Due (AT91SAM3X8E, ARM Cortex-M3 at 84 MHz) connected over USB to its « Programming » port. Caution: 3.3 V logic, never 5 V on the pins. 1 LED + 470 Ω resistor (3.3 V).
Wiring
LED + resistor between pin 2 and GND.
How it works
analogWriteResolution(12) reconfigures the TC/CPCS channel for 4096 levels; the loop sweeps the whole range both ways. In the Arduino IDE, select « Arduino Due (Programming Port) » then Upload; the serial monitor runs at the speed set in the code.
Going further
Filter the PWM with an RC (1 kΩ + 10 µF) to recover a smoothed analog voltage — the poor man's DAC.
pwm-12-bits.ino
// PWM 12 bits (0..4095) sur broche 2 : respiration ultra-douce.
const int LED = 2; // broche PWM (SAM3X CPCS)
void setup() {
analogWriteResolution(12); // 0..4095 au lieu de 0..255
pinMode(LED, OUTPUT);
}
void loop() {
for (int v = 0; v <= 4095; v += 8) { analogWrite(LED, v); delay(4); }
for (int v = 4095; v >= 0; v -= 8) { analogWrite(LED, v); delay(4); }
}