Capture mode in PIC16F8777a

Discussion in 'Embedded Systems and Microcontrollers' started by RRITESH KAKKAR, Sep 22, 2013.

  1. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    HI,

    I am working on capture mode for measuring pulse at pic input pin...
    here is code pls have a look is that fine after that i will watch on lcd..
    Code ( (Unknown Language)):
    1.  
    2. #include<pic.h>
    3. #define _XTAL_FREQ 20000000L
    4. __CONFIG(0x3F18);
    5.  unsigned char low,high;
    6. void main (void){
    7.  
    8. TRISC2=1;
    9. CCP1CON=0b00000101;//Capture mode, every rising edge
    10. T1CON=0b00001001;//Internal clock,Enables Timer1
    11. TMR1IF =0;
    12.  TMR1H  = 0x00;
    13.  TMR1L = 0x00;
    14. GIE =1;  // Interrupt Enable
    15.   PEIE =1;
    16. CCP1IE =1;
    17. while(1){}
    18.  
    19. }
    20.  
    21.  
    22.  
    23. static void interrupt isr(void) {
    24.  
    25.   if ( CCP1IF ) {
    26.     low=CCPR1L;
    27. high=CCPR1H;
    28.     CCP1IF = 0;
    29.   }
    30.  
    31.   // if timer interrupt: reset timer and toggle Port B.2
    32.   if ( TMR1IF ) {
    33.    
    34.     TMR1H = 0x00;  TMR1L = 0x00;
    35.     TMR1IF = 0;
    36.   }
    37. }
    38.  
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ...I looked. Now what?
     
  3. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,790
    827
    Is that fine?
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Blessed is the one who finds wisdom, and the one who gets understanding, for the gain from her is better than gain from silver and her profit better than gold. She is more precious than jewels, and nothing you desire can compare with her. Long life is in her right hand; in her left hand are riches and honor. Her ways are ways of pleasantness, and all her paths are peace. She is a tree of life to those who lay hold of her those who hold her fast are called blessed
     
    Brian Griffin and Eric007 like this.
  5. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    I want to make controller which will capture the timing of pulse..
     
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Here is a simple and reliable way;

    Code ( (Unknown Language)):
    1.  
    2. // capturing a timed pulse period using TMR1
    3. main()
    4. {
    5.   // reset timer
    6.   T1CON = 0;        // timer1 OFF
    7.   TMR1H = 0;        
    8.   TMR1L = 0;
    9.  
    10.   while(PORTB.F0 == 1) continue;     // wait for \ edge
    11.   while(PORTB.F0 == 0) continue;     // wait for / edge  
    12.   T1CON = 0b00001001;                // start timing
    13.  
    14.   while(PORTB.F0 == 1) continue;     // wait for \ edge
    15.   while(PORTB.F0 == 0) continue;     // wait for / edge  
    16.   T1CON = 0;                         // stop timing
    17.  
    18.   // the period from / to / is now in TMRH and TMR1L.
    19. }  
    20.  
     
  7. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    What is this F0??

     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It is the same as RB0:cool:
     
  9. RRITESH KAKKAR

    Thread Starter Senior Member

    Jun 29, 2010
    2,831
    89
    is this in hi tech compiler ?
     
  10. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Just use the same way you normally read a single port pin in your compiler. :)
     
Loading...