The minimum number of cycles per half square wave that I need (working with a 14.7456 MHz oscillator) is 123, to obtain the 60 kHz that I want for maximum frequency. The maximum number of cycles is 377,303. That requires the use of a three-byte number. Since I'm trying to work with 2^11 divisions (2,048), the dividend requires the use of two bytes. The code I wrote, which is based on the long binary division algorithm, requires close to two thousand cycles to divide a three-byte number by a two-byte one. This is simply not practical.Frequency is the inverse of period, so I don't see a drastic change in programming complexity. One way to shortcut things is with a lookup table. It's only 65,000 entries to type in; how hard can it be?
ak
And as for a look up table, I have already considered that. Thing is that the total memory available in the device I'm trying to use is 4kB, and that is short of the 6kB needed for a three-byte look up table for this task. I cannot think of a way to make the table any smaller, other than compressing it to two bytes, and then adding the third byte as an exception in the algorithm for very low frequencies.
I am, however, working on a non-continuous function that looks promising, that might give me a close approximation the linear output frequency that I want.
