What timers do the Arduino Libraries Use?

Hi, I was interested in finding out which timers the Arduino Libraries Use I want to use one for an app and i want to make sure that its not already being used!

Thanks

Pete

Timer0 is used by the core arduino code so that leaves timers 1 and 2 (on non-mega arduino boards). Both of these timers are used in various playground libraries. Timer1 is more versatile (it's the only 16 bit timer and the only timer that can measure frequency and pulse widths in hardware) so I would use timer2 if an 8 bit timer is ok for your application.

I think the only timer used by the libraries distributed with arduino is Timer1 (used by the Servo library) . However, the next arduino release will have a tone function that uses timer2.

Hi, Thanks for the quick reply, I use the MSTimer project to control everyting inside the micro which i think uses Timer 1 so timer 2 is ideal! What i want to do is use its counter function to count a toggling pin, which i can reset on a certain time base. This is going to be used to control Fan speed, and with my sums a 6000rpm with 3 clicks per cycle will mean i get 300 pulses per second. So it i use a reset time base of 100ms or 500ms i only need to count up to 30 or 150. So the 8 bit register will be fine.

Two issues i could do with a hand with, 1. How do i connect the counter of timer2 to a i/o pin? I cant find any reference to it, only to the external clock. 2. It i am using Timer0 via the libraries Timer1 to control the system on MSTimer and Timer2 to count the Fan Speed. Will i still be able to supply a PWM signal to a fan?

Thanks

Pete

I think only timer1 has the ability to count external pulses in hardware. But why not measure the period between pulses to get the fan speed. You can do this with pulseIn or by measuring the period in an interrupt

The PWM outputs on Timer0 are available for fan control, although if you use the technique above you would also have PWM on timer2

Yep the pulseIn function would do it!! And i take it I can use the AnalogWrite Command to send the PWM out, Which uses timer0 right???

How many different AnalogWrite process can i have running at any one point? IE could i have 2-4 fans being ran on the same Chip? with pulseIn being used as well? Or would i be heavily over using the chip?

Pete

Assuming you will be using timer1 for other purposes, you can do analogWrites to pins 3,5,6 and 11. PWM is produced in hardware by the timers so CPU load is not affected by the number of PWM outputs you are using.

Hi, But can i run two different PWM values to 2 different pins? IE 3 and 5 which i believe uses timer0. Could i have one set to 50% and one set to 75% Or would they need to be the same value, because they are using the same timer? Thanks again for your help this Forum is amazingly useful!

Pete

But can i run two different PWM values to 2 different pins? Yes

You can write any valid analogWrite value to any of the free pwm pins mentioned in my previous post.

Excellent!!!! I will hopefully get something working tomorrow when my optocoupler turns up! You mentioned at the top of this post the new release. Is there anyway to find out whats coming???

Thanks

Pete

issues addressed in 0018 are listed here: http://code.google.com/p/arduino/issues/list?can=1&q=milestone=0018