Dithering consists in adding some extra clocks cycles in a frame of several PWM cycles, and can improve
the accuracy of the
average
output pulse width and 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 is enabled by writing the corresponding configuration in the Enhanced Resolution bits in CTRLA
register (CTRLA.RESOLUTION):
•
DITH4 enable dithering every 16 PWM frames
•
DITH5 enable dithering every 32 PWM frames
•
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;
}
Dithering on Period
Writing DITHERCY in PER will lead to an average PWM period configured by the following formulas.
DITH4 mode:
��������� = DITHERCY
16
+ PER
1
�
GCLK_TCC
Note:
If DITH4 mode is enabled, the last 4 significant bits from PER/CCx or COUNT register correspond
to the DITHERCY value, rest of the bits corresponds to PER/CCx or COUNT value.
DITH5 mode:
��������� = DITHERCY
32
+ PER
1
�
GCLK_TCC
DITH6 mode:
��������� = DITHERCY
64
+ PER
1
�
GCLK_TCC
Dithering on Pulse Width
Writing DITHERCY in CCx will lead to an average PWM pulse width configured by the following formula.
DITH4 mode:
������������ℎ = DITHERCY
16
+ CCx
1
�
GCLK_TCC
Atmel SAM L22G / L22J / L22N [DATASHEET]
Atmel-42402E-SAM L22G / L22J / L22N_Datasheet_Complete-07/2016
813