int period; // declare period as global variable
ISR(PCINT2_vect) // interrupt service routine for pin change interrupt request 2
{
if (PIND & 0b10000000){ // if pin 7 is high
period = TCNT1*.0000625*1024; // convert clock ticks to milliseconds
Serial.println(period);
}else{ // pin 7 is low
TCNT1 = 0; // reset the timer to 0
}
}
int main(void)
{
// setup code that only runs once
DDRD = 0b00000000; // set pin 7 as input
PORTD = 0b10000000; // enable internal pullup on pin 7
PCICR = 0b00000100; // enable pin change interrupt on pin 7
PCMSK2 = 0b10000000;
sei(); // enable interrupts
TCCR1A = 0b00000000; // set timer 1 to normal mode
TCCR1B = 0b00000101; // and set prescaler to 1024
Serial.begin(9600); // initialize serial
while(1){
// code that loops forever
}
}
/*
TCNT1 = 0;
owerflow = 0;
dummy = dummy + 65536*owerflov
unsigned long dummy;
dummy = TCNT1;
/ Declare your global variables here
uint8_t Overflow;
uint32_t Dummy;
uint8_t Inmpulse;
// Timer 1 overflow interrupt service routine ----------------------------------
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
Overflow = Overflow + 1;
}
// Timer 1 input capture interrupt service routine ------------------------------
interrupt [TIM1_CAPT] void timer1_capt_isr(void)
{
Dummy = TCNT1;
Dummy = Dummy + 65536 * Overflow;
Dummy = Dummy * 0.000000125;
Impulse = 60 / Dummy;
}
ISR(TIMER1_COMPA_vect)
ISR(TIMER1_OVF_vect)
*/