Wiki-KopieMirror

Dies ist ein Mirror des Wikis von pascal.chat. Bearbeiten, Verlauf und Anmeldung finden dort statt.

AVR Embedded Tutorial - Analog Write/de

Deutsch · English

PWM Analog Write

Titel

In diesem Beispiele wird ein Atmega328 verwendet.

Sleep

Eine einfache Pausenfunktion, das die LEDs langsam hell und dunkel werden.

pascal
  procedure sleep;
  var
    i: Int16;
  begin
    for i := 0 to 1999 do asm Nop END;
  end;

Beispiel

In diesem Beispiel wird die PWM Frequenz sehr langsam eingestellt, so das man ein Flackern der LEDs wahr nimmt. So sieht man gut, das ein analoger Ausgang in Wirklichkeit moduliert ist. Folgendes muss eingestellt werden:

pascal
var
  i: integer; // Schleifenzähler
begin
  // PD5 und PD6 auf Ausgang
  DDRD := %01100000;

  // PD5 und PD6 als PWM
  TCCR0A := (%10 shl COM0A) or (%10 shl COM0B) or (1 shl WGM0);

  // Timer 0 aktivieren, Clock / 1024
  TCCR0B := TCCR0B or %101;

  // Hauptschleife, welche die LEDs kontinuierlich heller und dunkler macht.
  repeat
    for i := 0 to 255 do begin
      OCR0A := i;
      OCR0B := 255 - i;
      sleep;
    end;
    for i := 0 to 255 do begin
      OCR0A := 255 - i;
      OCR0B := i;
      sleep;
    end;
  until False;
end.

Stolperfalle

Note: Da PWM mittels Timer gesteuert ist, kann es Überschneidungen mit den Timerfunktionen geben.

Für Timerfunktionen siehe hier:

Siehe auch

Autor: Mathias


From the Free Pascal wiki, page "AVR Embedded Tutorial - Analog Write/de", as it stood on 2020-10-19 after a change by Mathias, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Version 1, zuletzt geändert von WikiArchive .