Searching \ for '[PIC]: Using dual-clock chip as a RTC' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=clock
Search entire site for: 'Using dual-clock chip as a RTC'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Using dual-clock chip as a RTC'
2003\06\14@235153 by Alex Kilpatrick

flavicon
face
The datasheet for the 18F1220 describes how to use it as a RTC with an
external 32.768K crystal.  I understand the basic operation to be as
follows:
1) Pre-load timer1 so it overflows every second
2) In ISR, increment a set of second, minute, hour values to maintain a
time
That all makes sense.  But what I don't understand is how you integrate
that ISR with other things that may be happening on the chip.  For
example, if I have a time-sensitive asynchronous serial routine, I would
expect that I would have to disable interrupts so that I didn't mess
that up.  And if I disable interrupts, won't it throw the clock off?
Specifically, I am thinking about doing irDA with a 4 Mhz clock.  A irDA
serial pulse is only two instructions long at that rate.
Thanks for your help.
Alex

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\06\15@021128 by Robert Rolf

picon face
If you have such a time sensitive loop, disable interrupts, assuming that you
can be COMPLETELY done the loop in less than a second (or a serial character time).
The Timer1 overflow will be 'pending' when you reenable that interrupt, and
will just be serviced late.

Also, don't do all of the TOD incrementing in the ISR. Set a flag that your
main background loop will see, and then return. That way the slow TOD increment
cascade takes place at background priority.

I use a counter flag in the TOD ISR, and simple increment it each int.
If the background finds that the counter is non-zero, it adds it to the
TOD seconds, clears the flag, and wraps TODS modulo 60.
That way the background can miss several updates, but still 'catch up'
when it has cycles available to it. There is a tiny window of time
between where the add occurs and the counter gets cleared, where the Timer
could interrupt, and be missed, but since my RTC is not that accurate, the
loss of a tic or two over many days of operations is irrelevant.
If that bothers you, turn off int's just before the add, and back on
right after the following clear.


Alex Kilpatrick wrote:
{Quote hidden}

Then you have a high probability of missing pulse if you're doing -anything-
else during the stream. What about an external shift register to get you
8x more clock cycles to work with?


Robert

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu>

2003\06\15@084358 by Olin Lathrop

face picon face
> That all makes sense.  But what I don't understand is how you integrate
> that ISR with other things that may be happening on the chip.  For
> example, if I have a time-sensitive asynchronous serial routine, I would
> expect that I would have to disable interrupts so that I didn't mess
> that up.  And if I disable interrupts, won't it throw the clock off?

As long as you disable interrupts around short sections of code that are
much shorter than the interrupt period, no problem.  The interrupt
condition may get set during the time interrupts are off, so the interrupt
will be taken immediately after they are re-enabled.

Temporarily disabling interrupts is common for atomically accessing a
collection of state that can be altered by an interrupt routine.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu>

2003\06\15@143853 by Alex Kilpatrick

flavicon
face
> -----Original Message-----
> From: Robert Rolf [.....robert.rolfKILLspamspam.....UALBERTA.CA]
> Sent: Sunday, June 15, 2003 1:10 AM
> To: EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU
> Subject: Re: [PIC]: Using dual-clock chip as a RTC
>
>
> If you have such a time sensitive loop, disable interrupts,
> assuming that you can be COMPLETELY done the loop in less
> than a second (or a serial character time). The Timer1
> overflow will be 'pending' when you reenable that interrupt,
> and will just be serviced late.
>
Ah, ok.  I guess I didn't understand exactly how the timers worked.  For
some reason, I was assuming that when they overflowed, then they waited
until the interrupt was serviced before continuing counting.  Now that I
write that down, it doesn't make much sense.  :-)

So you may end up with a sequence like this:

Int1: 0 sec
Int2: 1.001 sec
Int3: 1.999 sec

So the interrupts aren't neccesarily right on 1 sec marks, but the
overall time measurement doesn't drift.  So, assuming you had a perfect
crystal, you would only be off by at most 1 second at any particular
time measurement.

For my application, I don't need a high level of precision, but I do
want my time measurement to not drift over time.

Alex

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...