Coding problem

Discussion in 'C Programming' started by snowdy, Aug 31, 2003.

  1. snowdy

    snowdy Guest

    Further to my post the other day:
    I am using Interactive C with my Handboard (68HC11) development system but
    I've got a problem that I am asking for help with.

    I have my code listed at http://www.fr33z3.net/code.txt

    Symptom:
    Programs fail ' Runtime error' which equates to a stack error.
    This is because my code is like going around and around (a snake chasing its
    tail is a term I've seen used)
    but I cant work out how to overcome this problem.

    Any help would be much appreciated.

    Thanks
    Jeff
     
    snowdy, Aug 31, 2003
    #1
    1. Advertising

  2. snowdy

    Nick Austin Guest

    On Sun, 31 Aug 2003 18:16:13 +1000, "snowdy"
    <@nospam> wrote:

    >Further to my post the other day:
    >I am using Interactive C with my Handboard (68HC11) development system but
    >I've got a problem that I am asking for help with.
    >
    >I have my code listed at http://www.fr33z3.net/code.txt
    >
    >Symptom:
    >Programs fail ' Runtime error' which equates to a stack error.
    >This is because my code is like going around and around (a snake chasing its
    >tail is a term I've seen used)
    >but I cant work out how to overcome this problem.


    > // Variables used throughout the program
    >
    > int range = 27;
    > int diff = 28;
    > int top = 19;
    > int current = 30;
    > int greyA = 26;
    > int greyB = 25;
    > int compass = 21;
    > int solenoid = 7;
    > int kick = 10;
    > int power = 9;
    > int sensors = 15;
    > int placement;
    > int value;
    > int ambient = 34;
    > int ambient_left = 121;
    > int ambient_right = 111;
    > int ambient_top = 165;
    > int ambient_diff = 116;
    > int attempt = 1;
    >
    > // Start of Real Program
    >
    > void main()


    int main()

    > {
    > init_expbd_servos(1);


    It's a good idea to declare functions before using them (i.e.
    include a prototype)

    > start_process(direction());


    Two more functions called without a declaration.

    Furthermore note that this calls direction() and passes its
    return value into start_process() as it's parameter value.
    The significance of this will be apparent later.

    [snip]

    > void direction()


    OK. So direction() doesn't return a value. This makes the
    call to direction() an error.

    > {
    > while(1)
    > {
    > if(analog(diff) > ambient_left)
    > {
    > placement = 1;
    > }
    > if(analog(diff) < ambient_right)
    > {
    > placement = 1;
    > }
    > }
    > }


    And direction() itself is an infinite loop! Therfor your
    program will never get as far as the call to start_process().

    I have to make a guess here that maybe the line in main()
    should have read:

    start_process(direction);

    This calls start_process() and passes as the parameter value the
    address of the function direction().

    If you include valid prototypes for all the functions you call this
    would have been immediately obvious. It should also point you to
    several instances of mis-matched parameter types that are in your
    code.

    Nick.
     
    Nick Austin, Aug 31, 2003
    #2
    1. Advertising

  3. snowdy

    Fr335tyl3r Guest

    Thanks for your help nick, however, this isnt the problem that we have. A
    lot of the problems that you spoke of are actually a feature of IC that we
    are taking advantage of. Interactive C contains libraries of commands that
    you can call such as init_expbd_servos(int) and start_process(function) that
    you can use to do different things.

    > It's a good idea to declare functions before using them (i.e.
    > include a prototype)
    >


    See above

    > > start_process(direction());

    >
    > Two more functions called without a declaration.
    >
    > Furthermore note that this calls direction() and passes its
    > return value into start_process() as it's parameter value.
    > The significance of this will be apparent later.
    >


    I understand the point that you are making with the passing of values.
    However, the start_process command begins multitasking within the Handyboard
    processor so that you may have 2 functions sharing processor time and
    running concurrently. Usualy this type of command would pass the result of
    direction to start_process, but in this case it begins a multitask of
    direction and main.

    >
    > > void direction()

    >
    > OK. So direction() doesn't return a value. This makes the
    > call to direction() an error.
    >


    See above, the call to direction starts multitasking, not return an int
    value

    > > {
    > > while(1)
    > > {
    > > if(analog(diff) > ambient_left)
    > > {
    > > placement = 1;
    > > }
    > > if(analog(diff) < ambient_right)
    > > {
    > > placement = 1;
    > > }
    > > }
    > > }

    >
    > And direction() itself is an infinite loop! Therfor your
    > program will never get as far as the call to start_process().
    >


    See above again, the infinite loop is required so that the multitask is
    maintained. Once the process is started, the main task continues so this
    will not cause a problem in the HB.

    > I have to make a guess here that maybe the line in main()
    > should have read:
    >
    > start_process(direction);
    >
    > This calls start_process() and passes as the parameter value the
    > address of the function direction().
    >
    > If you include valid prototypes for all the functions you call this
    > would have been immediately obvious. It should also point you to
    > several instances of mis-matched parameter types that are in your
    > code.
    >


    The prototypes are all included in libraries, so you do not have to create
    these functions yourself. Similarly, with the example you used, I believe
    the parameters are matched correctly (IC is able to debug this anyway).

    Thankyou for your help nick, but I do not believe that this is the problem.
    Do you have any other ideas?

    TIA

    Jeff
     
    Fr335tyl3r, Aug 31, 2003
    #3
  4. snowdy

    snowdy Guest

    Think I have fixed it now...

    terminated the functions that were causing the recursion!

    Thank you for your comments, they helped me step through it

    Jeff/Fr33tyl3r
     
    snowdy, Aug 31, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. smu
    Replies:
    3
    Views:
    2,646
    shobhit24
    Jun 28, 2006
  2. Bart Schelkens

    Problem with coding

    Bart Schelkens, Jul 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    319
    Yuk Cheung
    Jul 29, 2004
  3. Jason

    simple jsp coding problem

    Jason, Sep 8, 2003, in forum: Java
    Replies:
    1
    Views:
    429
    Joe Smith
    Sep 8, 2003
  4. calmar
    Replies:
    11
    Views:
    917
    calmar
    Feb 21, 2006
  5. richard
    Replies:
    13
    Views:
    981
    Doug Miller
    Apr 24, 2012
Loading...

Share This Page