diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2014-08-26 15:46:56 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2014-08-26 16:27:26 +0200 |
commit | 0a9d079451c1ae4ba85f6735943734767140248d (patch) | |
tree | 1a3976ff5ad4b794662866da795f70854d46bcf5 | |
parent | 214ec8c9220c31c49c8e86bacd117fde54fea2aa (diff) | |
download | hourglass-0a9d079451c1ae4ba85f6735943734767140248d.tar.gz hourglass-0a9d079451c1ae4ba85f6735943734767140248d.tar.bz2 hourglass-0a9d079451c1ae4ba85f6735943734767140248d.zip |
speaker: Fix beep
Finally beeps. XXX: nope, it does not.
-rw-r--r-- | speaker.c | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -11,8 +11,16 @@ #include "speaker.h" -ISR(TIMER2_OVF_vect) { +static volatile uint16_t count; + +/* Compare interrupt + */ +ISR(TIMER2_COMPA_vect) { PORTD ^= (1 << PD6); + --count; + if (count == 0) { + speakerStop (); + } } void speakerInit () { @@ -23,21 +31,24 @@ void speakerInit () { } void speakerStart (const speakerMode mode) { + /* 12.8ms */ + count = 100; + + /* compare value (hit on every tick) */ + OCR2A = 1; /* reset timer value */ TCNT2 = 0; - /* set normal mode */ - TCCR2A = 0; + /* set ctc mode */ + TCCR2A = (1 << WGM21); /* enable overflow interrupt */ - TIMSK2 = (1 << TOIE2); - /* io clock with 1024 prescaler */ - TCCR2B = ((TCCR2B & ~(1 << CS21)) | (1 << CS22) | (1 << CS20)); - _delay_ms (50); - speakerStop (); + 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 = 0; + TCCR2B &= ~(0x7); /* turn off */ PORTD = PORTD & ~(1 << PD6); } |