Changing PreScaler during interrupt


Results 1 to 5 of 5

Threaded View

  1. #5
    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