Forum: Mikrocontroller und Digitale Elektronik PWM wird nie 0


von Hans (Gast)


Lesenswert?

Hallo!

Ich habe eine Frage, und zwar bei diesem Einfachen Programm wird die PWM 
nie 0, also ich habe immer ca. 200ns on-time

weiß jemand wieso?
Takt ist ein 4Mhz
1
#include <avr/io.h>
2
int main()
3
{
4
  
5
  DDRB = (1 << PB1 ); //OCR1A Ausgangspin Port B1
6
   
7
  TCCR1A = (1<<COM1A1) | (1<<WGM11); //Nicht Invertierende PWM
8
  TCCR1B = (1<<WGM13) | (1<<WGM12) | (1<<CS10); //Vorteiler 1 10-Bit Fast PWM
9
  ICR1 = 20000;
10
  while( 1 )
11
  {
12
    OCR1A = 0;
13
  }
14
}

danke
Lg Hans

von Julian O. (jaytech)


Lesenswert?

Hallo Hans,

Das Problem hatte ich auch schon. Liegt am "Fast PWM" Modus. Probiers 
mal mit "PWM, Phase Correct".

Die Bits für "PWM, Phase Correct" sehen z.b. beim Atmega644 wie folgt 
aus:

TCCR1A = (1<<WGM11) | (1<<WGM10)
TCCR1B = (1<<WGM13)

lg Julian

von avr (Gast)


Lesenswert?

Das liegt an der Zählweise bei Fast-PWM:
1
The extreme values for the OCR1x Register represents special cases when generating a PWM
2
waveform output in the fast PWM mode. If the OCR1x is set equal to BOTTOM (0x0000) the output
3
will be a narrow spike for each TOP+1 timer clock cycle. Setting the OCR1x equal to TOP
4
will result in a constant high or low output (depending on the polarity of the output set by the
5
COM1x1:0 bits.)

Es geht nur "dauer high" oder bei invertierung "dauer low" mit
dem Spike am anderen Ende.

avr

von Hans (Gast)


Lesenswert?

Danke Leute !!!!!
Problem gelöst :)

Besten dank !

Lg
Hans

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.