Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Reply To: Using 32khz crystal as second oscillator

Home Forums Flowcode Project Discussions Using 32khz crystal as second oscillator Reply To: Using 32khz crystal as second oscillator


Bitahwa Bindu

Hi. Sorry for the late reply.

For you to build a clock, any crystal frequency can be used whether internal or external depending on your need and understanding the advantages of ones vs the others.

Interrupts occurs when the timer overflows. A count is made internally based on clock inputs (clock input can be internal or external) and the pre-scaler property (A prescaler divides down the clock signals used for the timer giving reduced overflow rates. The rate can be set to a number of possible values. The exact values are chip dependent).

When the count reaches a certain point it overflows back to 0 triggering an Overflow event. This event can then be used to call a macro. Timer overflow interrupts are called repeatedly at the Interrupt time interval making them very useful for time based events.

The exact properties available for a timer interrupt are device and timer dependent. As such the timer overflow dialogs may vary from device to device and from timer to timer.

As I replied to you on YouTube, there is an example of a software clock using timer0 in Flowcode LCD component examples.

They are using Timer0, Clock source Internal Oscillator, Prescaller: 1:128 giving an interrupt frequency of 150Hz, as time is the inverse of frequency, to get 1 second or 1 Hz, they count each time an interrupt as occurs until this counter =150 to get 1 second. Once you have 1 Second, you have your time base for your clock.

You can follow the same procedure but instead of using timer 0, use timer 1. In Flowcode, once you select Timer 1 from the Timer icon properties, you have option to select your clock source between Transition between T1CK1 pin, Internal clock (Fosc/4), Internal Clock (Fosc) and of course 32.768KHz XTAL T1CK1/T1CK0

Why chose external vs internal?

There are many advantages of using external clock for time based compared to internal clock. You can google to learn more, but usually external clocks are more precise and temperature tolerant better than using internal clocks. This will help you not to lose more seconds per day thus making your clock precise.

Why use the 32.768KHz?

The frequency 32768 Hz (32.768 KHz) is commonly used, because it is a power of 2 (215) value. And, you can get a precise 1 second period (1 Hz frequency) by using a 15 stage binary counter.

As current consumption has to be as low as possible to preserve battery life. The low the frequency the low the current consumption. So, this frequency is selected as a best compromise between low frequency and convenient manufacture with market availability and real estate in term of physical dimensions while designing board, where low frequency generally means the quartz is physically bigger.