CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

restart main() in 10 seconds

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Darknight23



Joined: 08 Nov 2005
Posts: 4

View user's profile Send private message

restart main() in 10 seconds
PostPosted: Tue Nov 08, 2005 6:50 pm     Reply with quote

I'm using a 16F818, and I've read about using Timer1 as a real-time clock, but is there an easier way to do this? If a loop executes for 10 seconds I wanted to restart the main() method.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 08, 2005 6:55 pm     Reply with quote

What is the reason for doing this ?

1. Is this 10 second period a test for program lock-up ?
In other words, are you really talking about a Watchdog Timer ?

2. Or is it just a normal part of program operation, such that
you want to jump to the start of a loop after 10 seconds ?

3. Do you really want to go to the start of main(), or do you
want to go to the start of a while() loop in your program ?
Darknight23



Joined: 08 Nov 2005
Posts: 4

View user's profile Send private message

PostPosted: Tue Nov 08, 2005 6:59 pm     Reply with quote

The loop is actually within another function separate from main(). Yes it is apart of the normal operation, therefore a WDT wouldn't be appropriate. Basically restart the PICs operation after a specified time. Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 08, 2005 7:58 pm     Reply with quote

Can you explain what the basic purpose of your program is ?

The method that you have conceived, may not be the best
possible way to design the program.
Darknight23



Joined: 08 Nov 2005
Posts: 4

View user's profile Send private message

PostPosted: Tue Nov 08, 2005 8:31 pm     Reply with quote

Sure, I have 3 infrared sensors mounted on the front of a remote control car. The middle IR detects the object around 1 ft and turns on the top/bottom IR. The top and bottom IR are used for close range detection. When top/bottom IR detect the object, the car is supposed to stop. I'm currently working when the middle IR detects an object, the middle IR turns on, and turns on the close range IR. After a specified amount of time, if the top/bottom IR do not detect anything, the car should then restart to its start up state: Middle IR on, Top/bottom IR off, forward motion, with normal speed.

The program is controlled with this in main():

Code:
while(1)
   {
      reset();
      detect_far();
      detect_near();
   }


In the detect_near() method, I after a certain time, if the top/bottom IR doesn't detect anything, I want it to go back to the while(1) in the main method.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Tue Nov 08, 2005 9:14 pm     Reply with quote

Darknight23 wrote:


Code:
while(1)
   {
      reset();
      detect_far();
      detect_near();
   }



It strikes me that this code will never get to detect_far(), becasue it will resetin the first line of the while loop.

As a general comment, resetting the PIC just to restore the initial conditions is quite a non-orthodoxal approach. It may work fine, if you don't want to retain certain values all the time.

Consider the following algorithm (although there are many ways to skin this cat):

Code:

void main()
{
   init_global();      // initialize global variables
   init_hardware();   // initialize hardware
   
   while (1)
   {
      if (detect_far())
      {
         while(elapsed < 10sec)
         {
            if (detect_near()
            {
               stop();
            }
         }
      }
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group