Can't get input capture timer to work

Very frustrating last few days on this one. I'll try to be as specific as possible:

Goal:

-ATTiny85 is generating a pulse using Timer1. By changing the OCR value, I can arbitrarily adjust the frequency of said pulse

-ATTiny85 pin 4 is the output of that pulse and is connected to Mega Pin 53 (I assume this is PB0 or PCINT0, which is also ICP1???)

-Maga is meant to capture the falling edges and calculate the time delta for what will become a serial out stream sending time deltas to a graphing function for RPM

My problem:

The Tiny is producing the pulses but I had to use interrupts to do it because I couldn't output the raw wave to one of the pins directly from the timer. Thus I have a slightly buggy interrupt doing it manually. This is a problem but a LOW priority at this time, since I am still getting a good enough wave to test with

The REAL problem is on the Mega side where I must utilize the INPUT CAPTURE feature to get the most responsive and noise free measurement of the delta T between falling edges.

a) I do not know if the ICP is pin 53 or not. I've read that it is PBO or PCINT0, which is pin 53 but I'm not getting anything on pin 53

b) I'm not entirely sure how to activate the input capture feature. I know the bit that controls noise cancelling and the bit that activates the input capture interrupt vector but my ISR does not execute despite this.

Request:

1) Can somebody please tell me the absolute minimal code to tell the Mega to monitor pin 53 for INPUT CAPTURE. If this is not the right pin to use, which pin is it and how do I enable input capture on that pin?

2) Absolute minimum code to set up the appropriate timer and/or input capture registers to trigger off that pin's falling edge and call the TIMER1_CAPT_vect ISR so that I can record the delta T in the 16 bit buffer (ICR is it?). I think ICR has 2 bytes that need to be copied, correct? What's the syntax for doing that?

Thank you very much.

The Arduino MEGA doesn't have a pin that connects to Input Capture Pin for Timer1 (ICP1). You can use: Timer4 ICP4 (Pin 49) Timer5 ICP5 (Pin 48)

Thanks Cattledog. Not that I don't believe you or anything, but why are there references to PB0 (pin 53) out on the net when searching for input capture using timer1 ?

Furthermore, I attempted to write down my thoughts on how to get the capture timer working. It's a bit informal but I'm just wondering if I'm on the right track:

WGM1 - page 145 - ICR1 needs to be made "TOP" as will be seen in the next step and there are 4 modes that do this. The CTC mode "seems" to be the best because on input capture event, it updates the interrupt flag immediately. Set WGM1 bits 3,2,1,0 to 1100

COM1 A1,B1,C1, A0,B0,C0 - page 155 - I don't truly understand this but I think when the capture unit triggers a new "TOP" value and compare match is performed, this is when the OCR should be set to high. So CTC is a non-PWM mode and COM1[ABC]1, COM1[ABC]0 should be set to 11

TCCR1B - Page 156 - Bits ICNC1 and ICES1 need to be set to 1 and 0 respectively for ENABLED and FALLING. CS1[2,1,0] set the prescaler which I think is best set to 1024. This would be 101.

TIMSK1 - Page 161 - ICIE1 needs to be set to 1 to enable the IC interrupt but the interrupt vector will only fire if the ICF1 flag is set. See next step.

TIFR1 - Page 163 - Bit 5, ICF1 doesn't need to be set manually but as per the first step in this sequence (see above), WGM needs to be set properly to make sure that upon capture event, the ICF1 flag is set. This is required to fire the interrupt.

ICR1H and ICR1L contain the 16bit number corresponding to the input capture unit's counter value (the time delta)

Nick Gammon has an example of using the input capture to time an interval. It's part of his excellent tutorial on the timer/counters of the AVR processors.

https://www.gammon.com.au/forum/?id=11504&reply=12#reply12

why are there references to PB0 (pin 53) out on the net when searching for input capture using timer1 ?

Information on the net is frequently wrong. Pin 53 (PB0) is for the Pin Change Interrupt 0. (PCINT0)

Gahhhrrrlic: Thanks Cattledog. Not that I don't believe you or anything, but why are there references to PB0 (pin 53) out on the net when searching for input capture using timer1 ?

Probably because those references are dealing with ATMega328-based boards, where PB0 is ICP1. On the ATMega2560 (as used on the Arduino Mega) ICP1 is on PD4, which isn't broken out.

Son of a...

Well I guess the devil is in the details and I didn't pick up on that. Head gets clouded easily when you're knee deep in the manual I guess.

Thanks a lot for clearing that up. I'm going to take another crack at it, this time with Timer4 and we'll see how that goes.

EDIT: You may already know this but there are a couple of rare 3rd party mega boards which do connect every single pin on the chip. I hope to acquire one of those so I can use other disabled stuff like the analog comparator. One of the AIN pins is also not normally exposed.