Using internal timer as a counter, triggered by an external pin, how?

Hi mates, since I'm experiencing problems using micros(); to check the value after the zero cross I would use another approach, use the hardware timer which sounds much better.

My goal is to trigger the gates (by photocoupler) to turn a bulb on after the zero crossing, it's a leading edge dimmer.

Since now I was using interrupts on zero cross, save the micros(); and in the loop() compare the actual micros() with the one of zero cross.. and depending on the desidered light intensity turn off the gates and cut the wave, waiting next zero.

Would be better to use the pulse (rising) of the zero crossing detector to start a counter, and in the loop read the register of the counter and do the proper compare, and if exceed turn off the gates.

  1. How can I program my Mega 2650 to use Timer1 as a counter, triggered by hardware pin? As in PWM Timer 2 is related to pin 12 and 11 I suppose I've to use one of them and connect the zero detector there.

  2. Timer1 has 16bit register, if I use a 256 prescaler I'll have an increment every 16uS, it means the counter may go till about 1 second. Can I also program an interrupt if it reaches 0? (I can use it as an allarm).

  3. The zero happens every 10ms, can I setup the counter to reset automatically and restart from 65535 at every rise of pulse on the hardware pin?

I would love someone expert may write me here the instructions I've to use, I need to program the counter and to check the counter values, thank you a lot!

I hope someone may support me,
I'm thinking alternatively to use interrupts as now and inside interrupt reset the timer register back to FFFF, and in loop() check its value. Is it possible to force the timer register? thank you