CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem using CCP1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
marcus.couceiro



Joined: 04 Jan 2012
Posts: 12
Location: Brazil

View user's profile Send private message

Problem using CCP1
PostPosted: Mon Feb 20, 2012 7:55 pm     Reply with quote

Gentlemen,

I am trying to measure the period of a known frequency using the following code
Code:


#include <16F873.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

int1 interruption=0;

#int_CCP1

   void CCP1_interruption()
      {
         interruption=1;         
      }

void main()
{
   long timer_T1, timer_T2, period;
   
   
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
   set_timer1(0);
     
   setup_ccp1(CCP_CAPTURE_RE);
   setup_ccp2(CCP_OFF);
   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_CCP1);
   clear_interrupt(INT_CCP1);
   
   while(1)
      {
         if (interruption==1)
            {
               disable_interrupts(GLOBAL);
               timer_T1 = CCP_1;
               period = timer_T1-timer_T2;
               timer_T2 = timer_T1;
               clear_interrupt(INT_CCP1);
               interruption=0;
               enable_interrupts(GLOBAL);
                             
            }     
         
       
       putc(254);putc(1); delay_ms(10);
       printf("period: %lu", period);
       delay_ms(500);
       
      }
}

So far my display gives only 0.0 as readings. Could anyone tell what am I doing wrong?

Thanks,
_________________
Marcus Couceiro
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 20, 2012 8:49 pm     Reply with quote

Do a search on the forum for: tachometer
http://www.ccsinfo.com/forum/search.php
There are several threads with working CCP capture code.
Stygian



Joined: 26 Apr 2011
Posts: 13

View user's profile Send private message

PostPosted: Mon Feb 27, 2012 8:56 am     Reply with quote

Hello All!

I don't want to open a new topic so I write here.
My question is simple. I'm using a PIC16F1938.
I want to use the CCP3 and the RS232 at the same time.
How can I disable the CCP3 on port C6 and enable on port B5 Rolling Eyes ?

Best regards,
Stygian
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group