A Top Octave Generator ====================== A Top Octave Generator is an IC used in early electronic keyboards. It generates 12 square waves approximating the 12 notes in an octave. The frequency was high (in audio terms) so that each note could be input to a divider IC to create all the lower notes. This project emulates a Top Octave Generator using an ATmega328P microprocessor with a 16MHz instruction clock. It is not an exact emulation, and might be considered an improvement. The original ICs required unusual input frequencies then divided that frequency by an integer, a different integer for each note. The project generates square waves with the length of the on/off periods varied in increments of 500ns. Because the note periods are not exact multiples of 500ns, an algorithm increases some periods by 500ns to bring the average closer to the true note. The highest note generated is C9 (8,372Hz) with the periods varying between 119 and 120 500ns periods. This technique produces notes that are closer (within 0.1Hz) of the desired note. Two versions are in this directory, emulating two TOG ICs. MK50242.asm covers the octave C#8 (4,434.92 Hz) to C9 (8,372.02 Hz). AY10212.asm covers the octave A7 (3520 Hz) to G#8 (6,644.88 Hz). The file notecalc.txt has the calculated well tempered note frequencies (derived from an A of 440Hz), the length in 500ns of the note period, a dither value used to calculate when to extend the period by an extra 500ns, and the frequency of the resultant note (which is close to, but not exactly, the well tempered frequency). To produce a program for the ATmega328P, it is only necessary to compile and upload the appropriate .asm file. It is a standalone program and requires no additional files. The chain used for testing was Microchip Studio 7 (a rebadged ATmel Studio) to produce the .hex file, uploaded using avrdude 7. 20 Jan 2024