Timerwerte für Noten-Seite auf Deutsch
Timerwerte für Noten-Seite auf Deutsch

Timer Values for musical Notes

This page requires Javascript!
Either you have javascript disabled or your browser does not support it.
This page can not work with your current settings.

You have a beeper in your project? Why should it only say beep, beep, let it play a melody! Here you can calculate the divider values for your timer to produce tones that represent musical notes.

But be careful: be aware of the copyright on the melodies, at least if you are not just planning a private project! The Big Ben hourly chime or Für Elise are probably unproblematic, but current charts usually are not.

Oscillator frequency
MHz
Lowest tone
Hz
Number of octaves

Timer width is

Prescaler is

Prescaler
Bit
Maximum

The prescaler is present in many controllers and it may also be necessary for higher clock frequencies. It can usually only be a power of two (e.g. 64, but not 65). If it is not available or you do not need it, leave the setting at 1.

Have a look at Wikipedia if you wish a different frequency.

In the Firmware of my Levelmeter you can find an example of how to do this on an AVR microcontroller with a minimum of overhead in an interrupt routine.


Prescaler Divider fnom fact Error [‰] Error [cent]

I have chosen the lowest tone here as pitched A (primed A) at 440 Hz. If you need lower tones, simply use the half (one octave lower) or the quarter (two octaves lower). Of course you can also enter the crooked frequency for the middle C of 261.626 Hz...

Divider values that cannot be implemented with the selected timer size are highlighted in yellow. If your timer has 32 bits this will normally not happen, otherwise you have to increase the prescaler value. By combining the prescaler and the timer, music is in principle possible even with an 8 bit timer, even if an experienced ear could detect detuning (errors of more than around 3 cents). Tones with more than 3 cent deviation are highlighted turquoise.

For your Sourcecode

The code for both arrays is also specific to AVR. With other types (or other languages than C) you may have to adapt it.

// One Line per Octave

// Have fun!

If you have chosen the prescaler to be constant or all values of prescaler[] are the same, you can of course save this array and only set the prescaler once.

The prescaler array contains the bit number if you have chosen the prescaler as a power of two, otherwise the divider factor. This is helpful for the further necessary code.