I'm trying to write code for a an LFO with target freq. range of 0.5Hz to 20Hz, the actual output is made by an external DAC to an AVR. To generate the output I use a phase accumulator which is just a 32bit variable to which I add various "adders" (values) at a fixed interval. The top 8 bits are used as index to a LUT containing the waveforms. The adder values are stored inside an array.

Normally I would like to use the potentiometer to set the freq. so because the ADC resolution is 10 bits I made the array with the adders 1024 long and I simply use the converted value as index. So far all good...

I measure the time between 2 button presses inside an interrupt routine which fires every 1ms. This way I can calculate the time between the two presses and I get the reading in ms. My problem is that I don't know how to convert the ms reading to the correct index required to add the right value to the phase accumulator. Any thoughts on this?

The way I dealt with it was to avoid doing a lookup for tapped tempos. Unfortunately this means you need to do a division instead. The freq_inc (what you call the "adder"), the frequency, and the sample rate are related by the following:

freq_increment = 2^32 * freq / sample_rate

We can replace "freq" with "1/period" since it's the same thing:

freq_increment = 2^32 / (sample_rate * period)

Since 2^32 / sample_rate is a constant we can reduce that a bit:

constant = 2^32 / sample_rate

freq_increment = constant / period

The final result of all this is that you work out the constant for your LFO, then you measure the period and divide one by the other. It works, but like I said, the division is a pain.

Alternatively, if the frequencies in your table of adders are linear (like Slacker said - I'm following him around today!) then you ought to be able to multiply the tap tempo timer count by some multiplier and use that for a lookup index. The value of the multiplier would depend on the count units (milliseconds or whatever). Bonus points if you can arrange things so that the multiplier finishes up binary-friendly and can be done with shifts.

HTH,

Tom