ON INTERRUPT questions


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default ON INTERRUPT questions

    I need to be ready to accept RS-232 input at any time in a PIC18F8722. It normally sits in a tight loop, so I monitor the PIR1.5 bit. When it is set, I jump to my input routine using HSERIN. However, my program must occasionally send out long strings using the HSEROUT command. I must have a way to immediately break out of my SEND routines if a character is received.

    I was hoping to be able to usint the ON INTERRUPT statement to help me. My questions are - when sending a long string of characters, does the ON INTERRUPT statement add the check for the interrupt flag bit between each character sent, or does it wait until the entire string has been sent?
    Would the SEROUT2 command work any differently?

    And normally, I would use the ON INTERRUPT structures to send the program off to a special interrupt handler and put a RESUME at the end of that handler, but I don't want to use a handler. Upon receiving a character, I want to jump to my normal input routine and process the input in the normal way.
    (I don't need to pick up right where I left off in the SEND sequence). In such a case, where would I put a RESUME statement? And if the program comes across a RESUME in its normal flow, will something blow up?

    I can't use the ON INTERRUPT for all input routines because of the overhead involved.
    Charles Linquist

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Within your send routine, can you send character by character your string and check in between for the PIR1.5 ?

    The delay would be one byte maximum.

    Ioannis

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I thought of that method myself last night, and have already started implementing it. That seems to be the best alternative right now.

    I suppose that I need to check the listing file, but I need to make certain that I'm never "blind" for a significant part of a character reception period. I can't afford to miss even one character. There is no pacing. The data stream is coming from a computer, not a human.

    I'm thinking that there should be some easy assembly language routine that - upon interrupt, just dumps me to a particular line and starts execution there. As I said before, I don't need to pick up right where I left off. If I'm sending a string, and a character comes in, I can stop sending data and respond to the new request.
    Charles Linquist

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis
    I need to make certain that I'm never "blind" for a significant part of a character reception period. I can't afford to miss even one character.
    You won't since you will be checking every one byte. The PIC buffer is 2 bytes long.

    Quote Originally Posted by Charles Linquis
    I'm thinking that there should be some easy assembly language routine that - upon interrupt, just dumps me to a particular line and starts execution there.
    Either ASM or Basic the result with the suggested method will be the same. Maybe with ASM a few microseconds faster.

    Ioannis

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Question interrupt jam ...

    Quote Originally Posted by Charles Linquis
    I'm thinking that there should be some easy assembly language routine that - upon interrupt, just dumps me to a particular line and starts execution there. As I said before, I don't need to pick up right where I left off. If I'm sending a string, and a character comes in, I can stop sending data and respond to the new request.
    Hi, PbP kings ... Mel and Co.

    I see something interesting here ...

    Just add :

    ON INTERRUPT GOTO xxxy
    DISABLE INTERRUPT

    at the very top of the pbp program.

    DO not Forget to end your interrupt routine xxxy: with a ( PbP ) GOTO where you want to go back then.


    What's new in the asm Program window ???

    program address 3 and 4 are now free, there's a new "return" at address 5 ... change it for a nop.

    Label L 0001 ( a bit further ) contains the interrupt lines for PbP ... replace them by nops.

    as there are no PbP lines between ON Interrupt and Disable ....There are no Gosub L0001 !!!

    at address 3 put a GOTO 0006 to skip line 4 and 5

    at address 4 ... just set the page bits ( if necessary ) and add an asm "GOTO" to the PBP interrupt label ( in address 4 or 5, Then)

    we've seen 8 lines on 8 ...

    I think it might work now ...

    Alain

    PS: example given for an interrupt vector at line 4 ... of course !!!
    Last edited by Acetronics2; - 14th December 2005 at 15:09.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I hate to sound dumb, but...

    It has been a long time since I wrote ASM code for PICs.


    My code is basically as below-

    TOP:
    IF TMR0 rollover then gosub TASK_SCHEDULER
    IF PIR1.5 = 1 then gosub INPUT_ROUTINE
    GOTO TOP

    TASK_SCHEDULER:
    (normally calls a bunch of very short routines - 300uSec max)
    but- every once in awhile calls OUTPUT_ROUTINE
    RETURN


    INPUT_ROUTINE:
    HSERIN stuff
    RETURN

    OUTPUT_ROUTINE:
    HSEROUT [...]
    RETURN

    ---------------------------------------
    Questions:
    Do I just put the address of 'TOP' in the interrupt vector?
    Is there a way to automatically do this in PBP - some way that I don't have to look at the listing and find out what the actual address of 'TOP' is, and manually write that to address 0x08 (something like INT_VECTOR = TOP)?
    Do I have to save/restore any other registers (STATUS or W, for example?)
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis
    I hate to sound dumb, but...

    It has been a long time since I wrote ASM code for PICs.


    My code is basically as below-

    TOP:
    IF TMR0 rollover then gosub TASK_SCHEDULER
    IF PIR1.5 = 1 then gosub INPUT_ROUTINE
    GOTO TOP

    TASK_SCHEDULER:
    (normally calls a bunch of very short routines - 300uSec max)
    but- every once in awhile calls OUTPUT_ROUTINE
    RETURN


    INPUT_ROUTINE:
    HSERIN stuff
    RETURN

    OUTPUT_ROUTINE:
    HSEROUT [...]
    RETURN

    ---------------------------------------
    Questions:
    Do I just put the address of 'TOP' in the interrupt vector?

    > If TOP: is the label of your interrupt stubb ... yes. but, think to disable the asm interrupts while being in your receive section ...
    > BUT the receive section MUST end with a GOTO, and not a RETURN ( Return address is totally false, here !!! )

    Is there a way to automatically do this in PBP -

    > It would have already been done, I think !!!

    > Question has to be asked to Melabs or Mel Labs ( !!! ) ... I'm just a poor lonesome engineer !!! at this time, answer for me is no ...

    some way that I don't have to look at the listing and find out what the actual address of 'TOP' is, and manually write that to address 0x08 (something like INT_VECTOR = TOP)?

    > I do not know if labels can work here ( bi-directionnal translation ??? hex to asm and asm to hex ... hum ...) ... it's to try. But remember : you can't add or kill program lines at this step ...

    Do I have to save/restore any other registers (STATUS or W, for example?)
    > It is not necessary, as you go back to a full section of PbP code ... and redo a full task. but you've lost what you were doing ... may be care has to be taken with READ and WRITE to be sure values are really saved or read .
    I'd better kill interrupts in those sections ...


    Alain
    Last edited by Acetronics2; - 14th December 2005 at 18:02.
    ************************************************** ***********************
    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,648


    Did you find this post helpful? Yes | No

    Default It runs !!!

    I did just a little try ...16F84A, button on PortB.0, Led on PortB.7

    see :

    'Test Blink

    ON INTERRUPT GOTO Period
    DISABLE INTERRUPT


    DEFINE LCD_Ebit 1

    I var Bit
    Periode var Word

    Led var Portb.7
    Led = 0
    Periode = 64


    loop:

    INTCON.4 = 1

    For I = 1 to 1000
    Pauseus Periode
    Next I

    Toggle led

    Goto loop


    Period:

    INTCON = $80

    Periode = ( Periode /2 )

    IF NOT Periode THEN
    Periode = 64
    ENDIF


    GOTO loop




    END


    the HEX, now, in the Program Window

    Change line 5 ( RETURN ) to ( GOTO 0x54 ) ....

    ENJOY !!!

    That's all !!!
    Last edited by Acetronics2; - 16th December 2005 at 14:19.
    ************************************************** ***********************
    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
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Thanks! I'll try it.
    Charles Linquist

  10. #10
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I'm using Microcode Studio, so I'm not familiar with Microchip's IDE.

    I'm trying to figure out how you changed the return address of the interrupt routine to the address of my label ''CharInput'.

    A couple of questions then:

    Within the ASM file, how do I find out what address the various labels are located? My character input routine is call 'CharInput'. That is where I want the program to jump when it gets an interrupt from the serial port.

    In the following, I see no RETFIE or RETURN where I could substitute the address of CharInput. Where do I find that?




    Here is a portion of my ASM file.

    ; C:\PIC\BASIC\BAE5_INT.BAS 00175 ON INTERRUPT GOTO CharInput
    ONINT?LL _CharInput, L00001

    ; C:\PIC\BASIC\BAE5_INT.BAS 00176 DISABLE INTERRUPT
    IDISABLE?
    Charles Linquist

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink One step further ...

    Hi Charles

    Try this :

    'Test Blink


    DEFINE INTHAND _Period

    I var Word
    Periode var Word

    Led var Portb.7
    Led = 0
    Periode = 64


    loop:

    INTCON = %10010000

    For I = 1 to 1000
    Pauseus Periode
    Next I

    Toggle led


    Goto loop


    Period:

    INTCON = $80

    Periode = ( Periode /2 )

    IF NOT Periode THEN
    Periode = 64
    ENDIF


    GOTO loop


    END


    !!! IMPORTANT NOTE !!! : DO NOT FORGET the underscore before Period , in the inthand DEFINE !!!

    No mod to add to the Hex, this time !!!

    No Retfie or Return to care with ... just give the jump label you want to go aft the interrupt stubb.

    ENJOY

    Alain

    PS : Doesn't hurt MCS nor ....
    Last edited by Acetronics2; - 19th December 2005 at 17:53.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  12. #12
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Thank you, Thank you, Thank you!

    I have modified my code to deal with a serial port interrupt, and (so far at least) it is working perfectly.
    Charles Linquist

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. Interrupt questions
    By ruijc in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2008, 22:18
  4. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  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