user490: I have a Parallax 27800 2-Axis Joystick wired up to a AVR 14 Pin 20MHz 8K 12A/D - ATtiny84. The joy stick sends out a x y analog signal. I have programmed the Attiny84 to read the signals and set one of the attiny84 pins (high or low) depending on the direction of the joystick. In this example, each pin is wired up to a LED. The problem I am having is there is about a 1 second delay for the LED to light. The Attiny84 has a built in 8MHz clock. Would connecting an external 20MHz crystal fix this issue?
int UD = 0;
int LR = 0;

int DWN = 0;
int UP = 1;
int LEFT = 4;
int RT = 5;

int LRMID = 0;
int UPMID = 0;
void setup(){

  pinMode(DWN, OUTPUT);
  pinMode(UP, OUTPUT);  
  pinMode(LEFT, OUTPUT); 
  pinMode(RT, OUTPUT);

  digitalWrite(DWN, LOW);
  digitalWrite(UP, LOW);
  digitalWrite(LEFT, LOW);
  digitalWrite(RT, LOW);

  //calabrate center
  LRMID = analogRead(3);
  UPMID = analogRead(2);
}

void loop(){

  UD = analogRead(2);
  LR = analogRead(3);
  // UP-DOWN
  if(UD < UPMID - 5){
   digitalWrite(DWN, HIGH);
  }else{
   digitalWrite(DWN, LOW);
  }

  if(UD > UPMID + 5){
   digitalWrite(UP, HIGH);
  }else{
   digitalWrite(UP, LOW);
  }
  // LEFT-RIGHT
  if(LR < LRMID-5){
   digitalWrite(LEFT, HIGH);
  }else{
   digitalWrite(LEFT, LOW);
  }

  if(LR > LRMID +5){
   digitalWrite(RT, HIGH);
  }else{
   digitalWrite(RT, LOW);
  }

  delay(100);


}


user470: Several AVR devices including ATtiny 84, have a clock prescaler that can be used to lower the core frequency.
The divider can be controlled two ways.
The first way is the CKDIV8 fuse that controls the default loaded value to CLKPR (Clock prescale register) to either

fuse disabled:  Clock Division Factor 1 (clk/1)
fuse enabled: Clock Division Factor 8 (clk/8)

The fuse is enabled by default and applies the clk/8 setting, it can be changed with a programmer.
The second way is by changing the prescaler value during runtime. All you need to do is to include the following header
#include <avr/power.h>

and call one of following functions with the appropriate value you want to use
   clock_prescale_set(clock_div_1);    // Clock Division Factor 1
   clock_prescale_set(clock_div_2);    // Clock Division Factor 2
   clock_prescale_set(clock_div_4);    // Clock Division Factor 4
   clock_prescale_set(clock_div_8);    // Clock Division Factor 8
   clock_prescale_set(clock_div_16);   // Clock Division Factor 16
   clock_prescale_set(clock_div_32);   // Clock Division Factor 32
   clock_prescale_set(clock_div_64);   // Clock Division Factor 64
   clock_prescale_set(lock_div_128);   // Clock Division Factor 128
   clock_prescale_set(clock_div_256);  // Clock Division Factor 256

power.h manual
Note that the above functions can be applied at any part of the program, for example you can lower the cpu frequency to reserve battery and then set it higher again for intensive tasks. Just be aware that all peripheral will work with the divided clock too so PWM, timers, SPI, UART etc will all be affected.
If the problem you are facing is caused by the clock divider being in the /8 setting then you can change it at runtime.  
Add the header at the start of the sketch
#include <avr/power.h>

And then set the prescaler value to 1 at the start of setup()
void setup() {
               clock_prescale_set(clock_div_1);  // set the clock prescaler to /1
}


user353: While @alexan_e’s suggestion fixed your practical problem, I would argue that it did not address your root cause, which is that whatever board setting you’re working from in boards.txt assumes a clock rate of 8MHz, while in reality your fuses are set to boot the microcontroller at 1MHz. This caused your delay(100) to take 800ms, and was the entire reason for the slowdown. 
Instead of fixing this at runtime, as aleman_e suggested, it seems more natural to me to bring your fuse settings into alignment with your compiler settings, using the “burn boot loader” Arduino command (which on Attinys generally does NOT burn a boot loader, but only sets the fuses to be in sync with the compiler settings).
If your application is not going to become much more complex, running at 1MHz might be a more efficient choice than running at 8MHz. 

490: <p>I have a <a href="http://www.radioshack.com/product/index.jsp?productId=12345958" rel="nofollow">Parallax 27800 2-Axis Joystick</a> wired up to a <a href="https://www.sparkfun.com/products/11232" rel="nofollow">AVR 14 Pin 20MHz 8K 12A/D - ATtiny84</a>. The joy stick sends out a x y analog signal. I have programmed the Attiny84 to read the signals and set one of the attiny84 pins (high or low) depending on the direction of the joystick. In this example, each pin is wired up to a LED. The problem I am having is there is about a 1 second delay for the LED to light. The Attiny84 has a built in 8MHz clock. Would connecting an external 20MHz crystal fix this issue?</p>

