Go Down

Topic: Blinky! (Read 2636 times) previous topic - next topic

liudr

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

Onions

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.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

Jack Christensen


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: [Select]
//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) {
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy