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

RTOS causes pausing of RTCC

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



Joined: 09 Apr 2013
Posts: 14
Location: UK

View user's profile Send private message

RTOS causes pausing of RTCC
PostPosted: Fri Jul 05, 2013 3:06 pm     Reply with quote

PIC:- 18F87K22
CCS :- 4.137

Hi Guys

I was hoping to use the RTOS to run several simple tasks which are triggered at times taken from comparing time from RTCC.
With set values in program. The rate these tasks are running is around 1 second.

But when I add this line of code to use the RTOS, RTCC clock start stuttering ?
Code:
#use rtos(timer=0,minor_cycle=100ms)

I have removed all the code and just read the times in one rtos loop but the RTCC still stutters. I left the pic running over night and the time lose 33 minutes in 24HR ?

Can you use the RTOS with the RTCC and retain time accuracy ?

I have set the following fuses
Code:

#FUSES NOWDT                     //No Watch Dog Timer
#FUSES WDT128                    //Watch Dog Timer uses 1:128 Postscale
#FUSES SOSC_LOW                  //RTTC External clock source
#FUSES HSH                       //High speed Osc (> 4mhz for PCM/PCH)
#FUSES NOBROWNOUT                //No brownout reset
#FUSES BBSIZ1K                   //1K words Boot Block size
#FUSES NOXINST                   //Extended set extension and Indexed
#FUSES RTCOSC_INT               //RTTC internal clock source

Here is the code reading the clock
Code:

void display_time(){

lcd_gotoxy(0,1);
printf(lcd_putc,"  %02u:%02u:%02u" read_clock.tm_hour,read_clock.tm_min,read_clock.tm_sec);
lcd_gotoxy(0,0);
printf(lcd_putc,"  %02u/%02u/%02u D:%u  ", read_clock.tm_mday,read_clock.tm_mon, read_clock.tm_year,read_clock.tm_wday);
}

Code:
#task(rate=500ms,max=10ms) 
void standby(){
display_time();
}

Can you use the two together ?

Thankyou in advance for any help

Dave Question
temtronic



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

View user's profile Send private message

PostPosted: Fri Jul 05, 2013 7:06 pm     Reply with quote

I don't use the RTOS but the RTCC module might be the problem.

What are the specs for it? How good it the xtal you're using? If using say an internal RC network, odds are it's not going to be very accurate over time( no pun intended).
I know that trying to use an internal clock source(RC) is not great for high speed serial communications and i suspect the same may be true for the RTCC.

I use a DS1307 for RTC use,maybe 'old fashsion' but I prefer a discrete external device.

I'm sure others will reply..

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Sat Jul 06, 2013 12:36 am     Reply with quote

Also, key thing to remember is that anything reading values updated somewhere 'else', should really take a copy of the values, and display them from this. Remember that a simple print, of a number, takes a relatively long time (divisions, repeated for each digit). What happens if the code reads the minutes as (say) 59, and then by the time it gets to the seconds, the time has updated to 00:00. The display will suddenly jump 'backwards', showing 59:00....
The sequence should always be:
Either disable interrupts for a moment, copy the remote variable to a local copy, and then enable interrupts and display from the copy, or
copy remote variable to local. Verify copy==remote. If not, loop back and copy again. Only once they match (so no update during the copy), then display from the copy.

Best Wishes
dave10



Joined: 09 Apr 2013
Posts: 14
Location: UK

View user's profile Send private message

PostPosted: Sat Jul 06, 2013 2:01 am     Reply with quote

Hi

Thank you for the reply. I'm using a external 16Mhz xtal as the main system clock and a tuning fork, 'fox' crystal for the RTCC.
Have I set the fuses correctly. I find it difficult to understand the correct fuses for the device from device file and manual.

I should have set system crystal to external 16 Mhz's and using internal multiplier to 64Mhz with,

Code:
 #use delay(clock=64MHZ, restart_wdt)


The RTCC should be set to external clock crystal and timer1 reference being taken from internal clock using.

Code:
#FUSES RTCOSC_INT       


Is this correct ? Question


I have included a footprint for an external clock DS1307 . As I was unsure of the internal clocks performance.
Perhaps I should give this ago ?


Thanks for your time and input
temtronic



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

View user's profile Send private message

PostPosted: Sat Jul 06, 2013 5:49 am     Reply with quote

My vote is for the DS1307. It's a tried and true device,zillions in operation worldwide.I think the RTCC is a peripheral that mchp came up with to try to compete with external RTC chips.Have a good look at the timing specs and what's required to keep it ticking(battery backup).I don't know if there's a separate pin for RTCC power.If not, you need a BIG battery to power the PIC and whole PCB just to keep time alive.The benefits of the DS1307 ... easy to use,easy battery backup,accurate timekeeping,SRAM for storage,interrupt to PIC.Sure it makes the PCB bigger but overall the cost is less.
Also consider your R&D time spent on the RTCC vs. the 1307.Since you've already made space for the DS1307, use it.Nothing is worse than finding out 3 months from now that 'I should have don't it' happens!

hth
jay

+++++++++++++++++
temtronic
Topic is internal RTC & how to use.
Do not hijack thread for Maxim sales pitch.
- Forum Moderator
+++++++++++++++++
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

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

PostPosted: Sat Jul 06, 2013 10:04 pm     Reply with quote

Code:
#FUSES RTCOSC_INT
is incorrect. You should be using
Code:
#FUSES RTCOSC_T1
The internal reference oscillates at 31kHz while the RTC expects a 32.768kHz reference and therefore expect to lose about (32768-31000)/32768*86400/60 = 77minutes per day.
_________________
Andrew
temtronic



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

View user's profile Send private message

PostPosted: Sun Jul 07, 2013 5:21 am     Reply with quote

Sorry...
Having see a few threads about problems with the RTCC and since the OP had alrady designed his PCB to accept the other device,my advice was to go with what works and not waste valuable time on what doesn't.
Since no one has posted a driver for the RTCC, I've concluded it's more trouble than it's worth.

jay
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

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

PostPosted: Tue Jul 09, 2013 7:44 am     Reply with quote

There's no need for anyone to post a driver for the RTCC, it's built into CCS. See setup_rtc() and the various rtc_XXX() functions.
_________________
Andrew
temtronic



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

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 7:53 am     Reply with quote

hmm...according to the help info....

Configures the Real Time Clock and Calendar module. The module requires an external 32.768 kHz Clock Crystal for operation

...so you MUST have an external 'clock crystal', can't run off the internal 31KHz clock.
dave10



Joined: 09 Apr 2013
Posts: 14
Location: UK

View user's profile Send private message

PostPosted: Fri Jul 12, 2013 1:45 pm     Reply with quote

Hi Guys

Thankyou for your help. RTCC been running for a week and is still pretty accurate. I'll have a play with the external RTC when everything else is finished !

Thanks Dave Laughing
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