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

RTCC Problem

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







RTCC Problem
PostPosted: Sun Feb 11, 2007 2:14 pm     Reply with quote

Is this code cause deviation in RTCC time. If yes ? what can I do? My crystal is 4 Mhz internal

Waiting your help


Code:


#define high_start 1000

void akimgerilim()
{
int adcdeger;

set_adc_channel( 1 );
delay_us(1);
value = Read_ADC();
deger=(float)value/51.0;
value=deger;
delay_us(1);
set_adc_channel( 0 );
delay_us(1);
adcdeger=Read_ADC();
max=adcdeger*1.5;
delay_us(1);
}

void besli() {
OUTPUT_HIGH(PIN_D4);
delay_ms(200);
OUTPUT_LOW(PIN_D4);
delay_ms(200);
OUTPUT_HIGH(PIN_C5);
delay_ms(200);
OUTPUT_LOW(PIN_C5);
delay_ms(200);
OUTPUT_HIGH(PIN_D3);
delay_ms(200);
OUTPUT_LOW(PIN_D3);
delay_ms(200);
OUTPUT_HIGH(PIN_D2);
delay_ms(200);
OUTPUT_LOW(PIN_D2);
delay_ms(200);
OUTPUT_HIGH(PIN_C2);
delay_ms(200);
OUTPUT_LOW(PIN_C2);
delay_ms(200);
}

#INT_RTCC

void clock_isr() {

  high_count -= 1;
  akimgerilim();

   if(high_count==0)
  {

   ++seconds;
   high_count=high_start;
   ahtoplam=ahtoplam+sah;
   ah=ahtoplam;
   }
   if(seconds>=60)
   {
   minute++;
   seconds=0;
   }

   if(minute>=60)
   {
   hour++;
   minute=0;
   }


}

main()
{
high_count=high_start;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8|RTCC_8_bit);
do
{
besli();
}while(true);
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 5:15 pm     Reply with quote

With a 4MHz crystal and
Code:
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8|RTCC_8_bit);

you will get 488.28125 interrupts per second, not 1000 interrupts as you have specified.

Even when you set high_start to 488 you will get almost 50 seconds deviation per day because of the rounding. For a really accurate clock have a look at http://www.ccsinfo.com/forum/viewtopic.php?t=26177
kocakaya
Guest







Thanks
PostPosted: Sun Feb 11, 2007 11:47 pm     Reply with quote

How can I calcute this number? What is formula?

Do you think making floating point number division and calling akimgerilim() function in INT_RTCC make any problem? or make any delay in interrupt?

This system calculates amper hour per seconds so I must use this code in RTCC interrupt

When I use RTCC , Timer1 and Timer2 together the system works very slow.And RTCC count 1 minute in two minute .Why? do you think?

The code that I changed is below

Code:

#INT_RTCC

void clock_isr() {

  high_count -= 1;
  akimgerilim();

   if(high_count==0)
  {

   ++seconds;
   high_count=high_start;
   [b]ahtoplam=ahtoplam+max/3600; [/b] "Max is Floating point number"
   }
   if(seconds>=60)
   {
   minute++;
   seconds=0;
   }

   if(minute>=60)
   {
   hour++;
   minute=0;
   }


}


kocakaya
Guest







help
PostPosted: Mon Feb 12, 2007 4:27 pm     Reply with quote

anybody help me in this forum?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Feb 12, 2007 5:06 pm     Reply with quote

Quote:
How can I calcute this number? What is formula?
Check the figure for timer0 in the datasheet of your PIC.
The timer is clocked with Fosc/4 divided by the number you set for the prescaler. An 8 bit timer will generate an interrupt every 256 clocks, a 16-bit timer every 65536 clocks.

Code:
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8|RTCC_8_bit);
This will give an interrupt rate of: 4MHz / 4 / prescaler 8 / 256 = 488.something Hz

Quote:
Do you think making floating point number division and calling akimgerilim() function in INT_RTCC make any problem? or make any delay in interrupt?
Interrupt routines should always be as short as possible. Floating point calculation takes a lot of computing power, but I think you are here still save. Search this forum or internet for an explanation of 'scaled integers' this is much quicker and might be an option for you.

Quote:
When I use RTCC , Timer1 and Timer2 together the system works very slow.And RTCC count 1 minute in two minute .Why? do you think?
This is after you changed the 1000 to 488?
How should we know? You don't show the code for Timer1 and Timer 2.
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