@@ -168,7 +168,11 @@ static uint8_t mozzi_TCCR4A, mozzi_TCCR4B, mozzi_TCCR4C, mozzi_TCCR4D,
168168static void startAudio () {
169169 backupPreMozziTimer1 ();
170170 Timer1.initializeCPUCycles (
171- F_CPU / AUDIO_RATE,
171+ (F_CPU/AUDIO_RATE)-1 , // the -1 here is a result of empirical tests
172+ // that showed that it brings the resulting frequency
173+ // closer to what is expected.
174+ // see: https://github.com/sensorium/Mozzi/pull/202
175+
172176 PHASE_FREQ_CORRECT); // set period, phase and frequency correct
173177 TIMSK1 = _BV (TOIE1); // Overflow Interrupt Enable (when not using
174178 // Timer1.attachInterrupt())
@@ -198,10 +202,16 @@ static void startAudio() {
198202 // pinMode(AUDIO_CHANNEL_2_PIN, OUTPUT); // set pin to output for audio
199203# if (AUDIO_MODE == STANDARD)
200204 Timer1.initializeCPUCycles (
201- F_CPU / AUDIO_RATE,
205+ (F_CPU/AUDIO_RATE)-1 ,// the -1 here is a result of empirical tests
206+ // that showed that it brings the resulting frequency
207+ // closer to what is expected.
208+ // see: https://github.com/sensorium/Mozzi/pull/202
202209 PHASE_FREQ_CORRECT); // set period, phase and frequency correct
203210# else // (AUDIO_MODE == STANDARD_PLUS)
204- Timer1.initializeCPUCycles (F_CPU / PWM_RATE,
211+ Timer1.initializeCPUCycles ((F_CPU/PWM_RATE)-1 , // the -1 here is a result of empirical tests
212+ // that showed that it brings the resulting frequency
213+ // closer to what is expected.
214+ // see: https://github.com/sensorium/Mozzi/pull/202
205215 FAST); // fast mode enables higher PWM rate
206216# endif
207217 Timer1.pwm (AUDIO_CHANNEL_1_PIN,
@@ -267,7 +277,7 @@ static void startAudio() {
267277 pinMode (AUDIO_CHANNEL_1_lowByte_PIN,
268278 OUTPUT); // set pin to output for audio, use 499k resistor
269279 Timer1.initializeCPUCycles (
270- F_CPU / 125000 ,
280+ F_CPU/ 125000 ,
271281 FAST); // set period for 125000 Hz fast pwm carrier frequency = 14 bits
272282 Timer1.pwm (AUDIO_CHANNEL_1_highByte_PIN,
273283 0 ); // pwm pin, 0% duty cycle, ie. 0 signal
0 commit comments