Question about Timers and PortManipulation

Ok I have two (somewhat) unrelated questions:

The first is in regards to timer interrupts I am planning on using Timer3 for a very fast (at least twice a millisecond) interrupt which will create a pulse on one of the various Digital I/O pins on the Arduino Mega 2560. So I went here http://arduino.cc/playground/Code/Timer1 and found the Timer3 library which I am using. It says I can set the interrupt to be any amount of microseconds I want, but really won't it be limited by the combinations of the prescalar? Is it just selecting the closest one to the microseconds you provide?

The second question has to do with Port Manipulation as shown here (http://www.arduino.cc/en/Reference/PortManipulation) Unfortunately it doesn't specify the registers to use for the Arduino Mega 2560, so does anyone have that information? I would be grateful.

Thanks!

wd40bomber7: It says I can set the interrupt to be any amount of microseconds I want, but really won't it be limited by the combinations of the prescalar? Is it just selecting the closest one to the microseconds you provide?

Maybe. The timer supports a very rich set of possible expirations. The prescaler and output compare register are combined to determine when the timer expires.

The answer is "maybe" because I have no idea if the library makes use of output compare.

Unfortunately it doesn't specify the registers to use for the Arduino Mega 2560, so does anyone have that information?

Generally it is called a "pin mapping"... https://www.google.com/search?q=arduino+mega+1280+2560+pin+mapping

Actually I've found and looked at http://arduino.cc/en/Hacking/PinMapping2560 before. But I must be missing something. How do I know what variables to use? How do I know which bit in that variable maps to which pin? Is that actually embedded in that page somewhere and I'm just missing it?

As for the timer, I'm afraid "maybe" clears up about as much as you'd think. Looking through the very short TimerThree class code, I must admit I am no wiser about whether or not it will exactly match the milliseconds I provide it. If you know what to look for, you can download the library at the link I provided above.

From that web page…

u Pin Number[/u] Pin Name Mapped Pin Name
1 PG5 ( OC0B ) Digital pin 4 (PWM)
2 PE0 ( RXD0/PCINT8 ) Digital pin 0 (PWM) (RX0)

PG5 - “G” is the port, “5” is the bit.

Configure it as an output…
DDRG |= (1 << DDG5);

Make it high…
PORTG |= (1 << PORTG5);

Make it low…
PORTG &= ~ (1 << PORTG5);

Configure it as an input…
DDRG &= ~ (1 << DDG5);

Read it…
PING & (1 << PING5)

wd40bomber7: I am planning on using Timer3 for a very fast (at least twice a millisecond) interrupt which will create a pulse on one of the various Digital I/O pins on the Arduino Mega 2560.

If you just want the interrupt, so you can make a pulse, I would bypass the interrupt altogether. Just make the timer toggle the pin. That way you don't have the interrupt latency.

Now it makes sense! Thank you. This was very informative.

I considered that but unfortunately it is a little more complicated than that. There are two pins I need to drive, not just one (sorry I was unclear earlier) and I also need to drive a counter. I could use Timer3 for the counter, Timer4 and timer5 for the two pins, but for now an interrupt should be plenty fast enough. If I need additional speed I will definitly look into that though.[