can someone tell me, what is the output frequency on the PORTE pins if I use this code?
or:
How can i get the highest switching-frequency on an Arduino-Port?
for (n = 0; n < 2800; n++) {
PORTE = B11111111;
PORTE = B00000000;
}
I'am using an Olimexino 32u4 (Leonardo-compatible)
The for:loop adds time to test for the end condition.
If you just want the frequency to be fast and nothing else, this will be pretty quick.
Unstoppable, but quick
while(1){
PINE = 0b11111111; // toggle output by writing to Input register
}
"However, writing a logic one to a bit in the PINx Register, will result in a toggle in the corresponding bit in the Data Register."
You can also program a fuse to output the system clock. Also, not stoppable.
"Port C, Bit 7
CLKO: When the corresponding fuse is enabled, this pin outputs the internal microcontroller
working frequency. If the clock prescaler is used, this will affect this output frequency."
If you're looking for a burst of frequency, then system clock gated with an IO pin (2-input AND gate) can give bursts of 16 MHz for as long as the IO pin is high, control with a for loop or while counter, or simple time track using micros().
You can also take over a timer, turn off the prescaler, and get up to half the system clock out of it using fast pwm mode - but this only gets you a few pins, not a whole port (do you want a whole port? I'm not sure what the use case might be...)
Thank you for the answers, now things become clearer.
I need pulses with a duty cycle of exactly 50% on the pins of PORTB (not PORTE).
for (n = 0; n < 2800; n++) {
PORTB = B11111111;
__asm__("nop\n\t"); //How many nops do i need?
PORTB = B00000000;
}
Now my question is, how many NOPs have I to insert, that the signal get's perfectly symmetrical?
Is it possible to make the the duty cyle exactly 50% without any jittering?
The resulting frequency is not critical, it should be in the range of some MHz
This is for a IR LED beacon which sends morse code but with pulsing carrier.
If you're looking for a burst of frequency, then system clock gated with an IO pin (2-input AND gate) can > give bursts of 16 MHz for as long as the IO pin is high, control with a for loop or while counter, or simple > time track using micros().
That's it!
But I will use an external XTAL-Oscillator on a AND Gate port and a Arduino pin on the other port.