<pre><code>int UD = 0;
int LR = 0;

int DWN = 0;
int UP = 1;
int LEFT = 4;
int RT = 5;

int LRMID = 0;
int UPMID = 0;
void setup(){

  pinMode(DWN, OUTPUT);
  pinMode(UP, OUTPUT);  
  pinMode(LEFT, OUTPUT); 
  pinMode(RT, OUTPUT);

  digitalWrite(DWN, LOW);
  digitalWrite(UP, LOW);
  digitalWrite(LEFT, LOW);
  digitalWrite(RT, LOW);

  //calabrate center
  LRMID = analogRead(3);
  UPMID = analogRead(2);
}

void loop(){

  UD = analogRead(2);
  LR = analogRead(3);
  // UP-DOWN
  if(UD &lt; UPMID - 5){
   digitalWrite(DWN, HIGH);
  }else{
   digitalWrite(DWN, LOW);
  }

  if(UD &gt; UPMID + 5){
   digitalWrite(UP, HIGH);
  }else{
   digitalWrite(UP, LOW);
  }
  // LEFT-RIGHT
  if(LR &lt; LRMID-5){
   digitalWrite(LEFT, HIGH);
  }else{
   digitalWrite(LEFT, LOW);
  }

  if(LR &gt; LRMID +5){
   digitalWrite(RT, HIGH);
  }else{
   digitalWrite(RT, LOW);
  }

  delay(100);


}
</code></pre>
 470: <p>Several AVR devices including ATtiny 84, have a clock prescaler that can be used to lower the core frequency.</p>

<p>The divider can be controlled two ways.</p>

<p>The first way is the <strong>CKDIV8</strong> fuse that controls the default loaded value to CLKPR (Clock prescale register) to either</p>

<ul>
<li><strong>fuse disabled:</strong>  Clock Division Factor 1 (clk/1)</li>
<li><strong>fuse enabled:</strong> Clock Division Factor 8 (clk/8)</li>
</ul>

<p>The fuse is enabled by default and applies the clk/8 setting, it can be changed with a programmer.</p>

<p>The second way is by changing the prescaler value during runtime. All you need to do is to include the following header</p>

<pre><code>#include &lt;avr/power.h&gt;
</code></pre>

<p>and call one of following functions with the appropriate value you want to use</p>

<pre><code>   clock_prescale_set(clock_div_1);    // Clock Division Factor 1
   clock_prescale_set(clock_div_2);    // Clock Division Factor 2
   clock_prescale_set(clock_div_4);    // Clock Division Factor 4
   clock_prescale_set(clock_div_8);    // Clock Division Factor 8
   clock_prescale_set(clock_div_16);   // Clock Division Factor 16
   clock_prescale_set(clock_div_32);   // Clock Division Factor 32
   clock_prescale_set(clock_div_64);   // Clock Division Factor 64
   clock_prescale_set(lock_div_128);   // Clock Division Factor 128
   clock_prescale_set(clock_div_256);  // Clock Division Factor 256
</code></pre>

<p><a href="http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html" rel="nofollow">power.h manual</a></p>

<p>Note that the above functions can be applied at any part of the program, for example you can lower the cpu frequency to reserve battery and then set it higher again for intensive tasks. Just be aware that all peripheral will work with the divided clock too so PWM, timers, SPI, UART etc will all be affected.</p>

<p>If the problem you are facing is caused by the clock divider being in the /8 setting then you can change it at runtime.  </p>

<p>Add the header at the start of the sketch</p>

<pre><code>#include &lt;avr/power.h&gt;
</code></pre>

<p>And then set the prescaler value to 1 at the start of setup()</p>

<pre><code>void setup() {
               clock_prescale_set(clock_div_1);  // set the clock prescaler to /1
}
</code></pre>
 353: <p>While @alexan_e’s suggestion fixed your practical problem, I would argue that it did not address your root cause, which is that whatever board setting you’re working from in boards.txt assumes a clock rate of 8MHz, while in reality your fuses are set to boot the microcontroller at 1MHz. This caused your delay(100) to take 800ms, and was the entire reason for the slowdown. </p>

<p>Instead of fixing this at runtime, as aleman_e suggested, it seems more natural to me to bring your fuse settings into alignment with your compiler settings, using the “burn boot loader” Arduino command (which on Attinys generally does NOT burn a boot loader, but only sets the fuses to be in sync with the compiler settings).</p>

<p>If your application is not going to become much more complex, running at 1MHz might be a more efficient choice than running at 8MHz. </p>
