interrupt on PICDEM2 +


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36

    Question interrupt on PICDEM2 +

    I think I've done everything right. Spelling, punctuation, etc., but it still won't interrupt. Did I miss something dumb and obvious?

    Using picdem2+ board, 18F452, 4mHz, rb0=pb switch to gnd.

    led var PORTB.3

    On Interrupt Goto MYINT1 ' Define interrupt handler
    INTCON = $90 ' Enable INTE interrupt
    INTCON2.7 = 0 ' Enable PORTB pullups
    loop:
    High led ' Turn LED on
    Goto loop ' Do it forever

    ' Interrupt handler
    Disable ' No interrupts past this point
    MYINT1:
    low led
    pause 500 ' Wait .5 seconds
    INTCON.1 = 0 ' Clear interrupt flag
    Resume ' Return to main program
    Enable

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


    Did you find this post helpful? Yes | No

    Default

    what about if you move your code lines like this
    Code:
    led var PORTB.3
    INTCON2.7 = 0 ' Enable PORTB pullups
    INTCON = $90 ' Enable INTE interrupt
    
    On Interrupt Goto MYINT1 ' Define interrupt handler
    
    
    loop: 
    High led ' Turn LED on
    Goto loop ' Do it forever
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Forget about above, your code is working. i just try it... must be a hardware or programming problem here.

    Be sure you set oscillator to XT.

    Last edited by mister_e; - 12th January 2005 at 21:40.
    Steve

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

  4. #4
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Thanks Steve for your quick reply. I'm glad that the code is working somewhere. What I posted is the entire program, there is no other programming. The LED at rb3 lights up fine.

    I'm assuming, first of all, that grounding the rb0 pin will result in the interrupt routine being executed (but it's not). The schematic for the picdem2+ board is available at:

    http://ww1.microchip.com/downloads/e...Doc/51275b.pdf

    As shown in the schematic rb0 also has an LED attached, but neither the LED nor the pullup should have any effect on the interrupt (at least as far as I see it).

    What exactly do you mean by "set oscillator to XT"?

    Thanks
    Klaus

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


    Did you find this post helpful? Yes | No

    Default

    hi Klaus,

    What exactly do you mean by "set oscillator to XT"?
    wich kind of programmer do you use :PICSTART, EPIC or else ?
    When you compile your code with PBP, here are the default osc setting you'll find the the pic18F452.inc file

    __CONFIG _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H

    These mean that you'll use XT oscillator (4mhz in your case) and you disable the oscillator switching mode (don't care for your app now)

    BUT i heard that some PIC programmer don't refresh those setting when you use the .HEX file for programming you PIC. So they will use their own default.. sometime RC-OSC as RA6. In this case you have chance if anything is working.

    In your programmer program you must have some place to set the "configuration bit" or "configuration fuse". Be sure to have XT OSC as oscillator setting. If anything is properly set, it will work.

    Case not try another program like simple Blink, keep Pull-up enable on PORTB, remove any interrupt stuff and do the blink while your push button is hold. that way you'll know that everything is working.

    Code:
    TRISB=%11110111
    LED VAR PORTB.3
    start:
          while PORTB.0=0 
              toggle LED
              pause 500
          wend
    goto start

    Be sure MCLR pin is set to 5Volt with pull-up resistors. And the last one be sure that you have capacitor (10-22pf) on each pin of your crystal to the ground.

    i can't say more than this
    Steve

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

  6. #6
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Steve,

    I'm using ICD2. The picdem2+ came with the ICD2 so I assume they are made to work with each other (or maybe the folks at Microchip have more of a sense of humor than we give them credit for). I did add "Define osc 4" just for good measure.

    I commented out the interrupt statements as you suggested and added a goto in the middle of the loop:

    if portb0.0 = 0 then goto myint1

    Works like a charm.

    Put the interrupt back in and ran in debug mode. The animation shows clearly portb.0 going form 1 to 0 when the button is pressed, but intcon.7 stays at 0.

    Time for a beer break.

    Klaus

  7. #7
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Had some clip leads laying around so I attached an LED to portC, disabled the portB Leds, and changed the code to blink rc.7.

    Everything is interrupting just great now. I guess the LED and pullup on rb0 were just too confusing for the interrupt to work.

    Thanks again for your help Steve.

    Klaus

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


    Did you find this post helpful? Yes | No

    Default

    Try it with INCLUDE "ICDDEFS4.BAS" in the top section of your code to reserve space for ICD vars.

    ICDDEFS4.BAS is for the - 18F252/258/452/458
    Regards,

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

  9. #9
    Join Date
    Dec 2004
    Location
    USA
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Bruce,

    Thanks for your input. I was finally able to get the interrupt working by disabling (diconnecting) the LEDs on rb0-rb3. It was a hardware problem after all.

    You bring up an interesting point, though. Just how much overhead does the ICD require?

    Best Regards,
    Klaus

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


    Did you find this post helpful? Yes | No

    Default

    Hi Klaus,

    > how much overhead does the ICD require?

    Not too much. The PBP header file ICDDEFS4.BAS reserves a few bytes for the "debug executive" ; ICDRESERVED12 VAR BYTE(12) $5f4, and the ICD2 uses & limits a few options like WDT, LVP, etc, but your ICD2 docs will give you a beter idea of the resources needed.

    It's pretty handy. I use the PICDEM 2 Plus, ICD2 & PBP all the time.
    Regards,

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

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. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  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