Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions MozziGuts_impl_AVR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ static uint8_t mozzi_TCCR4A, mozzi_TCCR4B, mozzi_TCCR4C, mozzi_TCCR4D,
static void startAudio() {
backupPreMozziTimer1();
Timer1.initializeCPUCycles(
F_CPU / AUDIO_RATE,
(F_CPU/AUDIO_RATE)-1, // the -1 here is a result of empirical tests
// that showed that it brings the resulting frequency
// closer to what is expected.
// see: https://github.com/sensorium/Mozzi/pull/202

PHASE_FREQ_CORRECT); // set period, phase and frequency correct
TIMSK1 = _BV(TOIE1); // Overflow Interrupt Enable (when not using
// Timer1.attachInterrupt())
Expand Down Expand Up @@ -198,10 +202,16 @@ static void startAudio() {
// pinMode(AUDIO_CHANNEL_2_PIN, OUTPUT); // set pin to output for audio
# if (AUDIO_MODE == STANDARD)
Timer1.initializeCPUCycles(
F_CPU / AUDIO_RATE,
(F_CPU/AUDIO_RATE)-1,// the -1 here is a result of empirical tests
// that showed that it brings the resulting frequency
// closer to what is expected.
// see: https://github.com/sensorium/Mozzi/pull/202
PHASE_FREQ_CORRECT); // set period, phase and frequency correct
# else // (AUDIO_MODE == STANDARD_PLUS)
Timer1.initializeCPUCycles(F_CPU / PWM_RATE,
Timer1.initializeCPUCycles((F_CPU/PWM_RATE)-1, // the -1 here is a result of empirical tests
// that showed that it brings the resulting frequency
// closer to what is expected.
// see: https://github.com/sensorium/Mozzi/pull/202
FAST); // fast mode enables higher PWM rate
# endif
Timer1.pwm(AUDIO_CHANNEL_1_PIN,
Expand Down Expand Up @@ -267,7 +277,7 @@ static void startAudio() {
pinMode(AUDIO_CHANNEL_1_lowByte_PIN,
OUTPUT); // set pin to output for audio, use 499k resistor
Timer1.initializeCPUCycles(
F_CPU / 125000,
F_CPU/125000,
FAST); // set period for 125000 Hz fast pwm carrier frequency = 14 bits
Timer1.pwm(AUDIO_CHANNEL_1_highByte_PIN,
0); // pwm pin, 0% duty cycle, ie. 0 signal
Expand Down