INTERRUPT on RB5


Closed Thread
Results 1 to 10 of 10
  1. #1
    fabritio's Avatar
    fabritio Guest

    Default INTERRUPT on RB5

    Hi everyone,
    it's just a simple question....
    Is it right the program that I've written to handle an interrupt on RB5?
    The output on PORTC must be always 255 except when it receive a high signal on RB5, when it has to do the procedure written in "loop".
    I've not written here the loop cause it's not useful.
    At the end of the loop it must return to 255 and wait at this value for the next high value on RB5.
    The program is this:



    TRISB.5 = 1
    TRISC = 0
    TRISA = 0
    PORTC = 0
    PORTA = 0

    on interrupt goto loop
    INTCON = %00001000

    main:

    PORTC = 255
    goto main

    disable

    loop:
    ..........
    ............

    INTCON.0 = 0
    resume
    enable


    Thank you very much!!!!

  2. #2
    fabritio's Avatar
    fabritio Guest


    Did you find this post helpful? Yes | No

    Default

    no one knows....


  3. #3
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    fabritio, be patient . . .

    What type of PIC are you using?

    what do you mean by saying:
    ... except when it receive a high signal on RB5 ...
    Is this "high signal" a HIGH level for a certain period of time, or is it a short pulse?
    Do you want to trigger on the rising or falling edge?

    If the program has nothing else to do than sit and wait for HIGH on RB5 you wouldn't even need an interrupt.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  4. #4
    fabritio's Avatar
    fabritio Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by NavMicroSystems
    fabritio, be patient . . .

    What type of PIC are you using?

    what do you mean by saying:


    Is this "high signal" a HIGH level for a certain period of time, or is it a short pulse?
    Do you want to trigger on the rising or falling edge?

    If the program has nothing else to do than sit and wait for HIGH on RB5 you wouldn't even need an interrupt.
    It's a 16f876.
    this "high signal" is a short pulse, (in particular there are 4 bursts, but i need to wait for the first), and has a repetion every 164 microseconds. So i can be able to trigger it on the change of status (every transition).
    I know, I've already written a program that works without interrupts, but the speed of the pulse doesn't let the loop start every time, it's randomic, so I am thinking about doing with the interrupts...
    Thank you!

  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    fabritio,

    your program should work.

    There are a couple of things I would like to mention:

    you should move the "PORTC=255"
    to the end of your Interrupt Routine,
    there is no need to write to PORTC every single time the mainloop is executed.

    Due to the fact it this is "INTERRUPT ON CHANGE"you will see an interrupt on EVERY rising AND falling edge.
    So if the execution time of the Interrupt routine is shorter than the incomming "burst" the routine will be executed more than once on a single burst.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  6. #6
    Samuel's Avatar
    Samuel Guest


    Did you find this post helpful? Yes | No

    Default interrupt on portb.5 (Triggers only one way)

    I want an interrupt to trigger everytime i change the switch on portb.5 (using a simple on/off switch connected to ground). My led is on porte.1

    this is what happens: no matter what the initial condition of the switch is, the interrupt triggers only one way. i.e once i change the switch it sits in the interrupt handler and DOES NOT go back to the main loop untill i take it back to the original position. So if the switch is ON at power up, the interrupt triggers every time i go from ON to OFF. But if the switch is OFF at power up, the interrupt triggers when i go from OFF to ON. I want the interrupt to trigger BOTH ways. (i.e everytime the state of the switch changes.)

    Isnt this what is "supposed" to happen according to the "Input change interrupt protocol" on PORTB<4:7> as per the data sheet?!?

    The funny part is i have a second test circuit with the LED connected to portb.1 and this setup works perfectly (i.e interrupt both @ ON and OFF) with the exact same code (ofcourse i just change my led var to portb.1) PLS HELP! This is driving my insane. My complete code is below.

    >>>>>>>>>>>>>>>>>>>>>>
    DEFINE OSC 20


    led var PORTe.1


    OPTION_REG = $7f ' Enable PORTB pullup
    On Interrupt Goto myint ' Define interrupt handler
    INTCON = %10001000 ' Enable interrupt portb 4:7 change

    loop: High led ' Turn LED on
    Goto loop ' Do it forever


    ' Interrupt handler
    Disable ' No interrupts past this point
    myint: Low led ' If we get here, turn LED off
    Pause 1000 ' Wait .5 seconds
    INTCON.0 = 0 ' Clear interrupt flag
    Resume ' Return to main program
    Enable
    >>>>>>>>>>>>>>>>>>>>>>>>>>>
    Last edited by Samuel; - 28th March 2005 at 22:19.

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


    Did you find this post helpful? Yes | No

    Default

    RBIF: RB Port Change Interrupt Flag bit
    A mismatch condition will continue to set flag bit RBIF. Reading PORTB will end the mismatch condition and allow flag bit RBIF to be cleared.

    With your LED on PORTB.1, that's exactly what you're doing with LOW LED. With your LED on PORTE, you're not performing a read-modify-write on RB, and the missmatch condition still exists.

    Just read PORTB in your interrupt routine, then clear RBIF, then return. Assuming you have your PORTE A/D turned off, it should work fine.

    The value read from PORTB in the interrupt handler will now be the new value that causes the interrupt once changed.
    Regards,

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

  8. #8
    Samuel's Avatar
    Samuel Guest


    Did you find this post helpful? Yes | No

    Default WOW!! Thanks SOO MUCH!

    What would ppl like me do without ppl like you!

  9. #9
    Samuel's Avatar
    Samuel Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce
    Assuming you have your PORTE A/D turned off, it should work fine.
    How do i do that and how does it make a difference? Is it the ADCON register you are talking about?

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


    Did you find this post helpful? Yes | No

    Default

    depending the PIC you're using it can be ADCON, ADCON0, ADCON1 refer to the datasheet.

    How can it make difference... roughly, you're checking a digital signal, if your analog converter are not turned off, you can have some odd/erratic results. a close to be low level signal can be considered as a high level and so on for the close to be high or high level. digital is digital, analog is analog. It's a common problem like some others, let's say RA4 to drive a source on many PIC
    Steve

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

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