I have hooked up an AY-3-8910 sound chip to an Arduino Nano and I am trying to get it to give me a square wave at a frequency of 440Hz on channel A. The datasheet for the AY-3-8910 says that the frequency of the tone generator is obtained by first dividing the input clock (2 MHz in my case) by 16 and then dividing the result by the 12 bit tone period value, but I can't work out how to calculate the values for a desired freqeuncy to store in the coarse tune and fine tune registers. The 12 bit value is made up by combining the two 8 bit coarse tune and fine tune registers. Can anyone help? Thanks.
The formula is as described in the datasheet. The master clock is divided by 16, and divided by the tone period register value to get the tone frequency.
Thus, to calculate the tone period value from the frequency you want, 440 Hz is calculated as follows : (2 MHz / 16) / 440 Hz = 284 in decimal, or 0x011C in hex.
The tone period register is 12-bit so it is divided into high 4 bit part and low 8-bit part. Thus the two register values are 0x01 for the high register and 0x1C for the low register.