aboutsummaryrefslogtreecommitdiff
path: root/pwm.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2014-07-22 15:58:55 +0200
committerLars-Dominik Braun <lars@6xq.net>2014-07-22 15:59:09 +0200
commitbedbcdc4de680720deff4b6e113a3ec1a0690482 (patch)
tree448003d0a8d8a356c956baa427bc3c35f620d314 /pwm.c
parent42e32ed74655e98e9f2d5a0152a047dcf9e72806 (diff)
downloadhourglass-bedbcdc4de680720deff4b6e113a3ec1a0690482.tar.gz
hourglass-bedbcdc4de680720deff4b6e113a3ec1a0690482.tar.bz2
hourglass-bedbcdc4de680720deff4b6e113a3ec1a0690482.zip
Speaker and LED pwm
Something is not correct here, stack overflow?
Diffstat (limited to 'pwm.c')
-rw-r--r--pwm.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/pwm.c b/pwm.c
index c38a162..669d9c3 100644
--- a/pwm.c
+++ b/pwm.c
@@ -1,6 +1,8 @@
/* LED pwm, uses timer0
*/
+#include "common.h"
+
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdbool.h>
@@ -18,6 +20,11 @@ static uint8_t state = 0;
static uint8_t val[2];
static uint8_t init[2];
+static void ledOff () {
+ PORTB = PORTB & ~((1 << PB6) | (1 << PB7));
+ PORTD = PORTD & ~((1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5));
+}
+
static uint8_t ledToArray (const uint8_t i) {
assert (i < PWM_LED_COUNT);
if (i >= 2) {
@@ -59,10 +66,7 @@ ISR(TIMER0_COMPA_vect) {
}
if (comphit % 2 == 0) {
- /* switch off: we can’t just set to 0 here, since PB6 is used by
- * speaker */
- PORTB = PORTB & ~((1 << PB6) | (1 << PB7));
- PORTD = PORTD & ~((1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5));
+ ledOff ();
} else {
PORTB |= val[0];
PORTD |= val[1];
@@ -77,6 +81,8 @@ void pwmInit () {
}
void pwmStart () {
+ comphit = 0;
+ state = 0;
/* reset timer value */
TCNT0 = 0;
/* set ctc timer0 (part 1) */
@@ -92,6 +98,7 @@ void pwmStart () {
void pwmStop () {
/* zero clock source */
TCCR0B = 0;
+ ledOff ();
}
void pwmSetBlink (const uint8_t i, const uint8_t value) {