interrupt trouble @.1ms


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51

    Default interrupt trouble @.1ms

    i tried to get an interrupt at .1ms using dt-ints.

    i used 16f877a at 4MHz and timer1 1:1 prescaler , want to toggle a led that connected to portb.7 to test interrupt.

    timer1 pre-load value is 65437. The signal must be 5KHz , but it is about 2.4KHz.

    The code is below.What am i missing or what is the mistake?

    Code:
        INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
        INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
        
        
        LED     VAR PORTB.7
        
        OUTPUT  LED
        
        ADCON1      = 7
        
        
        
        
        
        ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler     TMR1_INT,       _TMR1_INT, PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
        ENDASM
    
    @ INT_ENABLE  TMR1_INT     ; enable Timer 1 interrupts
    
    
        T1CON = %00000101                ; Prescaler = 1, TMR1ON
    
        TMR1L = $9D         ; TMR1 = 65437
        TMR1H = $FF
    
        
        MAIN :
        
        PAUSE 50
       
    GOTO MAIN
        
        
        TMR1_INT :
        
        TMR1L = $9D
        TMR1H = $FF
        
        TOGGLE LED
    @ INT_RETURN

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    When you load the timer, you have to load the High Byte first, then Low Byte.
    Charles Linquist

  3. #3
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    When you load the timer, you have to load the High Byte first, then Low Byte.
    thanks charles for your quick reply.

    i tried to load highbyte of timer1 first , but it is not the aid.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

    You forgot to take the reload time into account ...

    from MrE calc. I get 65443 ...

    Why not use a 8 bits timer w/ preload = 63 ???

    Alain
    Last edited by Acetronics2; - 24th March 2009 at 17:51.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    Why not use a 8 bits timer w/ preload = 63 ???

    Alain
    i used timer0 , the problem is the same.

    i used darrel taylor's intterrupt system before , but the interrupt durations was so long about 20ms there was no problem.

    but when i want to use it 100 microseconds this problem occurred.

    thanks for your advice.

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    1. I would remove "PAUSE 50" from main loop.
    2. To load the timer, have a word variable like timex.
    For example:

    Code:
    TimeX VAR WORD
    
    TimeX = 65437
    
    TMR1L = TimeX.LowByte
    TMR1H = TimeX.HighByte
    3. Why not use TMR0 ?


    ----------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    1. I would remove "PAUSE 50" from main loop.
    ----------------
    I CHANGED IT TO "PAUSEUS 5" THE FREQUENCY OF SIGNAL IS SAME.


    Quote Originally Posted by sayzer View Post
    3. Why not use TMR0 ?
    ----------------
    I usually do this with tmr1 , there is not a special reason.
    i used tmr0 too , but the problem is going on.

    İLGİN İÇİN ÇOK TEŞEKKÜR EDERİM SAYZER.

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Using a PBP interrupt eats hundreds of instruction cycles just saving & restoring PBP system
    variables.

    You can get much more accurate timing, and save hundreds of instruction cycles with a
    CCP Compare interrupt & .asm interrupt handler.

    Try something like this;
    Code:
      INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
      INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
        
        LED VAR PORTB.7
        OUTPUT LED
        LED = 1    
        ADCON1 = 7 
      
        ASM
    INT_LIST  macro    ; IntSource, Label,  Type, ResetFlag?
        INT_Handler     CCP1_INT,   CCP_INT, ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
        ENDASM
    
    @ INT_ENABLE  CCP1_INT  ; enable Compare interrupt
    
        T1CON = %00000001   ; Prescaler = 1, TMR1ON
        CCP1CON = %00001011 ; compare mode, int when TMR1 = CCPR1
        CCPR1L = 100        ; interrupt every 100 instruction cycles
        CCPR1H = 0    
       
    MAIN:
        PAUSE 50
        GOTO MAIN
        
    ASM
    CCP_INT
        MOVLW  0x80     ; W = %10000000
        XORWF  PORTB,F  ; toggle RB7 on each interrupt
        INT_RETURN
    ENDASM
    This should give you a 5kHz signal on RB7, with Timer1 reset by hardware. To change the
    frequency, just change the value in CCPR1 high & low registers.

    See analyzer screen capture attached.
    Attached Images Attached Images  
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    it is realy great bruce.

    I HAVE TO USE ASM INTERRUPTS AFTER THAT.

    The frequency is 5KHz.

    And where can i find some sample codes to use asm interrupt routines in PBP.

    thank you very much..

  10. #10
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    For examples of using assembler interrupts look at some of Darell Taylors code, and look
    through a few of the examples on MeLabs website.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. 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
  2. Replies: 10
    Last Post: - 2nd May 2009, 07:42
  3. Very Trouble with 8722 Interrupt
    By smarino in forum mel PIC BASIC
    Replies: 4
    Last Post: - 5th March 2009, 09:48
  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 : 1

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