Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

parameterize boot_timer with frequency

  • Loading branch information...
commit 0ddb2c8dedcb93c5edb8e0fdcc033d6362697525 1 parent 1549513
@beerriot authored
Showing with 7 additions and 6 deletions.
  1. +1 −3 blockgame.c
  2. +2 −0  include/timer.h
  3. +4 −3 src/timer.c
View
4 blockgame.c
@@ -3,8 +3,6 @@
// copyright 2011 Bryan Fink
// license: see LICENSE.txt
-#define F_CPU 14745600
-
#include <stdlib.h>
#include <inttypes.h>
@@ -637,7 +635,7 @@ int main() {
boot_lcd();
boot_pins();
- boot_timer();
+ boot_timer(60);
boot_adc();
srand(random_seed_from_ADC());
validate_highscores();
View
2  include/timer.h
@@ -1,6 +1,8 @@
#ifndef __TIMER_H__
#define __TIMER_H__
+#define F_CPU 14745600
+
void boot_timer();
uint8_t animate();
void simple_delay(int clicks);
View
7 src/timer.c
@@ -21,18 +21,19 @@ ISR(TIMER0_COMPA_vect) {
}
// configure the animation timer at boot
-void boot_timer() {
+void boot_timer(int freq) {
// Clear Timer on Compare Match of OCRA
TCCR0A |= (1<<WGM01);
// system clock is ~1.47Mhz
// 14740000/1024 = 14395
- // 14395/60 = 240 (60Hz being target frame rate)
// choose clock source as system/prescaler1024
TCCR0B |= (1<<CS02) | (1<<CS00);
+ // for example, 60Hz target:
+ // 14395/60 = 240
// choose the value for Output Compare A
- OCR0A = 240;
+ OCR0A = (F_CPU / 1024) / freq;
// endable Timer Output Compare Match A Interrupt 0
TIMSK0 |= (1<<OCIE0A);

0 comments on commit 0ddb2c8

Please sign in to comment.
Something went wrong with that request. Please try again.