hserin 100, main [flag] causing 18f24k22 to become unstabloe


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627

    Default Re: hserin 100, main [flag] causing 18f24k22 to become unstabloe

    For the sake of testing, can you try moving the code in the getchar subroutine to the actual place where the GOSUB getchar is? In other words, don't use a GOSUB just place the actual code "in line" instead.

    It's just a hunch but when you GOSUB getchar, where the HSERIN times out and jumps back to main you have an "unresolved" GOSUB/RETURN "pair". The number 27 happens to match the number of nested GOSUBs you can have on an 18F series, I think that's more than a coincidence.

    /Henrik.

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

    Default Re: hserin 100, main [flag] causing 18f24k22 to become unstabloe

    Timeout from a subroutine getchar to main is wrong.

    You should do it like this:

    Code:
    getChar
    
    
    'Receive a character, if no character within 100ms, then goto main
    hserin 100, exit_getchar, [flag]
    pause 100
    hserout ["received a character", 13]
    ' if char[0] = "U" then
    ' HSerout ["received a 'U'", 13]
    'Receive the remainder of the message
    ' hserin [STR char[1]\9]
    ' hserout ["received 9 more characters",13]
    ' hserout [str char\10]
    'array char[] should now hold all 10 bytes of the message from Elo
    ' endif
    
    exit_getchar:
    
    return
    Of course this will not start over from main, but if you need this, then set a flag in the subroutine that Hserin timed out and then jump to main (resetting the flag first).

    Ioannis
    Last edited by Ioannis; - 5th January 2018 at 08:11.

  3. #3
    Join Date
    Sep 2009
    Posts
    755

    Default Re: hserin 100, main [flag] causing 18f24k22 to become unstabloe

    You are right.
    He uses GOSUB and when times out, RETURN isn't executed. And it will jump with GOTO from HSERIN function to main.
    Other workaround is

    Code:
    getChar:
    'Receive a character, if no character within 100ms, then goto main >> IF you use goto main stack overflow, because RETURN isn't executed. 
    hserin 100, GetCharError, [flag]
    pause 100
    hserout ["received a character", 13]
    
    GetCharError:
    return

  4. #4
    Join Date
    Sep 2017
    Posts
    17

    Default Re: hserin 100, main [flag] causing 18f24k22 to become unstabloe

    Thank you and I changed the gosub to simply goto which works. I would ask, where is the maximum number of nested gosub routines documented?

    Again, thanks

    George

Similar Threads

  1. Can someone show me how to set ccp3 to RC6 on pic 18f24k22
    By jimseng in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd March 2012, 20:57
  2. Can someone help me get hpwm working on 18f24k22
    By jimseng in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st March 2012, 13:31
  3. Argument out of range - how to find what is causing it?
    By BrianT in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2011, 02:00
  4. Fan causing noise in audio circuit
    By The Master in forum Off Topic
    Replies: 11
    Last Post: - 28th August 2011, 11:47
  5. MCLR causing trouble . .
    By shahidali55 in forum General
    Replies: 10
    Last Post: - 21st December 2007, 12:20

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