Atmega328P Timer2 zu langsam

Gast #4629580
Lesenswert?

Grüße,
1
void setup() {
2
    DDRB = DDRB | B00000011; // Arduino 8&9 output
3
    TIMSK2 |= 0x01; // Overflow interrupt enable
4
    TCCR2B |= 0x01; // Start Timer, no prescaler
5
}
6

7
void loop() {
8
    // nix
9
}
10

11
ISR (TIMER2_OVF_vect) {
12
    PORTB ^= B00000010; // Toggle Pin
13
    if((PORTB & B00000010) > 0) TCNT2 = 0x80;
14
}

Das ist der vollständige Code, nix gekürzt. Wird via Arduino IDE auf 
einen Pro Mini @ 16 MHz geladen.
Erwartet hatte ich, dass der Pin 16µs LOW und 8µs HIGH ist. Tatsächlich 
ist er aber 4ms LOW und 3ms HIGH (ja, ms, nicht µs)...
Jemand eine Idee? Danke :)
Gast #4629629
Lesenswert?

1
void setup() {
2
    DDRB = DDRB | B00000011; // Arduino 8&9 output
3
    TIMSK2 |= 0x01; // Overflow interrupt enable
4
    TCCR2A = 0x00;
5
    TCCR2B = 0x01;
6
}
7

8
void loop() {
9
    // nix
10
}
11

12
ISR (TIMER2_OVF_vect) {
13
    PORTB ^= B00000010; // Toggle Pin
14
    if((PORTB & B00000010) > 0) TCNT2 = 0x80;
15
}

Okay, so geht es... Offensichtlich schreibt die Arduino Lib in der 
Timer2 Konfiguration herum. Dachte eigentlich die nutzt nur Timer0 (für 
delay...).
#4629630
Lesenswert?

dann lass doch mal das arduino zeugs weg.
1
void main() 
2
{
3
    DDRB = DDRB | B00000011; // Arduino 8&9 output
4
    TIMSK2 |= 0x01; // Overflow interrupt enable
5
    TCCR2B |= 0x01; // Start Timer, no prescaler
6

7
    sei();
8
}
9

10
ISR (TIMER2_OVF_vect) {
11
    PORTB ^= B00000010; // Toggle Pin
12
    if((PORTB & B00000010) > 0) TCNT2 = 0x80;
13
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren