Am I stupid? Goto does not GOTO??? Where's the bug??


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    I don't know because I changed the code meanwhile but anyway, as there is an LCDOUT $fe,1 the next LCDOUT would overwrite "0pin..." and it does not.
    "finish" is the label at the bottom of the int handler and nothing else will overwrite what is displayed so it shows the GOTO is ignored.

    Ever worse, in another part of the code I'm checking what pin has triggered the interruption and I can read port 0 to 3 but not port 4.

    I was wondering,... is there a limit to the number of GOTO we can use in a program? Is there such limitation?

    "Also, make sure when you GOTO another routine from your interrupt
    that the routine isn't outside the DISABLE/ENABLE block. If you do it returns
    to the beginning of your interrupt handler. "
    -> actually I don't GOTO to something outside the int handler.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    the problem may not be so obvious with just the code fragment you posted. I suggest you post your entire interrupt code so that we can see what else is in there which can affect your desired outcome. I usually consider it a bad idea to have functions like LCDOUT in the interrupt handler. If the interrupts are not disabled, that statement itself, in the interrupt, may cause immense pain to a coder.

    Jerson

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jerson View Post
    the problem may not be so obvious with just the code fragment you posted. I suggest you post your entire interrupt code so that we can see what else is in there which can affect your desired outcome. I usually consider it a bad idea to have functions like LCDOUT in the interrupt handler. If the interrupts are not disabled, that statement itself, in the interrupt, may cause immense pain to a coder.

    Jerson
    Yes, I will post the code but the entire interrupt code is pretty huge.

    As far as I know, using
    DISABLE - (int handler) - RESUME - ENABLE should take care of the INT disabling while in the interrupt routine, am I wrong?

    About LCDOUT, they are especially useful to debug the code but can lead to unexpected behaviors, I agree. They are to be deleted when debugging is finished because it woud slow down my handler anyway.

    What is so weird is that I seem to be able to get an interrupt on RA4 like I do with the other pins on this port but when in the int handler, it's dead, as if it cannot read the incoming pulses.

    Now I'm reading again the fuctions for this pin and I see CLOCKOUT (which should not be a problem as I disabled CLOCKOUT in the CONFIG words and this pin is an input anyway).
    I also see 'T1G_' (TIMER1 GATE INPUT)! As I'm using TIMER1 to measure/time the pulses incoming on the pins, IF I didn't set the TIMER1 registers right, then this pin is thinking a LOW going pulse is a Timer1 gate input...?
    My current TIMER1 settings are:
    T1CON = %00011100 '1:2 prescale for 1US increments, timer 1 is stopped

    I'm not sure exactly what settings I should use as the datasheet is not very clear to me.
    BIT7: I will invert the gate (which is by default: low) so it will not interfer with my pulse (my TSOP IR sensors pulls low the pin when getting IR signal)
    BIT6: (Time1 gate enable bit): it says if TIMER1 is on, "0" is 'Timer1 is on', "1" is 'Timer1 is on if Timer1 gate is not active'... what a strange and complicated way to say things... !!! Well, I think I should clear this bit...
    I will try with the register set to : T1CON = %10010100

    Why do the datasheet have to be soo intricate...

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


    Did you find this post helpful? Yes | No

    Wink

    Hi

    And what about changing "==" to "=" ???

    Just an idea ...

    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
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Acetronics View Post
    Hi

    And what about changing "==" to "=" ???

    Just an idea ...

    Alain
    ? Why? If I remember well, it is supposed to be exactly the same.

    Manual says:
    "4.18. Comparison Operators
    = or ==
    used for
    Equal"



    Manual says also:
    "2.6.4. GOTO
    Try not to use too many GOTOs. While GOTOs may be a necessary evil, try to minimize their use as much as possible. Try to write your code in logical sections and not jump around too much. GOSUBs can be helpful in achieving this."

    What do they mean "as much as possible"??? How many? What problem may arise otherwise?

  6. #6
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    GOTO's (and GOSUB's) can cause "spaghetti code" to be the end result. Unfortunately, if the compiler does not support functions and procedures (what is commonly referred to as "structured programming") you may not have a choice.

    Best to follow what the manual says "While GOTOs may be a necessary evil, try to minimize their use as much as possible."

  7. #7
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rmteo View Post
    GOTO's (and GOSUB's) can cause "spaghetti code" to be the end result. Unfortunately, if the compiler does not support functions and procedures (what is commonly referred to as "structured programming") you may not have a choice.

    Best to follow what the manual says "While GOTOs may be a necessary evil, try to minimize their use as much as possible."
    Right, but I need them to have bypass when multiple IF statements are used so not all IF are checked.

  8. #8
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    What is so weird is that I seem to be able to get an interrupt on RA4 like I do with the other pins on this port but when in the int handler, it's dead, as if it cannot read the incoming pulses.

    Now I'm reading again the fuctions for this pin and I see CLOCKOUT (which should not be a problem as I disabled CLOCKOUT in the CONFIG words and this pin is an input anyway).
    I also see 'T1G_' (TIMER1 GATE INPUT)! As I'm using TIMER1 to measure/time the pulses incoming on the pins, IF I didn't set the TIMER1 registers right, then this pin is thinking a LOW going pulse is a Timer1 gate input...?
    My current TIMER1 settings are:
    T1CON = %00011100 '1:2 prescale for 1US increments, timer 1 is stopped

    I'm not sure exactly what settings I should use as the datasheet is not very clear to me.
    BIT7: I will invert the gate (which is by default: low) so it will not interfer with my pulse (my TSOP IR sensors pulls low the pin when getting IR signal)
    BIT6: (Time1 gate enable bit): it says if TIMER1 is on, "0" is 'Timer1 is on', "1" is 'Timer1 is on if Timer1 gate is not active'... what a strange and complicated way to say things... !!! Well, I think I should clear this bit...
    I will try with the register set to : T1CON = %10010100

    Why do the datasheet have to be soo intricate...
    Well.
    I've tried the T1CON = %10010100 and it works.
    I will test again but it seems to be the solution. My signal pulse was pulling the pin low as it would have been TIMER1 INPUT.
    Always check the various functions of a pin.
    I already had the surprise when connecting an I2C EEPROM to ports that would be set as ANALOG or DIGITAL and using a bigger PIC I didn't expect anything else than ANSEL but there was ANSELH too

Similar Threads

  1. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 19:54
  2. Replies: 14
    Last Post: - 26th September 2007, 05:41
  3. Problems with RC2 and RC3
    By Christopher4187 in forum General
    Replies: 11
    Last Post: - 29th May 2006, 17:19
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10

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