Changing PreScaler during interrupt


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    I am using a F737 which shares the pre-scaler between the Watchdog and TMR0.

    Re-reading the data sheet I can see where I was getting a bit confused <code>(From the datasheet)
    When assigned to the Timer0 module, all instructions
    writing to the TMR0 register (e.g., CLRF 1, MOVWF 1,
    BSF 1,x....etc.) will clear the prescaler. When assigned
    to WDT, a CLRWDT instruction will clear the prescaler
    along with the Watchdog Timer.
    The prescaler is not
    readable or writable.
    </code>

    I was thinking Pre-Scaler meant the ratio rather than the count. Looks like it should work. Might be time to break out the breadboard and see what happens...

    bill
    Last edited by bcd; - 1st May 2008 at 09:11. Reason: Spelling...

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bcd View Post
    I am using a F737 which shares the pre-scaler between the Watchdog and TMR0.....................
    I was thinking Pre-Scaler meant the ratio rather than the count. Looks like it should work. Might be time to break out the breadboard and see what happens...
    bill
    Yep, same deal with the 18F4620, and probably most other PICs. I think you got the picture.

  3. #3
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    Its a bit messy - but it works ! Tomorrow we optimise !
    This is a snippet that shows how to change the Prescaler value from within the interrupt routinue using Instant Interrupts.

    Code:
    DEFINE OSC 20
    
    rs_led      var portb.7
    led          var portc.4 
    
    loops       var byte    ' count round the loop to load prescaler
    
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,  _doBAM,   PBP,  yes
        endm
        INT_CREATE     ; Creates the interrupt processor
    ENDASM
    
    OPTION_REG = %11010000 'Set TMR0 Prescaler to 2, leave RBPU alone
    
    TMR0 =  158 ' preload with 158 to give 21uS interrupts
    loops = 0
    
    ' interrupt routinue
    doBAM:
    toggle rs_led
    if loops > 6 then 
    loops = 0
    else
    loops = loops+1
    endif
    option_reg.0 = loops.0
    option_reg.1 = loops.1
    option_reg.2 = loops.2
    TMR0 =  158
    @ INT_RETURN
    bill.
    Last edited by bcd; - 1st May 2008 at 13:50. Reason: Made the code snippet make sense

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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