Broken interrupt foo
This commit is contained in:
43
src/main.cpp
43
src/main.cpp
@@ -9,6 +9,19 @@ static uint8_t led_duration = 4;
|
||||
*/
|
||||
void configureTimer()
|
||||
{
|
||||
// Configure Timer 0 to generate periodic interrupts
|
||||
TCCR0A = 0;// set entire TCCR0A register to 0
|
||||
TCCR0B = 0;// same for TCCR0B
|
||||
TCNT0 = 0;//initialize counter value to 0
|
||||
// set compare match register for 2khz increments
|
||||
OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256)
|
||||
// turn on CTC mode
|
||||
TCCR0A |= (1 << WGM01);
|
||||
// Set CS01 and CS00 bits for 64 prescaler
|
||||
TCCR0B |= (1 << CS01) | (1 << CS00);
|
||||
// enable timer compare interrupt
|
||||
TIMSK0 |= (1 << OCIE0A);
|
||||
|
||||
// Configure Timer 1 for PWM @ 25 kHz.
|
||||
TCCR1A = 0; // undo the configuration done by...
|
||||
TCCR1B = 0; // ...the Arduino core library...
|
||||
@@ -64,25 +77,24 @@ void setup()
|
||||
// configure timer
|
||||
Serial.println("configure timer for 25kHz PWM...");
|
||||
configureTimer();
|
||||
|
||||
Serial.println("fan control setup done.");
|
||||
Serial.println("Enable interrupts...");
|
||||
sei();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint8_t tacho_last = 0;
|
||||
uint8_t tacho_counter = 0;
|
||||
uint32_t iterator = 0;
|
||||
uint32_t period = 0;
|
||||
uint16_t rotations = 0;
|
||||
static uint8_t tacho_last = 0;
|
||||
static uint8_t tacho_counter = 0;
|
||||
static uint32_t iterator = 0;
|
||||
static uint32_t period = 0;
|
||||
static uint16_t rotations = 0;
|
||||
|
||||
uint16_t led_a_period = (uint16_t)-1;
|
||||
uint16_t led_a_counter = led_a_period;
|
||||
static uint16_t led_a_period = (uint16_t)-1;
|
||||
static uint16_t led_a_counter = led_a_period;
|
||||
|
||||
uint16_t led_b_period = (uint16_t)-1;
|
||||
uint16_t led_b_counter = led_b_period;
|
||||
static uint16_t led_b_period = (uint16_t)-1;
|
||||
static uint16_t led_b_counter = led_b_period;
|
||||
|
||||
while (1) {
|
||||
ISR(TIMER0_COMPA_vect){
|
||||
iterator++;
|
||||
|
||||
uint8_t tacho_current = digitalRead(7);
|
||||
@@ -123,5 +135,8 @@ void loop()
|
||||
} else {
|
||||
digitalWrite(3, LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user