Adjusted sample CTC timer calculations in the AudioOutput and AudioInput demos to...
[pub/USBasp.git] / Demos / Device / AudioInput / AudioInput.c
index f41306f..b0c0295 100644 (file)
@@ -95,7 +95,7 @@ EVENT_HANDLER(USB_Connect)
        UpdateStatus(Status_USBEnumerating);\r
 \r
        /* Sample reload timer initialization */\r
-       OCR0A   = (F_CPU / AUDIO_SAMPLE_FREQUENCY);\r
+       OCR0A   = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - ((F_CPU % AUDIO_SAMPLE_FREQUENCY) == 0 ? 1 : 0);\r
        TCCR0A  = (1 << WGM01);  // CTC mode\r
        TCCR0B  = (1 << CS00);   // Fcpu speed\r
 }\r