timer1 help


Closed Thread
Results 1 to 4 of 4

Thread: timer1 help

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    If you run out of Ticks then you simply run out of Ticks... because somebody will come along and say "How can I have Timer1 count an HOUR or a DAY or a WEEK"?

    Eventually you run out of capacity for the Registers for the Time period you wish to count. There is nothing you can directly do about that...

    So the usual solution is to preset the Timer to count say 0.5 Seconds (which is within range), and when the period has elapsed you simply increment a BYTE. When that BYTE has incremented to 12 (for 12 x 0.5 Seconds = your desired 6 Seconds), zero the byte (for the next 6 Second timing period) and toggle your LED. So basically you are supplimenting Timer1 with another eight or sixteen bits, but those you have to increment yourself rather than have it done for you.

  2. #2
    Join Date
    Aug 2009
    Posts
    63


    Did you find this post helpful? Yes | No

    Default

    ok thank you mel,

    additionally i just wanna check my calcs are along right lines...

    ive timed the blinks and it takes 19 seconds for 10 "on and offs". on is 6 cycles and off is 6 cycles, so total is 120 cycles.

    each cycle is 65536 bits.. so 120x65536/19 = 410000 hz

    Fosc/4 means that its 410,000x4 = 1,640,000 hz

    this seems a bit of a random clock frequency? especially when the deault internal oscialltor is 4mhz and im running the actual pic itself on an external 20mhz oscillator.

    maybe i have missed something, which is the most likely thing but i cant see it at the moment

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


    Did you find this post helpful? Yes | No

    Default

    Well, I was going to go through your code and verify your Timer settings, but not knowing what chip you are using that makes it kinda difficult.

    So, 'assuming' you are genuinely running at 20MHz (this now depends on your OSC and Configuration setting for your chosen PIC - and if you don't get that correct then everything is screwed thereafter...)...

    I tick = 200nS (FOsc/4), so an empty 16-bit Timer will execute in 65536 x 200nS = 13.1mS then multiplied by any scalers you have previously enabled.

    If you think your PIC speed is running oddly, then a simple blinky with PAUSE 10000 and your wristwatch should verify that your speed settings (which includes the DEFINE OSC 20) are all correct give or take.

Similar Threads

  1. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 12:49
  2. Help with TIMER1 + SLEEP
    By Yodoad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2009, 16:07
  3. Time Period of Timer1
    By arnol34 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 01:31
  4. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 02:24
  5. Use of Timer1 with 16F819
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th January 2005, 17:25

Members who have read this thread : 0

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