Galak Electronics VG-211 Руководство - Страница 3

Просмотреть онлайн или скачать pdf Руководство для Игрушка Galak Electronics VG-211. Galak Electronics VG-211 6 страниц. Singing snowman

Galak Electronics VG-211 Руководство
Creating a Music Generator
The key to creating music through a microcontroller is to generate the appropriate frequency
based on an equal-tempered music scale (A
frequencies generate to create all the notes you hear in your Singing Snowman.
Note
C5
#
C
5
D5
#
D
5
E5
F5
#
F
5
G5
A
5
b
A5
B
5
b
B5
The actual tone is generated by using the period of the selected note and dividing it by two to
determine the "on" and "off" time of each waveform. The microcontroller reads the note value
and length (stored as 16
calculates the duration of the note as the total number of waveform cycles. (Note: the duration
of a whole note is approximately one second).
For example, if the note is a half note of D5 then the following calculation is made:
Period = 1703 µS ÷ 2
Thus, to create a half note of D5 the microcontroller will pulse the output high for 852 µS and
then set it low for the same duration. This will generate a square wave with a frequency of
about 587 Hz. To maintain a consistent length regardless of frequency, the microcontroller will
repeat this frequency a specific number of times based on each specific note (more for higher
notes and less for lower notes). In this case, the waveform above will be repeated 288 times to
equal a total duration of 490,464 µS. More or less the half second we want for a half note.
Frequency
Period
523.25 Hz
1911 µS
554.37 Hz
1804 µS
587.33 Hz
1703 µS
622.25 Hz
1607 µS
659.25 Hz
1517 µS
698.46 Hz
1432 µS
739.99 Hz
1351 µS
783.99 Hz
1276 µS
830.61 Hz
1204 µS
880.00 Hz
1136 µS
932.33 Hz
1073 µS
987.77 Hz
1012 µS
th
through whole notes) and transfers these values to a subroutine that
= 440 Hz). The following chart illustrates the
4
Note
C6
#
C
6
D6
#
D
6
E6
F6
#
F
6
G6
A
6
b
A6
B
6
b
B6
852; Length = half note = 8 x 36
Frequency
1046.50 Hz
956 µS
1108.73 Hz
902 µS
1174.66 Hz
851 µS
1244.51 Hz
804 µS
1318.51 Hz
758 µS
1396.91 Hz
716 µS
1479.98 Hz
676 µS
1567.98 Hz
638 µS
1661.22 Hz
602 µS
1760.00 Hz
568 µS
1864.66 Hz
536 µS
1975.53 Hz
506 µS
288
Period