Close

sketch for timer

A project log for MMR-70 - cheap radio module

some experiments with the fm module that features an atmega32

davedarkodavedarko 08/31/2015 at 12:330 Comments
int output_pin = 15;
int randNumber;

ISR (TIMER2_COMP_vect)
{
  PORTD ^= ( 1 << PD7 );
}

void setup()
{
  randomSeed(analogRead(0));
  // set LED pin to ouput
  DDRD = ( 1 << PD7 );

//CTC Modus
  TCCR2 = (1 << WGM21);

//Prescaler 64
//3686400 / 64 / 440 = 131
  TCCR2 |= (1 << CS20);
  TCCR2 |= (1 << CS21);
//TCCR2 |= (1 << CS22);

//start with an A
  OCR2 = 131 - 1; 

//Enable Compare Interrupt
  TIMSK |= (1<<OCIE2);

//Enable global Interrupts 
  sei();               
}

void loop()
{
  randNumber = random(256);
  OCR2 = randNumber;
  delay(250);
}

Discussions