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

frequency checking problem....

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



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

frequency checking problem....
PostPosted: Wed Feb 06, 2008 10:04 pm     Reply with quote

Dear sir,
I am using CCS PCM C Compiler, Version 4.052, 40286
In my application i have i/p frequency to pin RC5 of device 16f913.which will
vary from 10hz to 700 hz.My application is, If the frequency is
above 297 hz the rate of count increment is frequency dependent.
and below 297 hz i have to increment count every 1 sec.
But problem is if kept frequency constant at 297hz by using function waveform generator
sometimes it goes to this routine,
Quote:
if(isr_ccp_delta <= 110) // if freq >=297 Hz == 111 count
{
above297Hz = 1;
SETUP_TIMER_1(T1_DISABLED); // TIMER_1 count OFF
set_timer1(0);
setup_timer_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1|T1_CLK_OUT);
sec_counter++;
if(sec_counter >=148) // 1sec == 298 count
{
sec_counter = 0;
min_count++;
BLINK_DUMBEL =~BLINK_DUMBEL; // compliment flag for decimal point.

}


& sometimes it goes to this routine,
Quote:

else
above297Hz = 0;

this means it should have to follow "if" part if freq>= 297 hz & "else"part below 297 hz.
Due to this rate of count incement is not getting correct.
For other frequency it is correct.
Here i am using external clock 32.768 khz for timer1 & same for freqency checking.And internal
clock for internal processing.
Here is part of my programme,
Code:
#include<16F913.h>
#fuses INTRC_IO,NOWDT,PUT,NOMCLR,PROTECT,NOCPD,BROWNOUT,NOIESO,NOFCMEN   
#use delay(clock=8000000)

#int_ccp1
void ccp1_isr(void)
{
int32 current_ccp;      // hold current count of timer1
static int32 old_ccp = 0;   
int32 isr_ccp_delta;

/**************** this routine to initialise & start the timer0 ********************/
if(stop_min_wr== 0)
{
   stop_min_wr = 1;      //flag to initialise timer0 one time whenever freq. start
   clear_interrupt(INT_TIMER0);
   ENABLE_INTERRUPTS(INT_TIMER0);
   SET_TIMER0(18);         // timer0 interrupt for 30.464 msec.
                           // 1 Count=128 Usec,So 256 - 238 ==18.
   SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_256);
}
/***************************** *********************************************************/
current_ccp = (int32)CCP_1;
isr_ccp_delta = (current_ccp - old_ccp) ;
isr_ccp_delta &= 0xFFFFFF;
old_ccp = current_ccp;

if(isr_ccp_delta <= 110)      // if freq >=297 Hz == 111 count
{   
   above297Hz = 1;   
    SETUP_TIMER_1(T1_DISABLED);      // TIMER_1 count OFF
   set_timer1(0);
   setup_timer_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1|T1_CLK_OUT);
   sec_counter++;      
   if(sec_counter >=148)   // 1sec == 148 count
   {      
      sec_counter = 0;
      min_count++;
      BLINK_DUMBEL =~BLINK_DUMBEL;      // compliment flag for decimal point.                                           
   
   }      
}
else                         // if freq. is below 297 hz   
      above297Hz = 0;      
}

void  init_CPU()
{

/**************  PORT SETTINGS ****************/
   PORT_B_PULLUPS(0X00);      
   SET_TRIS_A(0XC0);         // i/p OSC1 & OSC2
   SET_TRIS_B(0X00);
   SET_TRIS_C(0X27);         //VLCD 1,2,3 i/p,FREQ i/p.
   SET_TRIS_E(0X08);         // RE3 i/p to Clear the device EEPROM.
/*************** LCD SETTINGS ********************/
   SETUP_LCD( LCD_MUX14 |LCD_INTRC|VLCD_ENABLE, 2);   
/****************  COMPARATOR SETTINGS  ***************/
   SETUP_COMPARATOR(NC_NC_NC_NC);
/****************  INTERRUPT SETTINGS  *****************/
   ENABLE_INTERRUPTS(GLOBAL);
   clear_interrupt(INT_TIMER2);
   clear_interrupt(INT_TIMER1);
   ENABLE_INTERRUPTS(INT_TIMER1);      //enable timer1 interrupt         

   SETUP_TIMER_1(T1_DISABLED);      // TIMER_1 count OFF      
   set_timer1(0);           
   setup_ccp1(CCP_CAPTURE_RE);       //Capture on rising edge
   clear_interrupt(INT_CCP1);    
   enable_interrupts(INT_CCP1);
   setup_timer_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1|T1_CLK_OUT);
}

_________________
Thank You,
With Best Regards,
Deepak.
kolio



Joined: 06 Feb 2008
Posts: 26

View user's profile Send private message

PostPosted: Fri Feb 08, 2008 5:21 am     Reply with quote

You know your signal generator has an internal error, given itn the specification with some more or less 0.00X % or PPMs.
Also you know that 32768 clock oscillator has some PPM error.
We don't discuss the internal oscillator at all.
Get a frequency counter instrument and check all the frequencies and you'll see that all readings are moving at their rightmost digit positions.
Since you don't have a hysteresis thresholds (error tolerances) around that 297 Hz, the result will depend on the probability.
If possible, you can increase the frequency precision, let's say to 1/10 even to 1/100, but this will not affect the precision of the measurement.
Actually the generator output is not exactly 297 HZ, but 297.1, which means that after 10 cycles, the additional error will produce 298 Hz.

Good luck,
Kolio
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