Hello guys, I’ve just started working with a Arduino mini pro. I'm trying to measure a RPM with input capture timer 1. The interrupts are being triggered but when I write the value of TCNT1 to my serial monitor I only receive a 8 bit value, instead of a 16bit value. I also tried to get the counter value out of register ICR1L and ICR1H, but I noticed that ICR1H stayed zero and wasn’t receiving any values.
Could anybody tell me what I’m doing wrong?
static unsigned char Timer1;
unsigned int RPM;
unsigned short Period;
unsigned short Prev_Period;
void Init_ReadRPM()
{
//init RPM_read PB0
DDRB &= ~0x01;
TCCR1A |= 0x00; //Disable PWM
TCCR1B |= 0xC1; // - Noise filter on
// - Trigger on rising egde
// - NC
// - Waveform (bit3&4) normal
// - Prescaler (bit1&2&3) 1
TIMSK1 |= 0x21; //-Interrupt enable
// Timer overflow enable
TIFR1 |= 0x21; //Reset input capature flag
}
ISR(TIMER1_CAPT_vect)
{
if((PORTB && 0x01) != 0)
{
cli(); // Disable interrupts
if(counter <= 10)
{
Serial.print("TCNT1 = ");
Serial.println(TCNT1, DEC);
Serial.print("ICR1H = ");
Serial.println(ICR1H,DEC);
}
Timer1 = 0;
sei(); // Enable interrupts
TIFR1 |= 0x10; //Reset input capature flag
}
}
ISR(TIMER1_OVF_vect)
{
Timer1++;
TIFR1 |= 0x01;
}