Adjusted sample CTC timer calculations in the AudioOutput and AudioInput demos to account for situations where the division results in a value with no remainder, requiring one to be subtracted from the result (thanks to Robin Theunis).

This commit is contained in:
Dean Camera 2009-04-14 08:17:24 +00:00
parent af02b5b0c9
commit fea5d08512
3 changed files with 4 additions and 2 deletions

View file

@ -90,7 +90,7 @@ EVENT_HANDLER(USB_Connect)
UpdateStatus(Status_USBEnumerating);
/* Sample reload timer initialization */
OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY);
OCR0A = (F_CPU / AUDIO_SAMPLE_FREQUENCY) - ((F_CPU % AUDIO_SAMPLE_FREQUENCY) == 0 ? 1 : 0);
TCCR0A = (1 << WGM01); // CTC mode
TCCR0B = (1 << CS00); // Fcpu speed