# Using TIMER 1 without enabling interrupt in C on dsPIC33E

I am trying to decipher a C code in which Timer1 is being used for measuring the period of a digital signal, using dsPIC33EP256MC506. The timer interrupt is not being enabled, and there is no interrupt service routine for this timer. I'll post only the relevant portions of the code, since the actual code is Huge! The program is just initializing the timer as follows in the main() routine:

    volatile unsigned int ContinueTimeStep __attribute__ ((near)) = 0;
int main() {
PR1 = 0xFFFF;        /* Period */
T1CON = 0x8030;      /* enable timer, 1:256 input clock prescaler */
/* Main Loop */
for (;;) {
while (!ContinueTimeStep) ;
asm("BCLR.b _ContinueTimeStep,#0");/* ContinueTimeStep--; */
MyFunction();
}                                    /* End for(;;) */
}


In MyFunction() nothing is being done with the timer. The timer reading is only utilized in period calculation on rising edge. This done inside the change-notification ISR as follows:

void __attribute__((__interrupt__,__auto_psv__)) _CNInterrupt(void)
{
/* Change Notification on Port F0*/
if (portF_Xor & 1) {
if (portF_Copy & 1)                /* rising edge detection*/
{
CN80_RisingPeriode = Timer1 - TimerCN80_Old;
TimerCN80_Old = Timer1;
CN80_ChangeDetectedFlag++;
}

TimerCN80_Old = Timer1;
}
}


As I mentioned, I looked around in the code, but could not find a Timer 1 ISR. So I am pretty sure there isn't one. My question is, is this even valid? Will the timer automatically overflow and start from zero, once the period is reached? What happens if the interrupt occurs right after the timer 1 has overflown? The period will be calculated as negative? Thank you for your valuable input!

• Made some changes to the code ISR, to show the if statement, showing rising edge detection. – Adeel Apr 15 '15 at 20:54

• I did not include the if statement before, showing the rising edge detection. I edited the post. Does the updated ISR make any difference? – Adeel Apr 15 '15 at 20:54