Missing Timer Input Pins?%!&# (swearing omitted)

I set out to create a motor speed control design for an RC car project I'm working on and ran into an unexpected limitation in the Arduino Mega hardware design. Specifically, I wanted to implement a closed loop speed control on the drive motor on my car and thought I'd use one of the 16 bit timers to count revolutions of the motor using a hall effect sensor. But, after much searching, I was surprised to learn that the Mega Arduino design only bothers to bring out the input pin to Timer 5 to an edge connector. The input pins to the other 16 bit timers, timer 1, timer 3 and timer 4, are left completely unconnected... So, OK, fine. I thought I'd use timer 5. But, then I discovered that doing this would break my use of the Servo library, as it depends on Timer 5. Argh...

So, it seems that someone decided that using timers as counters was a rather unimportant feature in the design of the Arduino Mega. Frankly, this seems incredibly short sighted to me.


T0 is available. You would have to move millis to a different timer.

ICP4 is available.

ICP5 is available. The Servo library would have to run the timer at a constant frequency and leave it running.

You should be able to use any of the attachInterrupt() pins and count with an ISR - or even use pin-change interrupts and then any pin can be used.

Hi, I don't know a whole lot about hall effect sensors, but I have an RC Car on the table next to me, where on earth are you planning on mounting the sensor ? wont it be saturated by the motor magnets ? and wont it upset the balance of the motor ?

My suggestion - find an easily accessible slow moving gear or shaft and count the revs with light.

As others have suggested, any interrupt pin will do for this.

Duane B


Hall effect sensors cannot saturate, they are not ferromagnetic. (Well some sensors may add ferromagnetic materials to increase sensitivity, but your basic Hall effect sensor is just a piece of semiconductor with a bias-current flowing.)

Its an old thread, but these old threads come up in searches,and because of the poor quality suggestions and lack of clarity I thought I'd add the following:

Mega 2560 Timer input clk pins:

T0 - Port PD7 8bit counter - Pin 38 on the big header - often unavailable as used for comms (displays etc.) T1 - Port PD6 16bit counter - N.C. on arduino ! T2 - this timer cannot be used as a counter - no clock in pin T3 - Port PE6 16 bit counter - N.C. on Arduino ! T4 - Port PH7 16 bit counter - N.C. on Arduino ! T5 - Port PL2 16 bit counter - Pin 47 on the big header - a more or less dedicated pin

So it looks like Timer 5 is your only option if you are using a display or other device on pin 38.

This is true on MEGA type boards - the smaller microprocessors have only timers 0,1,2 leaving only the 8 bit timer 0 as the last remaining option on a pin much used for other things, not to mention the extensive use by built in Arduino functions like Delay(), but such functions can be bypassed by using timers and interrupts appropriately.

Talking of interrupts - shocked to see suggested to use a software counter on an edge interrupt, when the hardware has infinitely better resources available. How many clock cycles of dead time between counts?? Micro-controllers are all about the balance of hardware and software implementation...

Library support for counter use is almost non existent as far as I can determine. I may extend the timer 3 function library to cover all the options of the timer blocks as a solution for my code.

It does seem surprising to overlook the counter in this way - a shame to incur such a limitation given the sophistication of the MEGA timers.