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 support@ccsinfo.com

CCP Don't Work with 16F877 ?!?!

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



Joined: 07 Mar 2010
Posts: 10

View user's profile Send private message

CCP Don't Work with 16F877 ?!?!
PostPosted: Sun Mar 07, 2010 5:08 am     Reply with quote

Hello,
I have a problem please help.
I apologize for bad English!

I'm trying to use CCP Capture module for calculating the period of the rectangular input pulses. Do simulations with Proteus but 16F877 PIC program refuses to work! Never gets a Interrupt from the CCP module.

When I change to 18F458 pic, program works very well.

I have not tried on real PIC 16F877, if it works.
My problem is with Proteus and not know why we receive it.

I tried also the most basic program of "CCS HELP": EX_CCPMP.C
but it does not work with 16F877??

Pattern of connection Proteus are identical, only the PIC is different.

Proteus is 7.6 SP0
CCS is PCWHD v.4.093

I need your help, Thanks in advance:)

This program works with the 18F458 PIC

Code:
#include <18f458.h>   
#device *=16      // Pic Model 16F84A
#DEVICE ADC=10           
#Fuses HS,NOWDT,NOPROTECT,NOLVP, NOBROWNOUT, NOPUT
#use delay(clock=16000000)        // Crystal Oscillator Frequency
#use rs232(baud=15625,parity=N,xmit=PIN_C6,   rcv=PIN_C7   ,bits=8,FORCE_SW /* INVERT*/,TIMEOUT=460/*360*/ )

//#include "Function.h"
//#include "string.h"

#include <math.h>
#include <flex_lcd.c>   
 

#ifndef Enable
#define Enable           1
#endif

#ifndef Disable
#define Disable          0
#endif

//*************** TIMER ***************************
//RTC variables
#define XTAL_FREQUENCY  16000000
#define TIMER1_FREQUENCY (XTAL_FREQUENCY / 16 ); 
#define TIMER1_OverflowConst ( (1/TIMER1_FREQUENCY ) * 65536) 
#define TIMER1_TicketConst ( (1/TIMER1_FREQUENCY )  ) 
//**************************************************
#byte pA   =0xF80   //port a   //
#byte pB   =0xF81   //b         //
#byte pC   =0xF82   //c         //
#byte pD   =0xF83   //d         // usb port 8 bits parallel
#byte pE   =0xF84   //port e   //
// *********************************



//*********    ************
#Define  SetConfigPortA     0//100011  //33  100001
#Define  SetConfigPortB     0//16//16//16
#Define  SetConfigPortC     0//bx 00000011
#Define  SetConfigPortD     0
#Define  SetConfigPortE     0
//**************************************************

#define TEST_LED pin_c5

//globals
static int1 fHit = 0;
static int nHits = 1;
int16 timeC = 0, timeL = 0;



//****************************************************************
//measure the time from rising egdes then process
//****************************************************************
#int_ccp1
void isr_ext(){

output_low(TEST_LED);
output_high(TEST_LED);

if(nHits==1){
   timeL = ccp_1;
   nHits=2;
}
else if(nHits==2){
   timeC = CCP_1;//get ccp value
   fHit=1;  //flag for processing
   disable_interrupts(GLOBAL);//disable until processed
   nHits=1;//reset nHits to start over
}
}//isr
 

VOID MAIN(void)

{
 

int8 i = 0;
int16 period = 0, freq = 0;

//setup timer1 to measure pulses
SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_1);
#define DIVIDER 1
//setup ccp1 for interrupt of pulse measurement
CLEAR_INTERRUPT(INT_CCP1);
SETUP_CCP1(CCP_CAPTURE_RE);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);


lcd_init();
delay_ms(10);
printf(lcd_putc,"\fstarted...");


while(1){

if(fHit){
   
   printf(lcd_putc,"\fperiod:%lu us",timeC-timeL);
   fHit = 0;
   enable_interrupts(GLOBAL);   
}//if

 
delay_ms(1);
}
}





And this does not work with the 16F877 PIC
Code:
#include <16F877.h> 
                     
#Fuses HS,NOWDT,NOPROTECT,NOLVP, NOBROWNOUT, NOPUT
 
#use delay(clock=16000000)        // Crystal Oscillator Frequency
#use rs232(baud=15625,parity=N,xmit=PIN_C6,   rcv=PIN_C7   ,bits=8,FORCE_SW /* INVERT*/,TIMEOUT=460/*360*/ )
#include <flex_lcd.c>               


#ifndef ON
#define ON           1
#endif

#ifndef OFF
#define OFF          0
#endif


//*************** TIMER ***************************
//RTC variables
#define XTAL_FREQUENCY  16000000
#define TIMER1_FREQUENCY (XTAL_FREQUENCY / 16 ); 
#define TIMER1_OverflowConst ( (1/TIMER1_FREQUENCY ) * 65536) 
#define TIMER1_TicketConst ( (1/TIMER1_FREQUENCY )  )
//**************************************************
#byte pA   =5   //port a   //
#byte pB   =6   //b         //
#byte pC   =7   //c         //
#byte pD   =8   //d         // usb port 8 bits parallel
#byte pE   =9   //port e   //
// *********************************



 
#Define  SetConfigPortA     0
#Define  SetConfigPortB     16
#Define  SetConfigPortC     0
#Define  SetConfigPortD     0
#Define  SetConfigPortE     0
//**************************************************


#bit SpeedPulse=pB.5   
#bit pinB0=pB.0

#define TEST_LED pin_c5

//globals
static int1 fHit = 0;
static int nHits = 1;
int16 timeC = 0, timeL = 0;


 
//****************************************************************
//measure the time from rising egdes then process
//****************************************************************
#int_ccp1
void isr_ext(){
output_low(TEST_LED);
output_high(TEST_LED);
if(nHits==1){
   timeL = ccp_1;
   nHits=2;
}
else if(nHits==2){
   timeC = CCP_1;//get ccp value
   fHit=1;  //flag for processing
   disable_interrupts(GLOBAL);//disable until processed
   nHits=1;//reset nHits to start over
}
}//isr



VOID MAIN(void)

{
 

int8 i = 0;
int16 period = 0, freq = 0;

//setup timer1 to measure pulses
SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_1);
#define DIVIDER 1
//setup ccp1 for interrupt of pulse measurement
CLEAR_INTERRUPT(INT_CCP1);
SETUP_CCP1(CCP_CAPTURE_RE);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);


lcd_init();
delay_ms(10);
printf(lcd_putc,"\fstarted...");


while(1){

if(fHit){
   //printf("\r\nPeriod:%lu",timeC-timeL);
   printf(lcd_putc,"\fperiod:%lu us",timeC-timeL);
   fHit = 0;//processed hit
   enable_interrupts(GLOBAL);   
}//if

   //disable_interrupts(GLOBAL);
delay_ms(1);
}//while
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 07, 2010 1:30 pm     Reply with quote

Capture mode definitely works with the 16F877, and probably works in
your version. It may be a Proteus problem.
amdatlon



Joined: 07 Mar 2010
Posts: 10

View user's profile Send private message

PostPosted: Sun Mar 07, 2010 3:23 pm     Reply with quote

And I know that should work with PIC 16f877, but now I do not understand what was happening.
I changed the version of Proteus, but no change.
Will change and version of CCS , to see what happens.
I think the scheme is good, because with 18f458 works great.
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