I am using the MC9S12XE-family and I would like to use a timer.
The timer should be started for an indefinite time. And after a particular time I want to stop the timer.
Also I want to measure the time the timer was running for?
Does anybody have any idea which timer and how can I do it?
ECT, TIM, PIT timers, and even RTI (real time interrupt) are suitable for the task. You can even count the time using ATD (analog to digital module) interrupt. It's not necessary to stop the timer. Instead you can notice starting and ending timer count and calculate the difference.
ECT and TIM are very simple to use for short timer intervals, less that 2^16 timer ticks. You read starting TCNT value, read ending TCNT value and take the differemce. For longer times you need to enable timer overflow interrupt and count overflow events. Overflow counter combined with TCNT can help you extending timer bitness from 16bit to as much bits as you need.
Alternatively you can use any other periodic interrupt (RTI, PIT, ..) and count interrupt events. Since interrupt period is known, you can use interupt counter variable as a timer.
So you should just open the datasheet and go reading about these peripheral modules. Good luck.