Recent

Author Topic: PWM signals, atmega328p, but then on PD3 --> PIN5  (Read 355 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 292
PWM signals, atmega328p, but then on PD3 --> PIN5
« on: April 14, 2026, 12:43:28 pm »
Back to the system:


https://wiki.freepascal.org/AVR_Embedded_Tutorial_-_Analog_Write


Code: Pascal  [Select][+][-]
  1.   var
  2.    i : integer;  // Loop counter
  3.  begin
  4.    // Configure PD5 and PD6 as outputs
  5.    DDRD := %01100000;
  6.  
  7.    // Configure PD5 and PD6 in PWM mode
  8.    TCCR0A := (%10 shl COM0A) or (%10 shl COM0B) or (1 shl WGM0);
  9.  
  10.    // Enable timer 0, clock / 1024
  11.    TCCR0B := TCCR0B or %101;
  12.  
  13.     OCR0A := 100;
  14.     OCR0B := 100;
  15.  

Can somebody help me out changing this for the Atmega328p controller, for PD3 --> PIN5

that would be a great help, Wouter van Wegen, PascalByThree

ccrause

  • Hero Member
  • *****
  • Posts: 1117
Re: PWM signals, atmega328p, but then on PD3 --> PIN5
« Reply #1 on: April 14, 2026, 07:26:20 pm »
Can somebody help me out changing this for the Atmega328p controller, for PD3 --> PIN5

I assume you are referring to IO pin D3? That is controlled by timer 2 channel B.
Untested code adapted from the wiki example:
Code: Pascal  [Select][+][-]
  1.    // Configure PD3 as output and preserve state of other pins
  2.    DDRD := DDRB or  %00001000;
  3.  
  4.    // Configure PD3 PWM mode
  5.    TCCR2A := (%10 shl COM0B) or (1 shl WGM0);
  6.  
  7.    // Enable timer 0, clock / 1024
  8.    TCCR2B := TCCR2B or %101;
  9.     OCR2B := 100;
  10.  

In the attached picture you can see that output compare of timer two, channel B (OC2B) is routed to PD3.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 292
Re: PWM signals, atmega328p, but then on PD3 --> PIN5
« Reply #2 on: April 15, 2026, 12:39:25 pm »
i greatly thank, you it got to work !  8-)

 

TinyPortal © 2005-2018