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

16f887 not work

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



Joined: 14 Aug 2007
Posts: 31

View user's profile Send private message

16f887 not work
PostPosted: Sun Jul 12, 2015 2:37 pm     Reply with quote

i use this program by 16f877 and it play good
but when change to 16f887 not work.

Code:

int32 isr_ccp_delta,current_ccp,current_ccp_delta,frequency;

#int_ccp1
void ccp1_isr(void)
{

static int32 old_ccp = 0;

current_ccp = CCP_1;

isr_ccp_delta = current_ccp - old_ccp;

old_ccp = current_ccp;
}


//************************************
void main()
{


delay_us(20);


set_timer1(0);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_ccp1(CCP_CAPTURE_RE);


clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);



while(1)
  {

   disable_interrupts(GLOBAL);
   current_ccp_delta = isr_ccp_delta;
   enable_interrupts(GLOBAL);


   frequency = (2000000 / current_ccp_delta);
   output_d(frequency);

   delay_ms(500);
  }

}
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 2:42 pm     Reply with quote

You have been here long enough to know we need to see the setup
section of the program (CPU include, Fuses, Delay etc.) and the compiler version!
Also, when you say it doesn't work, what does that mean? What does it do?
_________________
Google and Forum Search are some of your best tools!!!!
temtronic



Joined: 01 Jul 2010
Posts: 9178
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 3:41 pm     Reply with quote

One item....

this....

output_d(frequency);

isn't going to sent a 32 bit data to an 8 bit port properly.....


Jay
eng/ IBRAHIM



Joined: 14 Aug 2007
Posts: 31

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 6:20 pm     Reply with quote

the output still zero.at any frequency.
but when use 16f877 the output is reading input frequency

version 4.014
Code:

#include <16F887.h>

 #device PIC16F887
#list
#device adc=8
 
 #FUSES NOWDT                    //No Watch Dog Timer
 #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
 #FUSES NOPUT                    //No Power Up Timer
 #FUSES NOMCLR                   //Master Clear pin used for I/O
 #FUSES NOPROTECT                //Code not protected from reading
 #FUSES NOCPD                    //No EE protection
 #FUSES NOBROWNOUT               //No brownout reset
 #FUSES NOIESO                   //Internal External Switch Over mode disabled
 #FUSES NOFCMEN                  //Fail-safe clock monitor disabled
 #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
 #FUSES NODEBUG                  //No Debug mode for ICD
 #FUSES BORV40                   //Brownout reset at 4.0V
 #FUSES NOWRT                    //Program memory not write protected

 #use delay(clock=8000000)
eng/ IBRAHIM



Joined: 14 Aug 2007
Posts: 31

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 2:13 pm     Reply with quote

when change some lines as below.
the output is reading frequency input correct.
but when freq is not in range 40Hz to 250Hz . the output is incorrect

what is error
input freq rang is 20 to 1000Hz
Code:

int16 isr_ccp_delta,current_ccp,frequency;

#int_CCP2
void  CCP2_isr(void)
{

static int32 old_ccp = 0;

current_ccp = CCP_2;

isr_ccp_delta = current_ccp - old_ccp;

old_ccp = current_ccp;


output_high(PIN_e0);

}


//************************************
void main()
{


delay_us(20);


while(1)
  {

   setup_ccp2(CCP_CAPTURE_RE);                        // Configure CCP1 to capture rise
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1 );         // Start timer 1
   enable_interrupts(INT_CCP2);                       // Setup interrupt on rise edge
   enable_interrupts(GLOBAL);


   frequency = (2000000 / isr_ccp_delta);
   output_d(frequency);

   delay_ms(5);
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19378

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 2:54 pm     Reply with quote

You are running out of counts.

You need to use int32 values, and increment the high byte of the current_ccp in a timer1 interrupt,
eng/ IBRAHIM



Joined: 14 Aug 2007
Posts: 31

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 5:12 pm     Reply with quote

OK run good

now at start freq is zero or no signal output is zero. then freq is vary and output is reading the freq


but when freq return zero or no signal . output not zero and still at last value of freq
how make output is zero if freq return zero??
guy



Joined: 21 Oct 2005
Posts: 291

View user's profile Send private message Visit poster's website

PostPosted: Sat Jul 18, 2015 9:06 am     Reply with quote

Add a flag in the interrupt, and in the main loop wait for the flag.
That makes the output change only when there is an interrupt.
Then, while waiting for this flag check TIMER_1 if time between edges is more than 20Hz / 50ms. If so, set the output value to 0.
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