Newb timer problems


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Hey GeoJoe, thanks for the input, I've mad ethe changes but still no joy :-s - the intcon bits are the same according to the data sheet "The T0IF bit
    (INTCON<2>) must be cleared in software by the
    Timer0 module Interrupt Service Routine before reenabling
    this interrupt."
    but no luck yet, do you think it might be something to do with running an external clock?
    also - how do i place the code in a special little code box on here??

    @ DEVICE PIC16F676, XT_OSC, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF

    TRISA = %000000
    TRISC = %101100

    ANSEL = %10000000 'enable ch7 analog
    CMCON = 7 'Disable comparitor
    OPTION_REG = %00010111
    INTCON.2 = 0 ' Clear Timer0 int flag
    INTCON.5 = 1 ' Enable Timer0 int
    TMR0 = 0 ' Set TMR0 to 0.

    ON INTERRUPT GOTO int

    red var PortC.0
    green var PortA.2
    PDWN var PortC.1
    DAT var PortC.2
    pwr var PortC.4
    Switch var PortC.5

    clear
    PortA = 0
    PortC = 0

    Start:

    goto start

    disable
    int:
    TMR0 = 0
    toggle red
    intcon.2 = 0 ' reset interupt flag
    resume
    enable

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi George,

    Try this ...
    Code:
    Start:
        PAUSE 1
    goto start
    Or, this ...
    Code:
    Start:
        @ CLRWDT
    goto start
    Or, maybe ...
    Code:
    @ DEVICE PIC16F676, XT_OSC, WDT_OFF, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF
    <br>
    DT

  3. #3
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Thanks DT - yr a genius, the first thing i did worked so didn't try the others. Why did it need that pause for it to work - i would have thought it would have just cycled around in the loop

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by George View Post
    ..., the first thing i did worked so didn't try the others. ...
    Well that's unfortunate.
    Trying the other 2, may have answered your question.

    Why did it need that pause for it to work - i would have thought it would have just cycled around in the loop
    It does "just cycled around in the loop".
    But, there's nothing in there to clear the WatchDogTimer. And without it, the processor will reset every ~18ms.
    Timer0 was set up with 1:256 prescaler, so it would interrupt after 65.536 ms had passed. But it never made it that far.

    PAUSE, automatically clears the WDT every so often, so that caused it to work.

    The second example just clears the WDT by using the ASM statement CLRWDT.

    And the third example turns the WDT OFF so that it doesn't need to be cleared.

    Any one of the three examples should have made it work.
    <br>
    DT

  5. #5
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by Darrel Taylor View Post
    Hi George,

    Try this ...
    Code:
    Start:
        PAUSE 1
    goto start
    Or, this ...
    Code:
    Start:
        @ CLRWDT
    goto start
    Or, maybe ...
    Code:
    @ DEVICE PIC16F676, XT_OSC, WDT_OFF, MCLR_OFF, PROTECT_OFF, BOD_ON, CPD_OFF
    <br>
    Quote Originally Posted by George View Post
    Thanks DT - yr a genius, the first thing i did worked so didn't try the others. Why did it need that pause for it to work - i would have thought it would have just cycled around in the loop
    Yes i have the same question:
    Why was that "pause 1" needed for it to work??

  6. #6
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Just after I turned the wdt off and got rid of the pause 1 and it worked also, detailed knowlegde certainly helps with these things doesn't it

    Cheers for your help

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  3. Timer + rc5
    By naga in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th November 2009, 07:56
  4. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  5. timer interupt help 16f73
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd July 2005, 08:41

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