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!

Using 32khz crystal as second oscillator

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

This topic contains 4 replies, has 2 voices, and was last updated by  Bitahwa Bindu 4 months, 2 weeks ago.

  • Author
    Posts
  • #3190

    santanu
    Participant

    Hi, i wanted to make a digital clock using timer1 interrupt to count 1sec and keep updating the time. So to get precise time we need the crystal 19.66Mhz from which the timer1 freq of 150hz can be obtained but this crystal is not available to me, so i have to use the 32khz crystal to get exact freq of 75hz but the pic has to be run by a higher frequency crystal and the 32khz is used as an secondary oscillator at t1oso and t1osi. Having seen your example at https://www.google.co.in/amp/s/www.studentcompanion.co.za/digital-clock-using-pic-microcontroller-interrupt-xc8/amp/ can you give a little insight as to how this can be implemented in flowcode. Thank you.

  • #3191

    Bitahwa Bindu
    Keymaster

    Can you post Your Flowcode Project that you have made so far which is not working?

  • #3192

    santanu
    Participant

    I just want to know how to use a 32khz crystal along with an external crystal (20mhz) . Where the external crystal is use to drive the pic and the 32khz crystal is use in timer1 for time keeping.

     

  • #3193

    santanu
    Participant

    My question is similar to the one asked in the foram< http://www.matrixtsl.com/mmforums/viewtopic.php?t=8852 >.but the explanation is a bit vague. Can you explain what i need to do?

  • #3195

    Bitahwa Bindu
    Keymaster

    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.

You must be logged in to reply to this topic.