Setting up registers


is ther reason not set timer1 register , interrupts this?
code: [select]
ddrb |= _bv(1); // set pin 9 output
ddrb |= _bv(2); // set pin 10 output

tccr1a =162; // com1a1=1, com1b1=1, wgm11=1
tccr1b=10;   // wgm12=1, cs11=1
ocr1a =off;  // set pwm pin 9
ocr1b =off;  // set pwm pin 9
 
eicra = 15; //the rising edge of int0 , int1 generates interrupt request
eimsk = 3; //enable both interrupt int0 , int1

(i don't remember why) told use timer 2 instead. (maybe can refresh memory arduino function/s use timers 0 , 1)

and avoid errors there way should manipulate bits.  i'll give sample of setting timer 2:

code: [select]

void setuptimerisr() {
 // disable interrupts while setting registers
 cli();

 // reset control registers
 tccr2a = 0;
 tccr2b = 0;

 // clear timer on compare match (ctc) mode
 tccr2a |= (1 << wgm21);

 // prescaler x1
 tccr2b |= (1 << cs20);

 // interrupt every 160/16e6 = 10 usec
 ocr2a = 159;

 // use system clock timer/counter2
 assr &= ~(1 << as2);

 // reset timer/counter2 interrupt mask register
 timsk2 = 0;

 // enable output compare match interrupt
 timsk2 |= (1 << ocie2a);

 // enable interrupts once registers have been update
 sei();
}

// isr run when timer/counter2 reaches ocr2a
isr(timer2_compa_vect)
{
 int_count++;
}


i hope helps
:)


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Setting up registers


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums