strange int behaviour


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Location
    Zagreb, Croatia
    Posts
    27

    Question strange int behaviour

    Hello dear pic friends and sorry for bad english!
    Yesterday in my lab I have some strange int behaviour
    So, when I wrote simple task like this:

    define LOADER_USED 1
    define OSC 16
    TRISC.3=0
    papak:
    high PORTC.3
    pause 5
    low PORTC.3
    pause 5
    goto papak
    end

    I can see on my scope what I expected: square wave signal with period of
    10ms (100Hz frequency). That is OK!

    When I wrote assembler interrupt with TMR0 interrupt and do nothing in
    main loop like this

    define LOADER_USED 1
    define OSC 16

    wsave var byte $20 system
    wsave1 var byte $a0 system
    wsave2 var byte $120 system
    wsave3 var byte $1a0 system

    ssave var byte bank0 system
    psave var byte bank0 system

    define INTHAND myint
    TRISC.3=0
    goto main

    asm
    myint
    movwf wsave
    swapf STATUS,W
    clrf STATUS
    movwf ssave
    movf PCLATH,W
    movwf psave
    clrf PCLATH
    endasm
    toggle PORTB.6
    asm
    movf psave,W
    movwf PCLATH
    swapf ssave,W
    movwf STATUS
    swapf wsave,F
    swapf wsave,W
    bcf INTCON,2
    retfie
    endasm

    main:
    OPTION_REG=%10000000
    INTCON=%10100000

    nothing:
    goto nothing
    end

    In this case I also see on scope what I expected on PORTB.6:
    My prescaler bits are 000, this is 1:2 TMR0 rate and my
    osc is 16MHz so I have 256*2*250ns=128us low time and 128us
    high time signal - this is about 3.9KHz signal on PORTB.6 pin.

    But, when I combine these two simple tasks in one program like this:

    define LOADER_USED 1
    define OSC 16

    wsave var byte $20 system
    wsave1 var byte $a0 system
    wsave2 var byte $120 system
    wsave3 var byte $1a0 system

    ssave var byte bank0 system
    psave var byte bank0 system

    define INTHAND myint
    TRISC.3=0
    goto main

    asm
    myint
    movwf wsave
    swapf STATUS,W
    clrf STATUS
    movwf ssave
    movf PCLATH,W
    movwf psave
    clrf PCLATH
    endasm
    toggle PORTB.6
    asm
    movf psave,W
    movwf PCLATH
    swapf ssave,W
    movwf STATUS
    swapf wsave,F
    swapf wsave,W
    bcf INTCON,2
    retfie
    endasm

    main:

    OPTION_REG=%10000000
    INTCON=%10100000
    do:
    high PORTC.3
    pause 5
    low PORTC.3
    pause 5
    goto do
    end

    I still have my int signal on PORTB6 pin OK(3.9KHz) but my main
    routine becomes faster?! Instead of 100Hz signal on PORTC3 pin
    like before now I have about 780Hz signal?!
    Why?
    It doesn't make any sense. The main routine should be the same
    speed or slightly slower because of int latency but not faster!?

    My PIC is 16F876 with 16MHz quartz and shane tolmie's bootloader.

    Thanks for answers!

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


    Did you find this post helpful? Yes | No

    Default

    Hi tom,

    The 16F876 has 8K of program space.

    PBP automatically inserts an Interrupt "Stub" for you if the program space is greater than 2K. Why?, I don't know. The "Stub" is identical to what you have at the beginning of "myint", and it's all done before getting to "myint". Then once in "myint" it tries to save them again, but now the registers have been modified. When they get restored after the interrupt, something will have the wrong value, affecting the main PBP program.

    By testing for the code size first you can avoid the problem. Or, since you know the code size is larger than 2K, you can just leave that part out entirely.
    Code:
        IF (CODE_SIZE <= 2)
            movwf   wsave 
            swapf   STATUS,W
            clrf    STATUS
            movwf   ssave
            movf    PCLATH,W
            movwf   psave
        endif
    Last edited by Darrel Taylor; - 15th November 2005 at 09:09.
    DT

  3. #3
    Join Date
    Oct 2004
    Location
    Zagreb, Croatia
    Posts
    27


    Did you find this post helpful? Yes | No

    Question

    I comment out this part of code but still have the same situation...

  4. #4
    J_Brittian's Avatar
    J_Brittian Guest


    Did you find this post helpful? Yes | No

    Default

    Tom,
    Is everything faster? Do you still have a beautiful square wave with each step the same length? Or are some steps shorter than others?

  5. #5
    Join Date
    Oct 2004
    Location
    Zagreb, Croatia
    Posts
    27


    Did you find this post helpful? Yes | No

    Talking

    J Brittian:
    Nice clean and seven times faster, but it doesn't matter.
    We ddiscussed it already.

Similar Threads

  1. Strange Behaviour - Simple code+DT_INT+16F676
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th February 2010, 18:53
  2. Strange behaviour of my PBP code.
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th August 2009, 20:20
  3. Strange Serout Behaviour
    By bluesmoke in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th August 2009, 04:12
  4. Strange ADC behaviour
    By ruijc in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 12th December 2007, 20:03
  5. Strange behaviour from PIC16F877 on TMR0
    By mikebar in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 19th August 2006, 01:31

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