Timers and Interrupts

Hello,
I am trying to use the timers of arduino mega directly without using any library.
So far i have came across registers such as TCNT, TCCR and so on. My project requires to start the 16 bit timers and reset the timer by using two different functions. (Like to reset timer TCNT0 we can write "TCNT1=0;")
Could someone will help me with the same.
Any help with the code appreciated .

Careful and prolonged study of the Atmega2560 datasheet is required if you want to play around with the registers. IIRC it has both C and assembler code examples.

Nick Gammon’s Interrupt tutorial may also be useful.

Is the purpose of what you are doing just so you can learn about using the hardware timers, or are you simply trying to get some project to work? If the latter please describe the project as that will allow us to help you better.

…R

The interrupt tutorial seems to be awesome but its of no use to me right now. Interrupts will be used afterwards.
And yes there is project which i am trying to do.
The following is the project :
To start a 16 bit timer when a external interrupt is sensed, then store the value of the timer in a variable when again a new external interrupt comes and then reset the timer.
i.e to to count time between two interrupts by using counter

kulkarnipurvesh:
The interrupt tutorial seems to be awesome but its of no use to me right now. Interrupts will be used afterwards.
And yes there is project which i am trying to do.
The following is the project :
To start a 16 bit timer when a external interrupt is sensed, then store the value of the timer in a variable when again a new external interrupt comes and then reset the timer.
i.e to to count time between two interrupts by using counter

Have you heard of the interrupt capture mode on Timer 1. It can do this by itself without any other interrupt to stop the timer. Why re-invent the wheel in code when the hardware will already do what you want.

Okay so Timer1 seems to be nice. The interrupt capture function useful.
Could you please help me with an example code for the same ?

kulkarnipurvesh:
Okay so Timer1 seems to be nice. The interrupt capture function useful.
Could you please help me with an example code for the same ?

Have you looked at the data sheet? It's all there.

Maybe it was called input capture and not interrupt capture. Either way, it's all illustrated in the datasheet

Well yeah , sorry i misspelled , its input capture .
Any help with the example code is appreciated.

kulkarnipurvesh:
Well yeah , sorry i misspelled , its input capture .
Any help with the example code is appreciated.

Have
You
Read
The
Datasheet
???

What help do you need? What question do you have? What part do you not understand?

Delta_G:
Have
You
Read
The
Datasheet
???

I suggested reading the datasheet at 17:09 and the OP wrote Reply #7 at 19:07 (i.e. 2hours later) so we can safely assume that he did NOT read it, and certainly not with the required intensity. It is a slow read even when you are familiar with it.

…R