Coding problem

S

snowdy

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
 
N

Nick Austin

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.
 
F

Fr335tyl3r

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
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.
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
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
 
S

snowdy

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top