Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

timer 1 question

2008-02-20 by bobby cossum

i'm trying to get a 30Hz pulse out of timer 1.  i initialize it as
follows...
//
//  set up timer 1, ca 30Hz, fast pwm mode 15, prescale = 64, top =
8333, no interrupts
//
  TCCR1B = 0;                             // stop timer 1
  TIMSK1 = 0;                             // disable all interrupts on
timer 1
  TCCR1A = (1 << WGM11) | (1 << WGM10);   // disconnect output compare
pins
  OCR1A = 8333;                           // freq = 16M / 64 / 8333,
ca 30Hz
  TCCR1B = (1 << CS11) | (1 << CS10) |    // start timer one with
prescale = 64 and ...
           (1 << WGM13) | (1 << WGM12);   // ... fast pwm mode 15

then to get a 1 Hz pulse on PD7 i test TOV1 in my main loop as follows


if (TIFR1 & (1 << TOV1)) {             // timer1 overflow ?
  TIFR1 &= ~(1 << TOV1);               // clear timer1 overflow
  if (++t1Count == 15) {
    PORTD ^= 0x80;
    t1Count = 0;
  }
}

instead i get a very rapid flicker on the led i have connected.  i
suspect my timer math, but i've gone over it again and again and don't
see what's wrong.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.