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

Timer based Real Time Clock (RTC)
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
andrewg



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

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

PostPosted: Sat Dec 18, 2010 12:55 am     Reply with quote

You don't have any delays in any interrupt handlers?
_________________
Andrew
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Sat Dec 18, 2010 8:55 am     Reply with quote

Not in the code I just posted. The only delay was in Main.
My real code has some delays in timer2 int, but I can probably get rid of those. The delay in main will be hard to get rid of, I plan on taking sensor readings as close to exactly once a second as possible so I use a delay to tune the timing. Does it make sense that delay messes up the timer? I thought it counted clock cycles and kept counting no matter else was going on.
Ringo
_________________
Ringo Davis
andrewg



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

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

PostPosted: Sun Dec 19, 2010 12:31 am     Reply with quote

The timer will keep counting, but if your delays are long enough to miss two interrupts, the second interrupt will not be counted. This is the time between interrupts, or in your case, a little over 13ms.

If interrupts are disabled for longer than that (which applies inside interrupt handlers), then you will lose time. Delays in your mainline are OK, so long as you haven't disabled interrupts at the same time you're doing the delay.
_________________
Andrew
ünloco



Joined: 02 Oct 2011
Posts: 12
Location: Tunisia

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

PostPosted: Thu Nov 17, 2011 11:30 am     Reply with quote

Should days and months be reset to 1 rather than 0 ?? :p
Thanks a lot for the code Smile)
_________________
for(;;);
ckielstra



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

View user's profile Send private message

PostPosted: Thu Nov 17, 2011 6:41 pm     Reply with quote

Yes, days and months should start at 1. Nice find!
A shame no one else noticed this bug in the last 5 years. Embarassed
I'll edit the posted code.
salanki



Joined: 28 Apr 2012
Posts: 2
Location: New York, NY

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

Other interrupts
PostPosted: Sat Apr 28, 2012 11:26 am     Reply with quote

How is this affected by other interrupts? Say I have an RS232 interrupt that executes fairly frequently. Would the timer interrupt still be executed timely? I would want to increase the granularity of this timer to 1/10 of a milisecond.
ckielstra



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

View user's profile Send private message

PostPosted: Sat Apr 28, 2012 3:43 pm     Reply with quote

The special feature of this algorithm is that it is accurate over a long period of time, unaffected by other interrupts happening in between. A second feature is that you can use whatever crystal frequency you want, i.e. it doesn't have to be an exact multiple of the clock dividers avoiding the 'funny' clock frequencies like 32768Hz.

A disadvantage is that for short periods of time it is possible the clock is reporting the time a little bit too late. So the moment the clock says a new second is started may be a little off but the total number of seconds will be correct in the long term. This means you can not use the timer as an accurate timing source for starting a precisely timed action if that is what you intend to do.

I'm not sure what you want to do with the 0.1ms timer but it sounds wrong for this algorithm. If one of your other interrupts would ever take more than 0.1ms, then your clock would be missing a tick and would run behind.

For accurate timing in the 0.1ms range I would recommend to use one of the hardware timers directly. Just make sure the RS232 interrupt is never going to take more than 0.1ms. If that can't be guaranteed you could use a PIC18 processor which has the feature of High Priority interrupts that can be used to interrupt a lower level interrupt like your RS232.

I hope this answers your question?
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Awesome!
PostPosted: Sat Jul 14, 2012 3:39 pm     Reply with quote

I just used your Timer ISR for my program... but im driving it from TMR1 internal 32.768 Osc...

i gotta say, beautiful work man... i got this running in less than 2 minutes....

you just saved me some cash on RTC chips...

THANK YOU! and great work!


G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
tnt.vlad



Joined: 28 May 2012
Posts: 1

View user's profile Send private message

thx for the code
PostPosted: Wed Aug 21, 2013 1:52 pm     Reply with quote

nice code! works perfectly!
tested with 16f628a, at the beginning i tried with internal osc at 4MHz, but the error was too big, like 1 second/min with one chip, 0.5 sec/min with another 2.5 sec/min.....but with an external osc at 20MHz it is simply perfect
thank you
mr.njt



Joined: 30 Oct 2013
Posts: 4

View user's profile Send private message

PostPosted: Fri Nov 08, 2013 2:43 am     Reply with quote

I used that codes in my pic24fj256ga006 based project. I am simulating the circuit on Proteus VSM.

Proteus says :

-[PIC24] Invalid word adress range 0x0002ABF8-0002ABFF in program data.
-Disassembly requested for an invalid number of bytes.

Does someone know how i can solve that problem?

Thx.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Nov 08, 2013 4:18 am     Reply with quote

Simple. Don't use Proteus.

Read the comments about ISIS/Proteus on this forum.

Mike
yzq707



Joined: 04 Jul 2014
Posts: 1

View user's profile Send private message

PostPosted: Fri Jul 04, 2014 9:22 pm     Reply with quote

i am looking for CCS C code example
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Jul 05, 2014 3:43 pm     Reply with quote

CCS code is provided in this thread.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
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