440

 

440.0 Hz Standard Music Tone Generatior

 

 

Figure 1 is a simple but very accurate circuit that generates the 440.0 Hz standard music tone. It can act like a "tuning fork" for musical instruments. For example, you can use it to check whether your piano has been out of tune. If your piano is fine tuned, its A4 key must sound the same tone as this one.

 

Figure 1. 440 Hz Music Tone generator

 

 

To get exact 440.0 Hz tone, both hardware and software must be fine-tuned. Because ATtiny11's built-in RC oscillator is not accurately 1 MHz, we replace it with the 1 MHz crystal oscillator as shown. The speaker needs to have good response to audible frequencies, we choose a 2.5" 100 Ohm speaker.

 

Since the factory has pre-programmed the ATtiny11's "Fuse bits" and made it shipped with built-in RC oscillator, we need to re-program its "Fuse bits" in order to use external oscillator.

 

This "Fuse bits" programming facility is not included in AVRHVP-1 programmer since there is no more flash memory to accommodate this. For this reason another special programmer AVRHVP-2 has been developed, which handles only "Fuse bits" programming and writing "Lock bits" (to hide the binary code on chip) functions.

 

Listing 1 is the software. To generate the accurate 440 Hz frequency tone, an infinite loop of 1136 us (microsecond) High and Low voltage is alternately applied to the speaker, here 1136 us is the half period (T/2) corresponding to 440 Hz.

 

The key routine here is DL1132us delay routine, but every other instruction counts. For example, setting up PB1=High or Low takes 2 us each, calling DL1132 also takes 2 us. Adding them up gives exact 1136 us.

 

With such meticulous calculation, the circuit output tone is exactly 440.0 Hz when measured by frequency meter. As a comparison, if you don't re-program the Fuse bits but use the original factory built-in RC oscillator, the frequency meter will show quite different readings, such as 495.7 Hz and with the last two digits changing.

 

 

 

 

 

LISTING 1. The Standard 440 Hz Music Tone Generation program

 

;ATonTn11.ASM: 440 Hz Standard Music A tone generator

.include "TN11def.inc" ; Port definitions here

.cseg

.org 0

sbi DDRB, 1 ; config DDRB bit-1 as output

sbi DDRB, 0 ; config DDRB bit-0 as output

 

cbi PORTB, 0 ; LED=ON

 

AGAIN:

cbi PORTB, 1 ; PB1=LOW; 2us

rcall DL1132us ;

NOP ; 1us

NOP ; 1us

; 1136

; ------ --

sbi PORTB, 1 ; PB1=High | | |

rcall DL1132us ; ___| |______|

; 1136

rjmp AGAIN ; 2us

;--------------------------------------------------------------

;delay 1132us at 1 MHz

 

DL1132us:

LDI R20, 0 ; 1us

LOOP1:

DEC R20 ; 1us \ 3*256 = 768 us

brne LOOP1 ; 2us /

 

LDI R21, 119 ; 1us

LOOP2:

DEC R21 ; 1us \ 3*119 = 357 us

brne LOOP2 ; 2us /

 

RET ; 4us

;---------------------------------------------------------

;rcall is 3us; Total delay = 1132 us