Searching \ for 'TMR0 Questions' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=tmr0+questions
Search entire site for: 'TMR0 Questions'.

Truncated match.
PICList Thread
'TMR0 Questions'
1998\09\07@222833 by Sean Breheny

face picon face
Hi all,

I recently received an email from one of the spanish speaking members of
the PICLIST who had a few questions about TMR0. He asked me if I would
either answer them, or translate his email and send it to the list. I tried
to answer them as best I could, but I figured I ought to send a copy to the
list as well to see if there are any further suggestions. The original
sender (Jose) and I would appreciate it if you would take a look at the
questions. What follows is the original question and my response translated
into english:



~~~~~ ORIGINAL QUESTION ~~~~~

>Date: Fri, 04 Sep 1998 10:21:37 +0200
>X-PH: spam_OUTV4.1TakeThisOuTspamcornell.edu (Cornell Modified)
>From: Jose Antonio Gracia <.....jgraneKILLspamspam@spam@colon.net>
>X-Mailer: Mozilla 4.03 [es] (Win95; I)
>To: "Sean Breheny (Piclist EE.UU esp)" <shb7spamKILLspamCORNELL.EDU>
>Subject: Peticion de ayuda
>

[SOME SNIPPED]

I am now starting to program pics, and I have a series of doubts that I
would like to resolve.  If you know the answer, good. If you don't, fine,
but if you would, please transfer this to the list translated to english.

In Spain, I found two books about this topic, en them there appears a line
which says:
"when TMR0 is set by loading it with a value, two clock cycles are lost for
synchronization."

If I want to make a clock with a 1 MHz crystal, the frequency of
instruction execution is 250,000 per second. To obtain a frequency of 1
tenth of a second (sic), I should adjust the prescaler to 5(count up to
250) a later add a counter to count up to 100.

The question is:

Does one need to load TMR0 with 4 every two times to compensate for the two
lost cycles?
If ones adds (maybe he meant changes) the prescaler too are two cycles lost?
Does the prescaler get reset (when changing TMR0, I presume)?
Can you suggest to me more resources (about PICs)?


I wrote to the authors of those books and they told me that they don't know!

[CLOSING SNIPPED]

>                Jose Antonio Gracia
>
>.....jgraneKILLspamspam.....colon.net
>http://www.geocities.com/SiliconValley/Pines/7097

~~~~~ MY RESPONSE ~~~~~

I don't think that the prescaler can be set to 5. The possible values are
1,2,4,8,16,32,64,128,256. These values come from the bits in the OPTION
register. If you have a prescaler of 1, count up to 250 in TMR0, and later
have a counter (software postscaler) to count up to 100, then you have a
frequency of 10 Hz. For a frequency of less than 10 Hz, there are many
posibilities. You can use a crystal of a frequency less than 1 MHz. Or, if
you need the main chip clock to be 1 MHz, you can use a second crystal in
an oscillator feeding TMR0 directly. There are 32kHz watch crystals made
especially for slow clock rates.

Now to the specific questions:

Yes, you should load TMR0 with 2+value to compensate for the lost cycles(if
they matter in your application). For example, to clear TMR0, load it with 2.

I don't know if you loose any cycles if the prescaler is changed. I would
guess not. I will ask the PICLIST.

Yes, if you write to TMR0, the internal prescaler value gets reset, but not
the division factor.In other words, you don't need to reload the OPTION
register when you change TMR0, but the prescaler/TMR0 system gets reset.

Well, you know better than I about books and web sites in spanish about
PICs. You ought to make an effort to read the PIC microcontroller
datasheets from Microchip.

[ENDING SNIPPED]




+--------------------------------+
| Sean Breheny                   |
| Amateur Radio Callsign: KA3YXM |
| Electrical Engineering Student |
+--------------------------------+
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
EraseMEshb7spam_OUTspamTakeThisOuTcornell.edu  Phone(USA): (607) 253-0315 ICQ #: 3329174

1998\09\08@005557 by tjaart

flavicon
face
Sean Breheny wrote:

{Quote hidden}

My stategy would be to use a /16 prescaler. You now have
15625 counts to handle. If you set the TMR0 to 132 on every
overrun, you get another division of 125 (255-125+2). Count
125 of these overruns.

Take care to set the TMR0 = 132 immediately after overrun.
If you can't, add the extra program cycles to TMR0.

An easier approach could be to let the TMR0 overrun 61
times per second. This gives you a 'second' of 0.999424s.
A 'minute' becomes 59.96544s. By periodically increasing
the overrun count, you can adjust by 1/(250000/(16*256))
= 0.016384s per extra overrun.

--
Friendly Regards

Tjaart van der Walt
@spam@tjaartKILLspamspamwasp.co.za

|--------------------------------------------------|
|                WASP International                |
|R&D Engineer : GSM peripheral services development|
|--------------------------------------------------|
|SMS KILLspamtjaartKILLspamspamsms.wasp.co.za  (160 chars max)|
|     http://www.wasp.co.za/~tjaart/index.html     |
|Voice: +27-(0)11-622-8686  Fax: +27-(0)11-622-8973|
|          WGS-84 : 26¡10.52'S 28¡06.19'E          |
|--------------------------------------------------|

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