Chapter 8: C Pointers and Arrays
/ 2 = 1911
imer1 to generate a phase/frequency
We then compensate for our
sing a left bit shift of one
eft shifting a byte or integer doubles
is less than half the possible
lue, 256/2 for a byte.)
ew tones from the sound.h table:
// tone 2
time we play the tone. The Timer0 calls
at 10ms intervals. It begins by getting the tempo from the
ay and putting it into a Tempo variable. The next time
d, if Tempo is not 0, it decrements the tempo and exits. It
the Tempo is 0, when it rereads the tempo and starts
Tone = 220*2^(NOTE/12)
When NOTE = C0 we get:
Tone = 220*2^(3/12) = 261.6256.
We get the frequency to generate for the tone with:
Timer value = 1Mhz / Tone / 2
For the C0 we would have:
Timer value = 1000000 / 261,6256...
So when we want to generate a C0 we set T
correct PWM with a top value calculated as above.
using a 2Mhz cpu clock by doubling the value u
position. (In case you didn’t get this earlier, l
it if there is headroom. Headroom means the value
va
A f
#define a 2273 // tone 0
#define xa 2145 // tone 1
#define ax 2145 // tone 1
#define b 2024
#define c0 1911 // tone 3
Setting the tempo
The tempo, in this case, is the length of
the Play_Tune function
first position of the arr
Play_Tune is calle
continues to do this until
over.