vendredi 27 mars 2015

AVR C++ will not compare numbers

I've been writing a small library for Arduino that essentially gives me control over timer 0 (yes I know the delay() function uses this timer). I started to notice an issue in the code though. The pre-scaler value is passed through the function when it is called along with a few other things: attachTimeInterrupt(int ttc, int prescaler, void (*f)()). In this function, I have a few if statements that determine if the pre-scaler is equal to a few values, being: 1, 8, 64, 256, 1024. Even if the pre-scaler value is set to one of these numbers, the if statement will still not trigger. The proper ISR for this function does, however trigger if a default pre-scaler is set. Here is my code for that function. Any help would be appreciated.



void TimerZero::attachTimeInterrupt(int ttc, int prescaler, void (*f)()){
DDRB = 0b11111111;

prescaler = 1; //Even if I set this right here, it will still not work.


if(prescaler == 1){
PORTB = 0b11111111; //This tests to see if it has been called
TCCR0B |= (1 << CS00) | (1 << WGM02);

}else if(prescaler == 8){

TCCR0B |= (1 << CS01) | (1 << WGM02);

}else if(prescaler == 64){

TCCR0B |= (1 << CS00) | (1 << CS01) | (1 << WGM02);

}else if(prescaler == 256){

TCCR0B |= (1 << CS02) | (1 << WGM02);

}else if(prescaler == 1024){

TCCR0B |= (1 << CS00) | (1 << CS02) | (1 << WGM02);

}else{
//Default prescaler
TCCR0B |= (1 << CS00) | (1 << CS02) | (1 << WGM02);
}

TIMSK0 |= (1 << OCIE0A);




ttc = 255;



OCR0A = 255;




sei();


}


Aucun commentaire:

Enregistrer un commentaire