Pages: [1]   Go Down
Author Topic: Timer on Attiny85  (Read 1220 times)
0 Members and 1 Guest are viewing this topic.
Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1057
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to teach myself something about timers, by reading this

http://deans-avr-tutorials.googlecode.com/svn/trunk/Timers/Output/Timers.pdf

I have an example (for Atmega16), and used it on a Attiny85.
The sketch  blinks a LED on Pin 0 every second, and it works.
But when i think about there are some strange thing I don't understand.

1. When I change the prescaler to 16384 it dosnt change the blinkrate ?
Code:
TCCR1 |= ((1 << CS13) |  (1 << CS12)| (1 << CS11)| (1 << CS10)); // Prescaler @ 1024 Table 12.5

2. I set OCR1A=7812; , but isn't OCR1A a 8 bit register ?

Code:

void setup(){
  DDRB |= (1<<PB0); //Set pin PB0 as output
 TCCR1 |=(1<<CTC1); //Start timer 1 in CTC mode Table 12.3.1
 TCCR1 |=(1<<COM1A0); //Timer1 in toggle mode Table 12.4
TCCR1 |= ((1 << CS13) |  (1 << CS11)| (1 << CS10)); // Prescaler @ 1024 Table 12.5
 
 
 OCR1A=7812; //CTC Compare value
 }
 
 void loop(){
 
 
 }

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Which core are you using?
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1057
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using this core, Arduino 0021 and a pololu programmer.
The Attiny @ 8MHz

http://arduino.cc/forum/index.php/topic,51984.0.html
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Some things...

• Timer 1 on the ATtiny85 family is different than all the other timers I've seen.  Code from another processor is unlikely to work without modifications.

• For the ATtiny85 family, the Tiny Core uses timer 1 for millis.  You can change that (for all projects) by modifying this macro...
http://code.google.com/p/arduino-tiny/source/browse/trunk/hardware/tiny/cores/tiny/core_build_options.h#107

• As far as I can tell, timer 0 is the same across all processors.  I suggest leaving millis on timer 1 and using timer 0 for your experiments.

• When manipulating registers, do not assume they are already set to a specific value.  For example...

 TCCR1 |= ((1 << CS13) |  (1 << CS12)| (1 << CS11)| (1 << CS10)); // Prescaler @ 1024 Table 12.5

...what if CS13 through CS10 are already 1?  Or this...

 TCCR1 |=(1<<COM1A0); //Timer1 in toggle mode Table 12.4

...what if COM1A1 is already 1?  You should first initialize all the relevant registers to a known value (like zero) then manipulate them.
« Last Edit: July 20, 2012, 12:35:51 pm by Coding Badly » Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1057
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I suggest leaving millis on timer 1 and using timer 0 for your experiments.

I certanly will

Quote
You should first initialize all the relevant registers to 0

I see the point, and I will do that too, although I don't see that often in the tutorials.

Thank you for your help, it is not easy for me to understand the attiny datasheet, at least not at the stage I'm  on now.
Logged

Pages: [1]   Go Up
Jump to: