Pages: 1 [2]   Go Down
Author Topic: Blinky!  (Read 2055 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 74
Posts: 7251
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Bookmarked. I've thought about using timers for a while. Thanks for sharing.
Logged


Newcastle, England
Offline Offline
Sr. Member
****
Karma: 3
Posts: 489
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm up to the pre-scaler bit, and trying to set up an 8 bit timer with a /1024 pre-scaler. You need some of the info hidden in the datasheet for it; the datasheet can be found here: http://www.atmel.com/dyn/resources/prod_documents/doc8025.pdf . At over 400 pages long, finding the relevant pages is extremely difficult... I've saved a copy to my computer though, for future reference.
Learning about timers is something I have also wanted to do for a long time, but I only got round to finding that page yesterday. It provides for interesting reading though!

Onions.
Logged

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) smiley-grin

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4089
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I learned about the timers on here: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=50106 . Lots of good info for a timer newbie!

I read that a few months back; very well written, I'd like to see the guy do more! If we're not hung up on using the "pin 13" LED, then a timer can do the blinking for us with no additional code once it's set up:

Code:
//Turns an LED connected to Arduino pin 9 on for one second,
//then off for one second, repeatedly. Uses Timer/Counter1 to divide the 16MHz clock
//by 256 with the prescaler (to 62500 Hz) and then toggles the pin after
//62500 counts (i.e. 0 to 62499).
//
//478 bytes with Arduino 0022

void setup(void) {
    DDRB = _BV(DDB1);                  //set OC1A/PB1 as output (Arduino pin D9, DIP pin 15)
    TCCR1A = _BV(COM1A0);              //toggle OC1A on compare match
    OCR1A = 62499;                     //top value for counter
    TCCR1B = _BV(WGM12) | _BV(CS12);   //CTC mode, prescaler clock/256
}

void loop(void) {
}
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Pages: 1 [2]   Go Up
Jump to: