PWM Initialisierung

Gast #3922350
Lesenswert?

Hallo,

ich möchte mit einer PWM eines Atmega128 eine LED betreiben. Das 
funktioniert auch, nur bei der Initialisierung leuchtet die LED einmal 
kurz auf, was mich stört.

Das Problem ist hier schon beschreiben:
Beitrag "Problem mit PWM Initialisierung"

Bei mir ist das PWM Signal jedoch invertiert und ich bekomme es einfach 
nicht hin.

1
// Initialisierung IO
2
void init_io (void)
3
{
4
  PORTB |= (1<<PORTB5) | (1<<PORTB6) | (1<<PORTB7); //Alle LED's aus
5
  DDRB |= (1<<DDB5) | (1<<DDB6) | (1<<DDB7);  
6
}
7
void init_io (void)
8
{
9
  PORTB |= (1<<PORTB5) | (1<<PORTB6) | (1<<PORTB7); //Alle LED's aus
10
  DDRB |= (1<<DDB5) | (1<<DDB6) | (1<<DDB7);  
11
}
12

13

14
// Timer 1 Initialisierung 8-Bit PWM invertierend
15
void init_timer1 (void)
16
{
17
  OCR1A = 0;
18
  OCR1B = 0;
19
  OCR1C = 0;
20
  
21
  // PWM, Phase Correct 8-bit
22
  TCCR1A |= (1<<WGM10);
23
  
24
  /* Set OCnn on compare match when up-counting, 
25
clear OCnn on  compare match when downcounting */
26
  TCCR1A |= (1<<COM1A1) | (1<<COM1A0);
27
  TCCR1A |= (1<<COM1B1) | (1<<COM1B0);
28
  TCCR1A |= (1<<COM1C1) | (1<<COM1C0);
29
  
30
  // Prescaler F_CPU / 64
31
  TCCR1B |= (1<<CS11) | (1<<CS10);
32
  
33
  
34
}
(Firma: matzetronics) #3922931
Lesenswert?

test schrieb:
> void init_io (void)
> {
>   PORTB |= (1<<PORTB5) | (1<<PORTB6) | (1<<PORTB7); //Alle LED's aus
>   DDRB |= (1<<DDB5) | (1<<DDB6) | (1<<DDB7);
> }
> void init_io (void)
> {
>   PORTB |= (1<<PORTB5) | (1<<PORTB6) | (1<<PORTB7); //Alle LED's aus
>   DDRB |= (1<<DDB5) | (1<<DDB6) | (1<<DDB7);
> }

Ich sags zweimal und es ist wahr? :-)
Aber du kannst ganz einfach den Timer vorher initialisieren und erst 
dann die Pins als Ausgang konfigurieren. Dann sollte das klappen.

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