Different Port Speeds

Hi guys,

i am new to the forum and i've got a question.
I've got an Arduino Mega

This is my code:

void setup() {
  DDRF = B00000001;

PORTF = B00000001;
PORTF = B00000000;

void loop() {
}

This gives me a pulsewidth of around 62ns.

void setup() {
  DDRK = B00000001;

PORTK = B00000001;
PORTK = B00000000;

void loop() {
}

And this gives me a pulsewidth of around 125ns.

Can somebody explain this?

Are you are referring to the frequency of the PWM output of different pins ?

If so, see analogWrite() - Arduino Reference

That's not a pulse, it's an edge. Go high, low and high again. Preferably multiple times so you're not affected by how long it takes your scope to trigger.

PORTF and PORTK reside in different memory regions. PORTF resides in a IO area that can be accessed with special IO commands. These are one-cycle instructions, but this region is small. The processor of the Mega has so much peripherals, that not all fit in this address space. PORTK must be addressed by standard ram access instructions. These commands need 2 cycles.

3 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.