Advertisement
martin2250

Timer

Nov 5th, 2013
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. void setup()
  2. {
  3.     /* setup pins etc*/  
  4. while(!(PINB & 0b100));//wait for input 1
  5.  
  6.  
  7.   TCCR1A = 0;// set entire TCCR1A register to 0
  8.   TIMSK1 = _BV(TOIE1);  //enalbe interrupt
  9.   TCCR1B = 1;// start timer 1
  10.  
  11.  
  12.  
  13.   while(!(PINA & 0b1000000));//wait for input 2
  14.  
  15.   cli();
  16.   TCCR1B = 0;    //stop timer;
  17.   temp_timer = TCNT1;  //store passed ticks
  18.  
  19.  
  20.   TCCR1A = 0;        // disable timer1
  21.   TCCR1B = 0;
  22.  
  23.  
  24.   time = (0xFFFFul * (unsigned long)overflows) + (unsigned long)temp_timer;      //calculate time
  25.  
  26.     /*display speed*/
  27. }
  28.  
  29. ISR(TIMER1_OVF_vect)
  30. {
  31.   overflows++;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement