AtMega8 CTC Interrupt nur einmal?

OP #1225880
Lesenswert?

Hallo,

bin gerade dabei das ich eine Uhr aufbauen will mit nen Atmega8 (16MHz 
Quarz), mit dem Timer1 (mit CTC).

Ich hab jetzt mal diesen Code:
1
#include <util/delay.h>
2
#include <avr/io.h>
3
#include <stdlib.h.>
4
#include <avr/interrupt.h>
5
#include <inttypes.h>
6
#include <stdio.h>
7
#include <avr/pgmspace.h>
8

9
volatile uint16_t Timer = 0;
10
volatile uint8_t Sek = 0;
11

12
ISR (TIMER1_COMPB_vect) {  
13
  if(Timer < 1000) {
14
    Timer++;
15
    PORTC ^= (1<<3);
16
  } else {
17
    Sek++;
18
    Timer = 0;
19
  }
20
}
21

22
int main (void) {
23
  uint8_t durch = 0;
24
  uint8_t Zehner = 0;
25
  uint8_t Einer = 0;
26

27

28
  DDRB = 0xFF;
29
  DDRD = 0xFF;
30
  DDRC = 0xFF;
31
  
32
  TCCR1B = ( 1 << WGM12 ) | ( 1 << CS10 );
33
  OCR1B = 16000 - 1;
34
  TIMSK = (1 << OCIE1B);
35
  sei();
36
  
37
  
38
  while(1) {
39
  }
40
  return 0;
41
}

auf dem Pin 3 auf Port C hab ich ein Relay hängen, das sich aber nie 
einschaltet!) Wenn ich jetzt die Zeile wo der Pin Toggeln soll, 
raufschiebe in dem Bereich wo hochgezählt wird, schaltet das Relay 
einmal um und fertig... Wenn ich jetzt mit dem Multimeter messe (die 
Frequenz) steht dort 0Hz...
Daraus folge ich das der Interrupt nur einmal ausgeführt wird...

Kann mir jemand sagen was da los ist?
Danke!

Lg Peter
OP #1226053
Lesenswert?

spess53 wrote:
> Hi
>
> Im Mode4 (WGM12=1) ist OCR1A Top, nicht OCR1B.
>
> MfG Spess

Hallo spess53,

hab grad im DB nochmal genau nachgelesen, da stehts nämlich e drinnen:
1
The OCR1A or ICR1 define the top value for the
2
counter, hence also its resolution.

Danke! Problem gelöst!

Lg Peter

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