Post Reply 
[34S] Ticks
03-24-2014, 07:34 PM
Post: #3
RE: [34S] Ticks
(03-24-2014 03:57 PM)Tugdual Wrote:  Quick question, how do you achieve a 0.1s timer with 32768Hz cristal?
You cannot divide by 3276,8?

My next question would be: can we change the timer resolution? I guess not otherwise I'm sure the stopwatch would be more accurate and I this would probably drain more energy from the batteries.

Monte has given one possible explanation for the mystery.

Here is what I did in the 34S:

The Atmel chip has several oscillators, one of which is the 32KHz clock. The quartz crystal is just an option to increase its accuracy. The processor frequency is created by multiplying the 32KHz clock with help of a PLL which can be configured. In fact, most of the power saving is done by reprogramming the PLL to adapt the speed to the present needs. A running program obviously needs a higher processor speed than manual digit entry.

The ticks pose a problem here: you cannot count on regular timer interrupts if you change the input frequency randomly. That's why I use the LCD driver circuit (which is part of the Atmel chip) to create the tick interrupt. It's driven by the 32kHz oscillator. The interrupt is called every 640 cycles which results in roughly 51 interrupts per second. When a crystal is installed, an elaborate count down scheme is used to reach the 100ms interval:

Code:

        /*
         *  Count down to next 100ms user heart beat
         */
        if ( --UserHeartbeatCountDown == 0 ) {
                /*
                 *  Service the 100ms user heart beat
                 */
                user_heartbeat();

                if ( Xtal ) {
                        /*
                         *  Schedule the next one so that there are 50 calls in 5 seconds
                         *  We need to skip 3 ticks in 128 cycles
                         */
                        if ( Heartbeats ==  40 || Heartbeats ==  81 || Heartbeats == 122 ) {
                                UserHeartbeatCountDown = 6;
                        }
                        else {
                                UserHeartbeatCountDown = 5;
                        }
                }
                else {
                        /*
                         *  Without a crystal a less accurate timing is good enough
                         */
                        UserHeartbeatCountDown = Heartbeats & 1 ? 4 : 5;
                }
        }

Feel free to submit any optimizations. Wink

One reason for an inaccurate clock is the quartz oscillator. I've fitted some stock capacitors without thorough research if they are really suited for the crystal installed. If you have an oscilloscope you may verify it for yourself (I do have an oscilloscope but I didn't try to measure the frequency.)

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
[34S] Ticks - Tugdual - 03-24-2014, 03:57 PM
RE: [34S] Ticks - Monte Dalrymple - 03-24-2014, 04:28 PM
RE: [34S] Ticks - Marcus von Cube - 03-24-2014 07:34 PM
RE: [34S] Ticks - GeorgeOfTheJungle - 05-29-2014, 09:43 PM
RE: [34S] Ticks - Tugdual - 03-24-2014, 10:09 PM
RE: [34S] Ticks - jebem - 05-17-2014, 11:15 AM
RE: [34S] Ticks - Paul Dale - 05-17-2014, 11:42 AM
RE: [34S] Ticks - walter b - 05-17-2014, 12:18 PM
RE: [34S] Ticks - jebem - 05-17-2014, 10:47 PM
RE: [34S] Ticks - walter b - 05-18-2014, 10:24 AM
RE: [34S] Ticks - jebem - 05-18-2014, 01:09 PM
RE: [34S] Ticks - Thomas Klemm - 05-18-2014, 05:26 PM
RE: [34S] Ticks - jebem - 05-18-2014, 08:37 PM
RE: [34S] Ticks - Thomas Klemm - 05-20-2014, 11:45 AM
RE: [34S] Ticks - Thomas Klemm - 05-21-2014, 11:47 AM
RE: [34S] Ticks - Marcus von Cube - 05-22-2014, 05:58 PM
RE: [34S] Ticks - jebem - 05-22-2014, 07:19 PM
RE: [34S] Ticks - walter b - 05-23-2014, 04:51 AM
RE: [34S] Ticks - Marcus von Cube - 05-24-2014, 07:56 PM
RE: [34S] Ticks - Paul Dale - 05-22-2014, 11:01 PM



User(s) browsing this thread: 1 Guest(s)