Sorry, but another interrupt problem


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    tbirchall's Avatar
    tbirchall Guest

    Default Sorry, but another interrupt problem

    I'm a newbie just can't seem to get this working. I've checked the other posts but I don't see what I'm doing wrong. I'm trying to receive an interrupt from push button connected to portb/0. I am using a PIC16F84A and here is the code:

    Include "modedefs.bas"

    CLEAR
    LOW 7

    TRISB.0 = 1
    INTCON = %10010000
    ON INTERRUPT GOTO handleInterrupt

    main:
    PAUSE 1
    GOTO main

    DISABLE
    handleInterrupt:

    HIGH 7 ' turn on LED so I know it worked
    PAUSE 1000
    LOW 7

    INTCON.1 = 0
    RESUME

    ENABLE

    END

    If the problem isn't in the code, it might also be how I've got the push button hooked up. (Like I said, I'm a newbie.) I've tried several things, but right now I have one lead on the push button connected to 5v+ and the other lead connected to portb/0. I've tested the LED and switch separately, and they both work and the code compiles as well.

    Any help is GREATLY appreciated.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what else on the PORTB.0 pin??? any pull-down resistor???
    Should have one, if not it could act weird.

    Another altenative is to use the internal PULL-UP and connect your push-buuton between RB0 and GND
    Code:
    OPTION_REG = 0 ' enable internal pull-up and interrupt on RB0 falling edge
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jan 2005
    Location
    Australia
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    You should initialise the INTEDG bit of OPTION_REG. If you would like to make falling edge interrupt, just add OPTION_REG.6 = 0 after INTCON = %10010000
    Yuantu Huang

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    This is why i suggest my previous. BTW in the first post PB was connected to VCC and OPTION_REG.6 is set to 1 at start-up wich is already rising edge.
    Last edited by mister_e; - 30th August 2005 at 01:20.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    tbirchall's Avatar
    tbirchall Guest


    Did you find this post helpful? Yes | No

    Default Thank you

    Thank you very much. That did the trick. It is really great to have such knowledgable people to turn to. Thanks for taking the time.

    -Tom

  6. #6
    tbirchall's Avatar
    tbirchall Guest


    Did you find this post helpful? Yes | No

    Default Another question

    OK, I hate to be a pest but... I got the sample code working, but when I apply it to my real code, it only works once. Basically, what I'm trying to achieve is to have the program wake on interrupt, do something, then go back to napping. This is to save power since it is a battery powered project. So, my loop looks like this:

    loop:
    NAP 0
    PAUSE 1

    GOSUB blah
    GOTO loop

    The idea is that all the interrupt does is to clear the flag, then the code will resume at the next line of code - in this case, the PAUSE statement. If I have a simple HIGH/LOW FOR/NEXT loop that lights an LED, it works perfectly over and over again. If I have my gosub (like above), then it works once and that's it - the interrupt never gets called again. Can someone tell me conceptually what is going on? My gosub has one other gosub nested in it, so I don't think it is too deep. Oh, and blah does have a return and my interrupt routine is wrapped in DISABLE and ENABLE calls. Thank you!

    -Tom

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Whilst I prefer to use @SLEEP rather than NAP, I did once experience an anomaly (about three years back - probably PBP v2.42) whereby a couple of instructions following the @SLEEP were not executed properly. I cured the problem (without investigating further due to lack of time) by inserting half a dozen @NOP statements before I resumed with any proper code... the reasoning behind that was if it was going to misbehave and skip a couple instructions then the NOP's would absorb the anomaly and contine as it was intended. Anyhow, it worked for me, might be worth trying to see if it does it for you.

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. Problem with Interrupt on PIC18F4620 PORTB
    By rookie in forum Off Topic
    Replies: 1
    Last Post: - 22nd March 2007, 01:34
  3. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  4. Interrupt stack overflow problem with Resume {label}
    By Yuantu Huang in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd May 2005, 01:17
  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