count the time between a cycle

I want to count the time between a cycle.
Everytime my signal is hight the time counter should start and when the signal is high again it should stop.

A cycle takes about 10ms.

int Lichtschranke;
int Lichtschranke1;
unsigned long int T2=0;
unsigned long int T0=0;

Lichtschranke = RdPortI(PEDR);
 	Lichtschranke1 = Lichtschranke & 0x01;


     if((Lichtschranke1 == 1))
     {
     	T0=TICK_TIMER;
             Lichtschranke = RdPortI(PEDR);
 		 Lichtschranke1 = Lichtschranke & 0x01;

     if((Lichtschranke1 == 1))
     {
     	  T2=(TICK_TIMER-T0);


     }
     }