sometimes skips code


Closed Thread
Results 1 to 4 of 4
  1. #1
    rasplund's Avatar
    rasplund Guest

    Default sometimes skips code

    settle:


    gosub A_to_D
    high yellow_l : high yellow_r
    if amp < 14 or amp > 18 then pause 500
    if amp < 14 or amp > 18 then settle
    if amp > 14 and amp < 18 then pause 7000
    gosub A_to_D
    if amp < 14 or amp > 18 then settle
    if amp > 14 and amp < 18 then low yellow_l : low yellow_r : ampon = 0

    the PIC16F877 is waiting for the amp value to settle. sometimes this code works..sometimes it appears to skip line 6 (no delay) and line 9 (outputs are not set low). Any one have any suggestions??

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The first observation is that for example if amp=14 then it doesn't meet any criteria.

    The second is I always try to put multiple conditional statements within parenthesis... sometimes, (certainly on early PBP compilers) multiple conditions were not actioned in what I considered a logical fashion, so rather than...

    if amp < 14 or amp > 18 then pause 500

    ...I chose to write...

    if (amp < 14) or (amp > 18) then pause 500

    ...then there's no ambiguity as to what conditions are tested against what other conditions.

  3. #3
    rasplund's Avatar
    rasplund Guest


    Did you find this post helpful? Yes | No

    Default sometimes skips code

    Thank you Melonie. I have been staring at this code for so long and I have missed the obvious....defining actions for the values 14 and 18 fixed it.

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi rasplund,

    How did you get this work ?
    if amp > 14 and amp < 18 then low yellow_l : low yellow_r : ampon = 0

    In my compiler, ":" does not work with IF statement on the same line, and also there is no ENDIF.

    So this code should do the following.

    Code:
    IF (amp > 14) and (amp < 18) then 
       low yellow_l 
    ENDIF
    
    low yellow_r 
    ampon = 0
    In this case,
    low yellow_r and ampon = 0 will work free of the IF statement.

    Was it what you needed or you needed these two inside the IF statement?





    ____________________________________
    Last edited by sayzer; - 5th September 2006 at 13:51.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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