Go Down

Topic: Using a Timer interrupt with the Servo library (Read 1 time) previous topic - next topic

Ischia

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.

PaulS

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.

Ischia

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.

Nick Gammon

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

WizenedEE

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

Ischia

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?

Nick Gammon

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
http://www.gammon.com.au/electronics

Ischia

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

Nick Gammon

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

Ischia

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

Nick Gammon

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

Ischia

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

Anyway, second link still not working here. Strange.

Go Up