Data Sheet

669
Atmel | SMART SAM D21 [DATASHEET]
Atmel-42181G–SAM-D21_Datasheet–09/2015
Dithering consists in adding some extra clocks cycles in a frame of several PWM cycles, improving the accuracy of the
average output pulses width or period. The extra clock cycles are added on some of the compare match signals, one at a
time, through a "blue noise" process that minimizes the flickering on the resulting dither patterns.
Dithering makes possible to improve the accuracy of the average output pulse width or period.
Dithering is enabled by writing the corresponding configuration in the Enhanced Resolution bits in CTRLA register
(CTRLA.RESOLUTION):
z DITH4 enable dithering every 16 PWM frames
z DITH5 enable dithering every 32 PWM frames
z DITH6 enable dithering every 64 PWM frames
The DITHERCY bits of COUNT, PER and CCx define the number of extra cycles to add into the frame (DITHERCY bits
from the respective COUNT, PER or CCx registers). The remaining bits of COUNT, PER, CCx define the compare value
itself.
The pseudo code, giving the extra cycles insertion regarding the cycle is:
int extra_cycle(resolution, dithercy, cycle){
int MASK;
int value
switch (resolution){
DITH4: MASK = 0x0f;
DITH5: MASK = 0x1f;
DITH6: MASK = 0x3f;
}
value = cycle * dithercy;
if (((MASK & value) + dithercy) > MASK)
return 1;
return 0;
}
1.7.3.3.1: Dithering on Period
Writing DITHERCY in PER will lead to an average PWM period configured by the following formula:
If DITH4 mode is enabled, the last 4 significant bits from PER/CCx or COUNT register corresponds to the DITHERCY
value, Rest of the bits corresponds to PER/CCx or COUNT value.
The PWM resolution can be calculated using the following formulas.
DITH4 mode:
DITH5 mode:
DITH6 mode:
1.7.3.3.2: Dithering on Pulse Width
Writing DITHERCY in CCx will lead to an average PWM pulse width configured by the following formula:
DITH4 mode:
PwmPeriod
DITHERCY
16
-------------------------------
PER+=
PwmPeriod
DITHERCY
32
-------------------------------
PER+=
PwmPeriod
DITHERCY
64
-------------------------------
PER+=
PwmPulseWidth
DITHERCY
16
-------------------------------
CCx+=