6-Digit Digital Clock using PIC16F84


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Posts
    31

    Question 6-Digit Digital Clock using PIC16F84

    Hey folks. I'm new to PIC Basic Programming. The only thing that interest me most in shifting to PIC Basic is the ease of the programming structure.

    I'm very much fascinated building the digital clock. The only problem I encountered was programming the TMR1 Interrupt. I tried designing a code using the POOLING process. And I'm not satisfied with the result. What are the considerations in programming the TMR1 interrupt? Anyone who knows how to explain the INTERRUPT programming of PIC Basic in simple terms.

    I really appreciate your generous support.


    Emmanuel

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Go search for OLYMPIC TIMER in this forum for an example of TMR1 and PICBASIC Interrupts. The text describes how it all works.

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    I posted two examples in the "Code Examples" section that show how to make accurate clocks using polling of TMR0. You could switch to TMR1 with a little effort - Look for "Easy and Accurate Clocks without RTC IC"

    The example programs require a 4.000MHz Crystal, use TMRO, but do not require preloading counters. Although pollling is used, you have over 65mSec to do other stuff before needing to return to your overflow check (polling routine). The programs are short as well. Good Luck.

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  4. #4
    Join Date
    Jan 2006
    Posts
    31


    Did you find this post helpful? Yes | No

    Question Computation of 1 Second display interval

    Thanks a lot.

    By the way, what is really the significance of PRESCALER in Timer0? I found examples that use 1:32, then another example that uses 1:8. The goal was to achieve a 1 second increment in clock display. Could you please show to me the proper way to compute the 1 second interval using 4MHz Cristal. I saw some PIC Basic examples that loads certain figures to the TMR0. How did they compute that number?


    Emmanuel
    Don Bosco-Victorias,
    Philippines

  5. #5
    Join Date
    Aug 2003
    Location
    Northern California
    Posts
    14


    Did you find this post helpful? Yes | No

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    With the code I posted in the Example Section (referenced above), the goal was to give the user as much time as possible to do other stuff before needing to update the LCD display, so I went with a 256 prescaler.

    Most TMR0 timers are 8 bit, meaning 256 instructions per flag rollover. A 4.000 Mhz crystal gives a 1.000 uS instruction (uS=microSecond). This means the default time for TMRO to rollover is 256 uS.

    The prescaler increases the TMR0 rollover Flag time:
    Prescale 2 – rollover flag is 2 * 256 = 512 uS
    Prescale 8 – rollover flag is 8 * 256 = 2048 uS
    Prescale 256 - rollover flag is 256 * 256 = 65536 uS.

    At 1.000 uS per instruction, there are 1,000,000 instructions per second. If you do not use a prescaler, then TMRO overflows 1,000,000/256=3906.25 times per second. In code, you just need to keep track of 3906.25 overflows, and 1 second has passed.

    If you use a prescaler of 256, then TMR0 overflows 1,000,000/65,636 = 15.235541 times per second.

    Because neither of these divisions give integers, some people preload the TMRO to start at a given time rather than 0. You can do this but it is more work - it also takes processor time to load the timer which must be adjusted out in order to maintain high accuracy. See Melanie's code (referenced above) for a perfect example of how to make this approach work.

    Since my code allows for colon blink, I tracked 0.5 second time intervals rather than 1.0 second time intervals. Details of the TMRO overflow tracking and math involved are in the code comments at the bottom of the post in the Code Examples Section. The approach I used does not require preloading the timer, but does require keeping track of the residual from the timer overflows (and leads to zero error).

    Again, Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

Similar Threads

  1. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 09:42
  2. Digital clock project
    By astouffer in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th February 2009, 04:00
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21:36
  4. Real Time Clock & Eeprom
    By smart_storm in forum General
    Replies: 8
    Last Post: - 17th February 2006, 20:03
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 21:10

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts