To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 8282
8281  |  8283
Subject: 
Re: IC problem
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Sun, 4 Feb 2001 22:44:42 GMT
Viewed: 
824 times
  
Hi.

The default process is running of out stack.   This is because you've
written a program in which one function calls another, which calls another,
which calls the first.  Each time a function is called, an internal "call
stack" must keep track of the nestedness.  If you've looped them to each
other (think of a snake eating its tail) eventually you run out of this
stack memory.

Instead, write a program like this:

void main() {
  while (1) {
     dosomestuff();
     doadifferentthing();
     whynottryathirdthing();
  }
}

That's your main loop.  The "while (1)" keeps it from ever finishing.

Each of the three "dosomestuff" functions must exit.  So, e.g.:

void dosomestuff() {
  fd(0);  /* turn on motor 0 */
  fd(1);  /* turn on motor 1 */
}

Then when that finishes, control will return to main, which will continue
with the next function.

Fred



In lugnet.robotics.handyboard, John R. Edwards writes:
I have written a small program for the Handyboard to test program flow in
IC. It is supposed to print "Step1", "Step2", Step3" in sucession to the LCD
in an endless loop until I reset the board. It works properly through 12
cycles but on the 13th cycle, the program hangs up and "RUNTIME ERR 04" is
printed out on the LCD. According to the HB Technical Reference Manual this
is indicating a stack overflow error in running process but I am not running
any processes that I know of. If anyone could help me out and tell me where
my mistakes are I would be most thankful.

John Edwards

The following is my troubled program:

/******************/
/*  Test_Loop.c   */
/******************/



int n;

void main()                       /* Push Start Button to Start */
{
while(!start_button());
increment();
while(start_button());
}

void increment()                  /* Add 1 to n each time through */
{                                /* When n becomes larger than 3 */
n =  n + 1;                     /* n is reassigned the value of 1 */
if(n < 1)
  {
   n = 1;
  }
if(n > 3)
  {
   n = 1;
  }
control();
}

void control()                    /* Reads Global Variable and */
{                                /* Directs program to one of */
if(n == 1)                      /* the Step# functions */
  {
   step1();
  }
if(n == 2)
  {
   step2();
  }
if(n == 3)
  {
   step3();
  }
}

void step1()                      /* Prints Step Number, Delays .1 second */
{                                /* then Returns program to increment
function */
printf("\nStep1");
sleep(.1);
increment();
}

void step2()                      /* Prints Step Number, Delays .1 second */
{                                /* then Returns program to increment
function */
printf("\nStep2");
sleep(.1);
increment();
}

void step3()                      /* Prints Step Number, Delays .1 second */
{                                /* then Returns program to increment
function */
printf("\nStep3");
sleep(.1);
increment();
}



Message has 1 Reply:
  Re: IC problem
 
Fred and Jim, Thank you for your quick responses. I can now see that I was trying to make a relatively simple piece of code very complicated. I rewrote the program using Fred's suggestions and wound up with the following simple, efficient program (...) (24 years ago, 5-Feb-01, to lugnet.robotics.handyboard)

Message is in Reply To:
  IC problem
 
I have written a small program for the Handyboard to test program flow in IC. It is supposed to print "Step1", "Step2", Step3" in sucession to the LCD in an endless loop until I reset the board. It works properly through 12 cycles but on the 13th (...) (24 years ago, 4-Feb-01, to lugnet.robotics.handyboard)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR