Slow LFO Timer Interrupt (help needed please)

Hi,

I am trying to create a slow LFO (0.05Hz to 5Hz would suffice), control would be via a potentiometer input to control the rate, nothing too fancy.

I have been basing my work on an example found online @ Arduino: LFO Generator – notes to self

This example uses timer intterupts and a sine table to derive a few wave shapes.

I have been slowing trying to grasp the timers and I'm kind of getting there.

I have altered timer0 prescaler to reduce speed slightly but more is needed: code snippet:

//---Timer 0 original ----///
cbi(TCCR0B,CS00);
cbi(TCCR0B,CS01);
sbi(TCCR0B,CS02);
//----End----------------//

//---Timer 0 my edit, 1024 ----//
sbi(TCCR0B,CS00); //1
cbi(TCCR0B,CS01); //0
sbi(TCCR0B,CS02); //1
//---End------------------------//

Can someone with more knowledge than me tell me how I could potentially change this code overall to decrease the speed further? I understand I could use delay(); generally speaking but I'm under the impression these timers and interrupt routines will be more stable over time?

Thank you and regards,

LFO_Example.ino (3.2 KB)

The timer interrupts give you a base time resolution, but you don't have to do something on every interrupt.

If you wrap everything inside the ISR with the following it will slow by 'divider' again

if (j = 0)
{
// wave update
}
j++;
if (j >= divider) j = 0;

Yes I see what you mean, I will give that a shot this evening, thank you

As an alternative, you might want to consider the direct digital synthesis technique described here:http://interface.khm.de/index.php/lab/interfaces-advanced/arduino-dds-sinewave-generator/It establishes a 32-bit phase accumulator, calculates how much to advance the phase accumulator with each timer rollover, and uses the upper bits of the phase accumulator as an index into the sine array. For the other waveforms, you can calculate the output pretty much the same way as in the referenced program. You might need to exercise some ingenuity to calculate the triangle wave.

Hi, I was looking at that DDS example and in some respects they seem similar. It seems the timing would be easier to manage though now you bring it to my attention again.

Actually the custom waveshape elements I have figured out and creating the tables is easy. I wrote a custom program so I can draw my own standard and more esoteric waveshapes and it can spit out the wavetables in any format I desire (MaxMsp)

I will certainly explore it further, my skills in max /puredataare pretty well developed but my lower level skills in C are in need of development.

Also looking at the teensy audio library, it's certainly amazing but not well documented and has its own set of unique challenges to face, not least getting my head wrapped around arrays of arrays and managing pointer (no idea as yet).

On a side note what exactly are the negative impacts of using delay() or delayMicrosec in an application like this, I have read that timers are more efficient but since these are LFOs and precise pitch accuracy is not too important, am I potentially making more work for myself than necessary? Down the road it will need to read inputs map ranges monitor button presses (hence why I think the timers and interrupts become important)

Thanks for the help this far gents, I'll hopefully make some progress tonight