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 / 8283
8282  |  8284
Subject: 
Re: IC problem
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Mon, 5 Feb 2001 03:30:49 GMT
Viewed: 
1129 times
  
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 that works as I had originally wanted.

John Edwards

/******************/
/*  Test_Loop1.c  */
/******************/



int n;

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

void increment()
{
  while(1)
   {
    step1();
    step2();
    step3();
   }
}


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

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

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


In lugnet.robotics.handyboard, Fred G. Martin writes:
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



Message is in Reply To:
  Re: IC problem
 
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 (...) (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
    

Custom Search

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