Interrupt On both (Rising and Falling)


Closed Thread
Results 1 to 10 of 10
  1. #1

    Default Interrupt On both (Rising and Falling)

    Hi to all.
    In my project I've used external interrupt. Rising edge on RB0 causes to occure an Interrupt. In the ISR, data are read from serial EEPROM. I've used a micro switch for determining the direction of movement. For example rising edge (1 to 0) implies right direction and falling edge (0 to 1) left direction. I need both of edge change detection. It means that in right direction should be done one thing and in left direction another thing. Unfortunately I can only detect one of directions: right or left! (By setting of OPTION register). How can I determine direction of movement?
    At the first I wanted to implement it by PORTB chane interrupt (RBIE). I defined all of pins of portB as output except for RB0. But it didn't work and it was so unstable.
    Please help me.
    Thanks alot

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Look at your available interrupts list ...

    Does "change on Port B" seem familiar ???

    Go on ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3


    Did you find this post helpful? Yes | No

    Default Good but HOW?!!

    Hi Acetronics. Thanks for your reply. As I said I wanted to use Interrupt from "Change on portB", but it didnot work. I use PIC16F84 in my project so I should optimize use of pins. I defined all of pins of PORTB as output except for one of them. I connected a push button to that. It didnot work normally. Why? Can you help me? How can I do that? Have you any example of method of using Change on port B interrupt?

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question My car doesn't start - Why ???

    Hi,Yasser

    First , In the title , understand we do not know at all what you did ( hardware ) nor what you wrote ( software ) ... and there are no "crystal ball" option on this forum ...

    For the car ... " did you insert the key ??? " is a first question to consider ...


    ...

    There's a funny thing in this feature ... the "end of mismatch" condition.

    I think there were ( numerous ) threads about that on this forum. ( a SEARCH will be useful ...)

    ... in a word, you have to READ PortB in your interrupt stubb to get it that interrupt working properly ( see examples given ...)

    BUT, as always ... only knowing which processor and compiler ... leaves NUMEROUS non-working reasons ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5


    Did you find this post helpful? Yes | No

    Default My car has unknown problem!!

    Thanks alot dear Acetronics.
    I wrote this simple program for testing portB change interrupt.

    '************************************************* ****************
    '* LCD Deifnes *
    '************************************************* ****************

    DEFINE LCD_DREG PORTD ' I/O port where LCD is connected
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTD
    DEFINE LCD_RSBIT 2 ' Register select pin
    DEFINE LCD_EREG PORTD
    DEFINE LCD_EBIT 3 ' Enable pin
    DEFINE LCD_BITS 4 ' 4-bit data bus
    DEFINE LCD_LINES 2 ' LCD has 2 character lines

    '************************************************* ****************
    '* Interrupt Initialzing *
    '************************************************* ****************

    INTCON = %10001000 ' GIE and RBIE are set
    OPTION_REG = %10000000

    '************************************************* ****************
    '* Initialzation *
    '************************************************* ****************

    TRISB = %00010000
    PORTB = 0

    ON INTERRUPT GOTO DIRECTION

    '************************************************* ****************
    '* Main Program *
    '************************************************* ****************

    MAIN:
    lcdout $fe,1
    lcdout "Main Routine"
    pause 500
    GOTO MAIN
    END

    '************************************************* ****************
    '* Interrupt Service Routine *
    '************************************************* ****************

    DISABLE
    DIRECTION:
    lcdout $fe,1
    lcdout "Interrupt !!!"
    PAUSE 100
    INTCON.0 = 0
    RESUME
    ENABLE

    I compiled it and downloaded HEX file to PIC. I use PROTEUS 6 pro for simulating my program.(My Circuit Attached) When I pushed start debugging button on
    proteus an unusual thing happened. I think that program should work in main loop so "Main Routine" should be written on LCD! But as soon as program starts
    executing, the message "Interrupt !!!" is shown on LCD!! even if the push button isn't pressed. Why it does not work correct?!!

    You wrote for me: "... in a word, you have to READ PortB in your interrupt stubb to get it that interrupt working properly ( see examples given ...)" What do you maen? Could you tell me about given examples?
    ** Although I use PIC16F877 in this simulator, I want to use PIC16F84 in my project. **
    Attached Images Attached Images  

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Do you know what the inital value of port B is in order to detect a change on said port B?
    Are all of your Port B pins pulled high/low or whatever?
    Are any of them floating? open?

    2nd thought...get rid of the simulator and build some real hardware...

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hi, Yasser

    I'll give a try on my test board : 16F84 + LCD ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Thumbs down

    Yasser,

    You're a bad student !!!

    What did I tell you about " mismatch condition " ???

    Code:
    	STATE 	var Byte
    	I 		var Byte
    	 	 
    	PORTA = 0
    	PORTB = 0
    '************************************************* ****************
    '* Interrupt Initialzing *
    '************************************************* **************** 
    
    INTCON     = %10001000 ' GIE and RBIE are set
    OPTION_REG = %10000000
    
    '************************************************* ****************
    '* Initialzation *
    '************************************************* ****************
    
    PORTB = 0
    TRISB = %00010000
    
    ON INTERRUPT GOTO DIRECTION
    
    '************************************************* ****************
    '* Main Program *
    '************************************************* ****************
    
    MAIN:
    
    lcdout $fe,1,"Main Routine"
    
    FOR I = 1 to 50 : PAUSE 10 : NEXT I ' For quick response
    
    GOTO MAIN
    END
    
    '************************************************* ****************
    '* Interrupt Service Routine *
    '************************************************* ****************
    
    DISABLE
    
    DIRECTION:
    
    STATE = PORTB	' End of Mismatch Condition
    
    lcdout $fe,1
    lcdout "Interrupt !!!"
    
    IF State.4 THEN
    
    	LCDOUT $FE,$C0," LOW to HIGH "
    	
    ELSE
    
    	LCDOUT $FE,$C0, " HIGH to LOW "
    	
    ENDIF
    	
    PAUSE 1000
    
    INTCON.0 = 0
    
    RESUME
    
    ENABLE
    
    END
    That works fine ... for a 16F84 !

    Alain
    Last edited by Acetronics2; - 12th March 2008 at 14:16.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9


    Did you find this post helpful? Yes | No

    Default Ok

    Hi dearAcetronics.
    Thanks alot for your replies. I found a nice PDF on the net about "Using the PORTB Interrupt on Change as an External Interrupt" microchip AN566. I rewote my code:

    '************************************************* ****************
    '* Initialzation *
    '************************************************* ****************

    TRISB = %00010000

    '************************************************* ****************
    '* Interrupt Initialzing *
    '************************************************* ****************

    OPTION_REG = %10000000
    INTCON = %10001000
    ON INTERRUPT GOTO DIRECTION

    '************************************************* ****************
    '* Main Program *
    '************************************************* ****************

    MAIN:
    PAUSEUS 10
    lcdout $fe,1
    lcdout "Main Routine"
    pause 100
    GOTO MAIN
    END

    '************************************************* ****************
    '* Interrupt Service Routine *
    '************************************************* ****************

    DISABLE
    DIRECTION:
    @ MOVF PORTB,1
    INTCON.0 = 0
    lcdout $fe,1
    lcdout "Interrupt !!!"
    PAUSE 100
    RESUME
    ENABLE
    and it worked correct.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Ok, you're fine now ...

    and you also know how to show the transition way !!!

    read you soon.

    Regards

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. mS Timer
    By whmeade10 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th September 2020, 12:12
  2. How to set TMRO & TMR3 as Counter?.
    By NatureTech in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 18th May 2007, 08:52
  3. 16F88 Interrupt
    By sskeet in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th January 2006, 15:51
  4. 2 interupts - portb.0 rising and falling edges
    By EDWARD in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th July 2005, 01:10
  5. Interrupts and Disable 16f877
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th April 2005, 21:08

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