Hey LeafLabs folks,
Thanks for a great product.
I may have found a bug in the code for the Timers.
The following code produces a nearly perfect square wave at 999.986KHz, well within the tolerance for the crystal.
pinMode(9,PWM);
Timer4.setPrescaleFactor(1);
Timer4.setOverflow(71);
pwmWrite(9,36);
The next piece of code, however, returns an Overflow value of 72 and produces a nearly square wave at 986.098KHz
pinMode(9,PWM);
int Overflow = Timer4.setPeriod(1);
pwmWrite(9,Overflow/2);
I have similar results using a period of 2 etc. The frequency is off by a proportion equal to the overflow value off by 1. Are you accounting for the timer count starting at zero?
Thanks for your help,
Carl