Pages: [1]   Go Down
Author Topic: A simple question about timers & pin usage.  (Read 596 times)
0 Members and 1 Guest are viewing this topic.
San Pedro, CA.
Offline Offline
Full Member
***
Karma: 3
Posts: 155
My head HURTS!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to use a timer without affecting any pins?

Thanks for any replies,
DJ
Logged

DigitalJohnson

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is it possible to use a timer without affecting any pins?
No. Every timer has multiple purposes. If you divert it from its assigned purpose(s), that will have some impact.
Logged

0
Offline Offline
Shannon Member
****
Karma: 221
Posts: 12710
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To flesh this out a bit:

The three timers in the Uno (and similar) are used by analogWrite() to control the PWM outputs on pins 3,5,6,9,10,11.
timer0 is used to implement millis(),micros(),delay().

If you don't use analogWrite() on pins 3,9,10,11 then you can use timers 1 and 2 how you like.
If you don't use the time functions or analogWrite on pins 5,6 you can
user timer0 how you like (but you'll have to inhibit the interrupt handler perhaps).

Timers can be used to just count time (no need to connect to pins like analogWrite() does), or to count inputs (timer1 with pin 5),
or to generate waveforms via PWM, or to generate regular interrupts.  Timers 0 and 2 are 8 bit only, timer1 is 16 bit (but can be
configured as 8,9 or 10 bits too).
Logged

[ I won't respond to messages, use the forum please ]

San Pedro, CA.
Offline Offline
Full Member
***
Karma: 3
Posts: 155
My head HURTS!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got a mega2560 and, believe it or not, I'm using almost every pin. I want to use a timer for timing events between some of the hardware I have attached. The thing is, all of the timer compare match pins are used by hardware devices. Is there any way to use a timer and not have it output on it's related compare match pins?

Thanks for your time,
DJ
Logged

DigitalJohnson

San Pedro, CA.
Offline Offline
Full Member
***
Karma: 3
Posts: 155
My head HURTS!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now that I've thought about it, I suppose I could set up software timers using micros() or millis() and poll them.

DJ
Logged

DigitalJohnson

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any way to use a timer and not have it output on it's related compare match pins?

Yes.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Yes.
Hey, dumbshit, that's not an acceptable answer!
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19326
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The thing is, all of the timer compare match pins are used by hardware devices. Is there any way to use a timer and not have it output on it's related compare match pins?

Why all the bickering? It is completely optional whether the output of a timer is directed to a hardware pin. For example, for "TCCR0A – Timer/Counter Control Register A":

Code:
COM0A1 = 0, COM0A0 = 0: Normal port operation, OC0A disconnected.

"Normal" operation (whatever that means) is that the output pin is not connected.

(edit) I suppose "normal" means you get to use the port in its normal way, that is the way you choose to use it.
« Last Edit: November 21, 2012, 05:23:17 pm by Nick Gammon » Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19326
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Now that I've thought about it, I suppose I could set up software timers using micros() or millis() and poll them.

Not necessary.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

San Pedro, CA.
Offline Offline
Full Member
***
Karma: 3
Posts: 155
My head HURTS!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Nick. I guess it's time to learn all about timers.  smiley-eek-blue
I'll do some research and see if I can get all the parts to play nice with each other. If so, I'll post some code for others' in need.

Thanx,
DJ
Logged

DigitalJohnson

Pages: [1]   Go Up
Jump to: