Pages: [1]   Go Down
Author Topic: Using a Timer interrupt with the Servo library  (Read 867 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I've read several tutorials dealing with timer interrupts, but most of them rely on the Timer1 library. My project is using the Servo library, and if I understand correctly I shouldn't mess with the Timer1 interrupt since that library uses it for PWM signals.

The interrupt function (or handler) needs to do something very simple: at a specified (and hopefully user-controlled variable) interval, check a certain global variable and write to a servo following certain conditions.

I'd be grateful for some more pointers on this issue, and advice as to the use of a library vs addressing the registers directly. Can these be "reset" if I make a mess, or can I potentially damage the chip?

Thanks.
Logged

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

Quote
The interrupt function (or handler) needs to do something very simple: at a specified (and hopefully user-controlled variable) interval, check a certain global variable and write to a servo following certain conditions.
What else is the Arduino doing?

How accurate (plus or minus how many milliseconds, microseconds, or nanoseconds) does the timing need to be?

What size interval, in milliseconds, microseconds, or nanoseconds?

If the answers are not much, not very, and fairly large, than interrupts are not even necessary.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino is basically operating a large-scale and weird-looking metronome. I was aiming for the most precise timing possible for two reasons: (1) accurate tempo (2) learning how to use interrupts...

While the main loop is running, the Arduino is mainly polling different buttons through a couple of 74HC165s and setting LEDs on an off with a couple of 74HC595s.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19026
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use Timer2.
Logged


Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To use timer2, you essentially change all of the "1"s in the registers to "2"s
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pardon the ignorance, but there only library I could find is for Timer1 (or3). Does this mean that to use Timer2 I need to use the low-level register commands?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19026
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe:

http://www.pjrc.com/teensy/td_libs_MsTimer2.html

It isn't too hard to do it yourself:

http://www.gammon.com.au/forum/?id=11504
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. The link to your site doesn't work, though...
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19026
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Worked for me just then.
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dunno what's wrong, then. Been trying since yesterday evening :)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19026
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I only posted it about 4 hours ago.
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it was 4AM here and I was awake... Not "evening" per se, I agree.

Anyway, second link still not working here. Strange.
Logged

Pages: [1]   Go Up
Jump to: