Author Topic: Arduino Help with timer0  (Read 8088 times)

0 Members and 1 Guest are viewing this topic.

Offline malexTopic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Arduino Help with timer0
« on: January 23, 2010, 08:43:41 AM »
I'm looked around the datasheet and sample code and I've come up with the following as my solution to making an LED flash (The timing isn't important at the moment, I just want to make an interrupt that fires when the timer overflows.)  The controller I'm using is the atmega328P.
Quote
#include <avr/interrupt.h>
int ledPin =  13;   
void setup()   {               
  pinMode(ledPin, OUTPUT);   
  
  TCCR0A=0x00;        // Normal Timer0 Operation
  TCCR0B=0b00000001;   // Prescaler and clock select
  TCNT0=0x00;                   // Start count from here
  TIMSK0=(1<<TOIE0);            // Enable Counter Overflow Interrupt
  digitalWrite(ledPin, HIGH);
  sei(); 
   TIFR0=0b00000000; 
}

ISR(TIM0_OVF)
{
    digitalWrite(13, LOW);
    TCNT0=0;
    while(1);
}
void loop()                     
{
     
}


So far, theres no luck in making the LED turn off from its initial lit state.  I've tried to manually set the TOV0 bit to 0 and 1 to try to see if we're allowed to do that...but it didn't work.

For the ISR handler I've tried TIM0_OVF_vect and TIM0_OVF since I've seen both used but neither works.

Any ideas on how to work this?  I've read about some library functions that may make interrupt usage easier but I want to do this by at this lower level.


Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Arduino Help with timer0
« Reply #1 on: January 23, 2010, 09:03:27 AM »
This is the holy grail of info for timer interrupts on the arduino: (with sample code)

http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/

I used it to make the 35Hz time for my motor controller: (you can look at my source)

http://www.billporter.info/?p=127

Hope this helps. Sorry I couldn't look through your source, i don't have time at the moment.

 


Get Your Ad Here