ATMega 8 16Bit-Timer CTC-Mode Interrupts

Gast #1157141
Lesenswert?

Ich versuche mich gerade an einer eigenen Software-PWM, komme aber nicht 
weiter, da "Timer/Counter1 Compare Match B interrupt" nicht 
funktioniert.
Kann jemand einen Tipp diesbezüglich geben ?
1
#include <avr/io.h>
2
#include <inttypes.h>
3
#include <avr/interrupt.h>
4

5
void init_timer_1(void);
6

7
int main(void)
8
{
9
  sei();        // global Interupt enable
10
  init_timer_1();
11

12
  DDRC=255;
13
  
14
  while(1)
15
  {
16
  }
17
}
18

19
void init_timer_1(void)
20
{
21
  TCCR1B |= (1<<WGM12);  // CTC-Mode, Top-Value OCR1A
22
  TCCR1B |= (1<<CS10);  // no Prescaler
23

24
  OCR1AL = 255;
25
  OCR1AH = 15;      // 12 Bit resoluttion (Top Value of CTC Mode: 4095)
26

27
  TIMSK |= (1<<OCIE1A);  // Output Compare A Match Interrupt Enable, OCR1A (TOP VALUE OF TIMER)
28
  TIMSK |= (1<<OCIE1B);  // Output Compare B Match Interrupt Enable, OCR1B
29

30
  OCR1BL = 0;
31
  OCR1BH = 1;
32

33
}
34

35
ISR (TIMER1_COMPA_vect)    // Timer/Counter1 Compare Match A interrupt
36
{
37
  PORTC=1;
38
}
39

40
ISR (TIMER1_COMPB_vect)    // Timer/Counter1 Compare Match B interrupt
41
{
42
  PORTC=0;  
43
}
#1157184
Lesenswert?

1
  OCR1AL = 255;
2
  OCR1AH = 15;      // 12 Bit resoluttion (Top Value of CTC Mode: 4095)
3
...
4
  OCR1BL = 0;
5
  OCR1BH = 1;
Es muss zuerst das High-Byte geschrieben werden, dann das Low-Byte. 
Warum überlässt du es nicht dem Compiler, die beiden Bytes in der 
richtigen Reihenfolge zu schreiben?
1
OCR1A = 4095;
2
OCR1B = 256;

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