Pages: [1]   Go Down
Author Topic: Timer interrupt and PWM  (Read 433 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
can I use analogWrite() function and Timer interrupt in the same code?
Thank you.
« Last Edit: March 18, 2012, 10:52:27 am by Mazen21 » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

which Timer, arduino has more....

Easiest way is just to try -

What is your goal?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

can I use analogWrite() function and Timer interrupt in the same code?

Yes.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you change the setup of the timer it can affect analogWrite, but you can add an interrupt handler for timers 1 and 2.

timer0 already has an interrupt handler that maintains the millis(), micros() and delay() time information, so its not wise to use this interrupt.

timer0 is used for PWM pins 5 and 6,
timer1 is used for PWM pins 9 and 10,
timer2 is used for PWM pins 11 and 3

(Arduino Mega's are different, note)
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you all for your answers.
I'm using arduino mega adk, and already using analogWrite() in pin 2 and 3.
I'm trying to do some code with a 5ms periode, The best way, I think, is using the timer interrupt, but I don't want to affect the analogWrite function.
Please if you have any links or answers send it to me.
Logged

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

Here is a link:

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

Pages: [1]   Go Up
Jump to: