Jump to content
Sign in to follow this  

Timer 1 as input capture

Recommended Posts

Hi all,


I need to measure time/frequncy with timer1, but the results I get seem to be nonsens.

Does anyone see my mistake ?


this is the initialisation:

void TMR1_IRQ_EN (void)



  clear_bit(intcon, PEIE);

  t1con = 0x30; /* Timer 1 prescale 1:8, int. clock, TMR1 off */

  ccp1con = 0x05 ;                 /* Capture every rising edge */  








... and here is the part of my IRQ handler:


     if (test_bit(pir1,CCP1IF))   // TMR1 Input Capture Interrupt


// clear_bit(pie1,CCP1IE);

tm1_val = 0;

tm1_val = ccpr1h;

tm1_val = tm1_val << 8;

tm1_val = tm1_val & 0xff00;

       tm1_val = tm1_val + ccpr1l;

ccpr1l = 0;

ccpr1h = 0;


// set_bit(pie1,CCP1IE);


Any ideas ?

Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...