Variable Pitch Beeper |
|
|
ATtiny45 --v-- rst pb5 -| |- vcc pi pb3 -| |- pb2 sck keyin po pb4 -| |- pb1 miso tone1 gnd -| |- pb0 mosi tone0 ----- 8Mhzhttp:files/DownloadParts/sidetone.asm Uses BynaseDriver Simple software io is not fast enough to make pure tones that vary smoothly so we press the timer/counter into service. This program generates an audio tone by toggling oc1a at a frequency determined by pi. The tone is keyed by keyin which is active low. ATtiny45 --v-- rst pb5 -| |- vcc pi pb3 -| |- pb2 sck keyin -- /| po pb4 -| |- pb1 miso oc1a ---||< | gnd -| |- pb0 mosi -- \| ----- 8Mhzhttp:files/DownloadParts/tone.asm Here is code that computes compare-register values to play musical notes. Change $n=12 to, say, 256, and you get close to continuous variation. perl -e '$n = 12; for $i (0..$n) { $p = 2.0**($i/$n); $f = 440*$p; $t = int(256/$p+.5); $g = 8e6/((2**6)*$t); $e = 100*($g-$f)/$f; print "$i\t$f\t$t\t$g\t$e\n"}'
|
Last edited March 9, 2008 Return to WelcomeVisitors |