850
Chapter 24
Sound Generator (SG)
Preliminary User’s Manual U17566EE1V2UM00
(2)
Tone frequency calculation
The tone frequency can be calculated as:
f
tone
= f
SG0CLK
/ (([SG0FL buffer] + 1)
×
([SG0FH buffer] + 1)
×
2)
where:
f
SG0CLK
= frequency of the SG0 input clock
[SG0FL buffer] = contents of the SG0FL buffer
[SG0FH buffer] = contents of the SG0FH buffer
Example
If:
– f
SG0CLK
= 16 MHz
– [SG0FL buffer] = 255 (00FF
H
) (this yields a PWM frequency of 62.5 KHz)
– [SG0FH buffer] = 32 (0020
H
)
then:
– f
tone
= 947 Hz
Note
Note that the buffer contents can differ from the contents of the associated
register until the next compare match.
24.3.2
Generating the volume information
The sound volume information is generated by comparing the SG0FL counter
value with the contents of the SG0PWM volume buffer. An RS flipflop is set
when the counter matches the SG0FL buffer and reset when the counter
reaches the value of the volume buffer SG0PWM.
Figure 24-4
PWM signal generation
The duty cycle of the PWM signal is determined by the difference between the
contents of the SG0FL counter buffer and the contents of the SG0PWM
volume buffer. The larger the difference, the smaller the duty cycle.
The PWM signal is continually high when the value of the volume buffer is
higher than the value of the frequency compare buffer.
PWM
signal
(RS flip-
flop output)
t
SG0FL
counter
value
SG0FL buffer value
(when reached, sets the FF)
SG0PWM buffer value
(when reached, resets the FF)
electronic components distributor