PIC16F877A - Timer0 won't interrupt


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Location
    Delft, the Netherlands
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thanks all for your responds, will try them out on monday, it's weekend now. But thank you all very very much !!!

  2. #2
    Join Date
    Apr 2007
    Location
    Delft, the Netherlands
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    It's working perfectly!!! Thanks for the help!

    Cheers,

    William

  3. #3
    Join Date
    Apr 2007
    Location
    Delft, the Netherlands
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Hello all!!
    An update and help request on my program:

    Code:
    define loader_used 1  
    define osc 20 
    
    ;---Defining Variables---
    wsave var   byte $70 system
    ssave var   byte bank0 system
    psave var   byte bank0 system       
    
    count0  var byte bank0 system
    count1  var byte bank0 system
    count2  var byte bank0 system
    count3  var byte bank0 system  
    count4  var byte bank0 system
    count5  var byte bank0 system
    hulp0   var byte bank0 system
    hulp1   var byte bank0 system
    hulp2   var byte bank0 system
    whulp   var byte bank0 system
    pclhulp var byte bank0 system
    sthulp  var byte bank0 system
    
    ;---Zeroing registers---
    count0   = 0
    count1   = 0
    count2   = 0
    count3   = 0  
    count4   = 0
    count5   = 0
    hulp0    = 0
    hulp1    = 0
    hulp2    = 0
    whulp    = 0
    pclhulp  = 0
    sthulp   = 0
    STATUS.0 = 0
    
    Goto main ;Skip interrupt routine
    
    define INTHAND int
    
    DISABLE DEBUG
    
    asm
    ;---Save W, STATUS and PCLATH---
    int movwf whulp
        swapf STATUS, W
        clrf STATUS
        movwf sthulp
        movf  PCLATH, W
        movwf pclhulp
        
    ;---Clock program---    
        incf count0, F
        movwf count0
        call check
        movf count0, W
        btfss STATUS,0
        goto eindafwerking
        incf count1, F
        movwf count1
        call check
        movf count1, W
        btfss STATUS,0
        goto eindafwerking
        incf count2, F
        movwf count2
        call check
        movf count2, W
        btfss STATUS,0
        goto eindafwerking
        incf count3, F
        movwf count3
        call check
        movf count3, W
        btfss STATUS,0
        goto eindafwerking
        incf count4, F
        movwf count4
        call check
        movf count4, W
        btfss STATUS,0
        goto eindafwerking
        incf count5, F
        movwf count5
        call check
        movf count5, W
        btfss STATUS,0
        goto eindafwerking
    
    ;---Restore W, STATUS and PCLATH---
    eindafwerking movf pclhulp, W
                  movwf PCLATH
                  swapf sthulp, W
                  movwf STATUS
                  swapf whulp, F
                  swapf whulp, W
                  bcf intcon,2
                  retfie
    
    ;---Check function for counts to be 99h maximum (NOT USED YET)---
    check return
    ENDASM
    
    ENABLE DEBUG
    
    main:
       INTCON = %10100000                  ;GIE enabled, T0IE enabled
       OPTION_REG = %00000111           
       goto loop
       
    loop:   goto loop                           ;Wait here for interrupt
    The program before (with the LED) was to time it on 1 millisecond, the final program (which isn't this one ofcourse ) is for measurement purposes.

    Test step 2:
    What I try to do here is to make a counter, that increments count0 when the timer overflows, then when count0 is full, it increments count1 etc etc. Atleast... it should do that....

    The things i tried to make it work:
    - Reset the C flag of STATUS, only this made only count0 to run.
    - Switched , W with , F and vice versa (example: STATUS, W becomes STATUS, F)

    A colleague told me to make some own save location (pclhulp, whulp and sthulp). I'm not sure if this is okay...

    If someone could help me out again, I will be very gratefull (again!!).

    Cheers,

    William

    (Excuse me for the dutch labeling, it shouldn't be be much of a problem i guess )

    /EDIT:

    Allrightey I fixed the problem myself! Yay ^^!

    Code:
    define loader_used 1  
    define osc 20 
    
    ;---Defining Variables---
    wsave var   byte $70 system
    ssave var   byte bank0 system
    psave var   byte bank0 system       
    
    count0  var byte bank0 system
    count1  var byte bank0 system
    count2  var byte bank0 system
    count3  var byte bank0 system  
    count4  var byte bank0 system
    count5  var byte bank0 system
    hulp0   var byte bank0 system
    hulp1   var byte bank0 system
    hulp2   var byte bank0 system
    whulp   var byte bank0 system
    pclhulp var byte bank0 system
    sthulp  var byte bank0 system
    
    ;---Zeroing registers---
    count0   = 0
    count1   = 0
    count2   = 0
    count3   = 0  
    count4   = 0
    count5   = 0
    hulp0    = 0
    hulp1    = 0
    hulp2    = 0
    whulp    = 0
    pclhulp  = 0
    sthulp   = 0
    STATUS.2 = 0
    
    Goto main ;Skip interrupt routine
    
    define INTHAND int
    
    DISABLE DEBUG
    
    asm
    ;---Save W, STATUS and PCLATH---
    int movwf whulp
        swapf STATUS, W
        clrf STATUS
        movwf sthulp
        movf  PCLATH, W
        movwf pclhulp
        
    ;---Clock program---    
        incf count0, F
        movf count0, W
        call check
        movwf count0
        btfss STATUS,2
        goto eindafwerking
        bcf STATUS,2
        incf count1, F
        movf count1, W
        call check
        movwf count1
        btfss STATUS,2
        goto eindafwerking
        bcf STATUS,2
        incf count2, F
        movf count2, W
        call check
        movwf count2
        btfss STATUS,2
        goto eindafwerking
        bcf STATUS,2
        incf count3, F
        movf count3, W
        call check
        movwf count3
        btfss STATUS,2
        goto eindafwerking
        bcf STATUS,2
        incf count4, F
        movf count4, W
        call check
        movwf count4
        btfss STATUS,2
        goto eindafwerking
        bcf STATUS,2
        incf count5, F
        movf count5, W
        call check
        movwf count5
        bcf STATUS,2
        goto eindafwerking
    
    
    ;---Restore W, STATUS and PCLATH---
    eindafwerking movf pclhulp, W
                  movwf PCLATH
                  swapf sthulp, W
                  movwf STATUS
                  swapf whulp, F
                  swapf whulp, W
                  bcf intcon,2
                  retfie
    
    ;---Check function for counts to be 99h maximum (NOT USED YET)---
    check return
    ENDASM
    
    ENABLE DEBUG
    
    main:
       INTCON = %10100000                  ;GIE enabled, T0IE enabled
       OPTION_REG = %00000111           
       goto loop
       
    loop:   goto loop                           ;Wait here for interrupt
    What I did wrong:
    - I switched the movf and the movwf instructions!
    - Checked the wrong bit, it checked the carry flag (Status.0) instead of the Zero flag (Status.2)

    I feel so noobish >)
    Last edited by WishMaster^; - 17th April 2007 at 10:27. Reason: Made some things more clear.. EDIT2: Fixed the problem..

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by WishMaster^ View Post
    I feel so noobish >)
    Really? Well...how many 'noob's' can say they fixed a problem on their own.
    I do believe you've done graduated out of the noob class...
    Now go let all the smoke out of a PIC to celebrate!

  5. #5
    Join Date
    Apr 2007
    Location
    Delft, the Netherlands
    Posts
    10


    Did you find this post helpful? Yes | No

    Arrow

    Quote Originally Posted by skimask View Post
    Really? Well...how many 'noob's' can say they fixed a problem on their own.
    I do believe you've done graduated out of the noob class...
    Now go let all the smoke out of a PIC to celebrate!
    I can count myself as a real rookie now!!

    Now that my program is growing, I encountered a new problem.
    The program is now some sort of stopwatch with 1 control button on portb.4.
    The problem is, that when I press the button, the timer won't start and it goes straight to "The time is: 00,00"

    What do I miss here?


    anyone? ^^

    Cheers,

    William

    /EDIT While I studied the behaviour of the program, I saw something odd... When i press RB4, INTCON.0 is set, BUT the interrupt enable bit is cleared on the same time. That's why it doesn't interrupt.

    Now I have forced the enable bit to stay set, only when I run it then it gives me an adress missmatch error. So that isn't the solution...

    Anyone with a clue what might reset INTCON.3?
    Attached Files Attached Files
    Last edited by WishMaster^; - 19th April 2007 at 13:02. Reason: Added a founding......
    ------------
    Oh Noes...
    ------------

  6. #6
    Join Date
    Apr 2007
    Location
    Delft, the Netherlands
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Odd...

    Okay, in debug mode all works fine now, but, when I compile and load the program without the debugger, then it goes bananas. What I suspect now, is that there is a signal in PortB what is resonating when I press the button. This will cause many interrupts, making the microcontroller think that I press the stop button right away.

    That will explain why it skips the interrupt routine without the debugger on...

    Before I order any parts to solve this, I want to know if I'm close or not. So is this a problem that might occure while making something like this?



    Cheers,

    William
    Attached Files Attached Files
    ------------
    Oh Noes...
    ------------

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by WishMaster^
    A colleague told me to make some own save location (pclhulp, whulp and sthulp). I'm not sure if this is okay...
    I don't think I'd be listening to that guy too much.

    If you are using a chip with more than 2K of program memory,PBP automatically inserts code to do the context saving. It uses the wsave, ssave and psave variables. Why? I don't know. But it does.

    In the process of saving the context, it also changes the W and STATUS registers. So if you try to save and restore it with different variables, you're only saving the changed values. Then the real values never get restored.

    This will send PBP to the Funny Farm. Or at least the person trying to figure it out.

    So, lose the saving portion of the interrupt handler, then change the restore section to what's shown in the manual.

    HTH,
    DT

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. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  3. Ping Darrel Taylor - Timer0 Instant Interrupt
    By JEC in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th January 2007, 11:20
  4. USART interrupt in PIC16F877A
    By amindzo in forum General
    Replies: 7
    Last Post: - 26th August 2006, 18:51
  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