16F676 Interupt on Change pin determination


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi HH,
    Just at a quick glance, it looks like these two lines are off a bit:


    IF NEWPORTA.4 <> OLDPORTA.5 THEN < compares A.4 to A.5

    IF NEWPORTA.3 <> OLDPORTA.5 THEN < compares A.3 to A.5


    I think they should be:

    IF NEWPORTA.4 <> OLDPORTA.4 THEN

    IF NEWPORTA.3 <> OLDPORTA.3 THEN

    Arch

  2. #2
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Sorry arch, I edited it to simplify it and may have messed that up. Let me check it and I'll post again.

  3. #3
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I fixed it and it still does the same thing. In addition, it seems that if I even get close to it sometimes it goes off. Is there a pin I should ground or have I really screwed something up?
    Last edited by BGreen; - 4th May 2006 at 01:10.

  4. #4
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    I tossed the code into MicroCode Studio to get a better look - think I see the problem...

    Code:
    	IF NEWPORTA.5 <> OLDPORTA.5 THEN
    ILOOP:
    		I = I + 1
    		IF I = 5 THEN
    			resume BASE
    		ENDIF
    		LOW LED : PAUSE 1000 : HIGH LED
    		PAUSE 1000
    		GOTO ILOOP
    	ENDIF
    
    	IF NEWPORTA.4 <> OLDPORTA.4 THEN
    		I = I + 1
    		IF I = 4 THEN
    			resume BASE
    		ENDIF
    		LOW LED : PAUSE 1000 : HIGH LED
    		PAUSE 1000
    		GOTO ILOOP  ; <<<<<<<<<< JUMPS BACK TO Iloop
    	ENDIF
    No matter which pin is interrupted, the code jumps back to "Iloop", which is in the middle of the "IF NEWPORTA.5 <> OLDPORTA.5 THEN" test. It loops there until done, blinking the LED as if A.5 were interrupted, no matter which pin actually caused it.

    Arch

    PS - on the erratic triggering, make sure your programmer is actually setting MCLR off, and check for 'floating' inputs.
    What value pullup/pulldowns are you using?
    Last edited by Archilochus; - 4th May 2006 at 01:27.

  5. #5
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I wasn't using anything but internals on this Arch. I'll check out what you posted and give it a whirl. Thanks for the help. I think my brain began to die after I passed 50.

  6. #6
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Had a few extra minutes and rewrote the code - I think it should work - I don't have any 16F676's to try it on.
    (yer way ahead of me... my brain died off around 5 or so)...

    Code:
    @ DEVICE PIC16F676,INTRC_OSC_NOCLKOUT,WDT_ON,PWRT_OFF,BOD_OFF,PROTECT_OFF,CPD_OFF,MCLR_OFF
    	LED var PORTA.0
    	BlinkCount var byte
    	CounterA var byte
    	OLDPORTA VAR byte
    	NEWPORTA VAR byte
    ; DISABLE ANALOG INPUT, COMPARATOR ON PORTA, A/D reference...
    	ANSEL = 0 : CMCON = 7 : VRCON = 0
    	TRISA = %00111110	; PortA In/Out states
    	WPUA = %00000110
    	INTCON = %10000000 : IOCA = %00111000 : OPTION_REG = %00001000
    	LED = 0 : PAUSE 1000 : LED = 1
    	GOTO BASE
    ;
    ; SUBROUTINES
    MYINT:
    	NEWPORTA = PORTA	; read current PortA state
    	INTCON = %10000000
    ;
    	IF NEWPORTA.5 <> OLDPORTA.5 THEN
    		BlinkCount = 3	; Set up for 4 blinks
    	ENDIF
    ;
    	IF NEWPORTA.4 <> OLDPORTA.4 THEN
    		BlinkCount = 2	; Set up for 3 blinks
    	ENDIF
    ;
    	IF NEWPORTA.3 <> OLDPORTA.3 THEN
    		BlinkCount = 1	; Set up for 2 blinks
    	ENDIF
    ;
    	for CounterA = 0 to BlinkCount
    		LED = 0 : PAUSE 1000 : LED = 1 : PAUSE 1000
    	next CounterA
    	RESUME Base
    ; The above section could have an error trap in case none of the IF's are true for some reason.
    ; A "Select Case" might use less code space.
    ;
    ; Start main program loop here
    ;
    BASE:
    	BlinkCount=0 : OLDPORTA = PORTA
    ;
    ON INTERRUPT GOTO MYINT
    	INTCON = %10001000
    ;
    LOOP:
    	SLEEP 240 : GOTO LOOP
    	end

    Arch

  7. #7
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Arch, once again I'd like to thank you. That was it. At one time programing was one of my strong points, but it seems I get lost pretty easy these days. Thanks for helping me out again.

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


    Did you find this post helpful? Yes | No

    Default

    Well, that definately looks better, and it may work better for now, but it still needs a couple things.

    The Interrupt "Handler" should be enclosed within DISABLE/ENABLE statements to keep the Interrupt Handler itself from being interrupted again.

    The clearing of the Flag should be done in the handler, not the point that execution resumes. If you RESUME without clearing the flag first, you can end up right back in the Handler again.

    And, "resume BASE" should only be "RESUME".
    When specifying a location to RESUME to, it essentially does a GOSUB to that routine when the Handler is finished. However, in this program, the PIC is told to go to Sleep, without ever returning from that GOSUB. So on each interrupt, it pushes another address on the stack, which overflows after 8 interrupts. For a 16F, the Stack will wrap around to the beginning again without causing a reset, so you may never see the problem right now, but if there are any other subroutines involved, they will never get a chance to RETURN, or will return to the wrong place.

    Because of the "Spaghetti" nature of this program, these problems may not be evident because it just falls back into the program and continues on, but when you start adding things later, you will lose a large portion of whatever hair you may have left trying to figure it out.
    <br>
    DT

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. HELP !!! How change the voltage of a pin ????
    By stormdacta in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st August 2007, 20:55
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  5. 16F676 Interupt
    By BGreen in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2006, 20:56

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