From b742ab3a288a1164b4ceb6e58ae42115d320d580 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 16 Sep 2014 15:31:53 +0200 Subject: Finally fix speaker Use one timer for LED/speaker. Not sure why two did not work. --- speaker.c | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 speaker.c (limited to 'speaker.c') diff --git a/speaker.c b/speaker.c deleted file mode 100644 index e96afcf..0000000 --- a/speaker.c +++ /dev/null @@ -1,55 +0,0 @@ -/* speaker control, uses timer2 - */ - -#include "common.h" - -#include -#include -#include -#include -#include - -#include "speaker.h" - -static volatile uint16_t count; - -/* Compare interrupt - */ -ISR(TIMER2_COMPA_vect) { - PORTD ^= (1 << PD6); - --count; - if (count == 0) { - speakerStop (); - } -} - -void speakerInit () { - /* set PD6 to output */ - DDRD |= (1 << PD6); - /* turn off */ - PORTD = PORTD & ~(1 << PD6); -} - -void speakerStart (const speakerMode mode) { - /* 12.8ms */ - count = 100; - - /* compare value (hit on every tick) */ - OCR2A = 1; - /* reset timer value */ - TCNT2 = 0; - /* set ctc mode */ - TCCR2A = (1 << WGM21); - /* enable overflow interrupt */ - TIMSK2 = (1 << OCIE2A); - /* io clock with 1024 prescaler -> ~4kHz tone, ctc part2 */ - TCCR2B = (1 << CS22) | (1 << CS21) | (1 << CS20); -} - -void speakerStop () { - /* zero clock source */ - TCCR2B &= ~(0x7); - /* turn off */ - PORTD = PORTD & ~(1 << PD6); -} - -- cgit v1.2.3