Pages: [1]   Go Down
Author Topic: PWM timer and Arduino CPU load  (Read 580 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm working on a project that requires fast analogWrites... I'm looking into using a DAC eventually, but for now I'm just using the PWM features of the arduino.

I found that to get even mediocre performance for my app I needed to play with the timers... no big surprise there... but I'm wondering if the way I'm doing it might impact anything else?  Is there an advantage to choosing, say, DIV8 over DIV1 in terms of how much processing power the PWM timer will use?  My main concern is that if I choose DIV1 over DIV8 unnecessarily, I'll be spending 1 out of every 4 clocks tending the PWM, or something silly like that...
Code:
#define TIMER_CLK_STOP            0x00      ///< Timer Stopped
#define TIMER_CLK_DIV1            0x01      ///< Timer clocked at F_CPU
#define TIMER_CLK_DIV8            0x02      ///< Timer clocked at F_CPU/8
#define TIMER_CLK_DIV64            0x03      ///< Timer clocked at F_CPU/64
#define TIMER_CLK_DIV256      0x04      ///< Timer clocked at F_CPU/256
#define TIMER_CLK_DIV1024      0x05      ///< Timer clocked at F_CPU/1024
#define TIMER_PRESCALE_MASK     0x07    //Total guess at this value...
void setup() {

  TCCR1B = (TCCR1B & ~TIMER_PRESCALE_MASK) | TIMER_CLK_DIV1;

}
Logged

Seattle, WA
Offline Offline
Jr. Member
**
Karma: 1
Posts: 81
Arduino rocks my socks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The timer isn't connected to the CPU - there's zero load.  The only time the CPU has to do anything is when you set registers, eg TCCR1A.
Logged

Pages: [1]   Go Up
Jump to: