Go to Post Putting 2 and 2 together, and then mixing them back up for someone else to try and get 4 in a different way is just plain fun. - Elgin Clock [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Spotlight this post!  
Unread 05-02-2007, 15:35
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: Commands

There are two different types of delays: blocking and non blocking. A blocking delay halts execution of EVERYTHING for that amount of time. A non-blocking delay only affects a small portion of the code.

I believe you are looking for a non-blocking delay. I would suggest adding a counter to your code that increments at the top of the control loop.

Code:
time_counter+=1;
if(button_pressed && time_counter>desired_delay)
    do stuff;
    time_counter=0;

rest of code
desired_delay would be equal to the amount of time you want to delay in seconds divided by the frequency of your control loop. I think that frequency is 40Hz, but please someone correct me. Therefore, desired_delay = 2seconds / 40 Hz = 80.

If you are looking for a blocking delay, you have several options, two of which I have outlined below.


The simple (read "simple"" as "bad") way is to simply spin in a loop.

Code:
for(i=0;i<DELAY_TIME;i++);
This is bad for many reasons, but is useable as a quick and dirty solution for small delay times, as would be seen for hacking out a bad bit banger for serial comm.

Quote:
Originally Posted by Mark McLeod View Post
Any substantial delay in that version causes the processor to be disabled.
I am guessing that this means that there is a watchdog that is timing out. If you really want to, you could delay, pet the watchdog, delay some more, pet him again, delay more, etc. When you get to this point, you are probably doing something wrong.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Relay Commands Matt Krass Programming 6 18-02-2006 23:03
Serial Commands on MPLAB tribotec_ca88 Programming 2 24-01-2006 16:26
at commands in c++ daroch Programming 1 04-03-2005 01:01
Kevin's Commands.h?? kshot Programming 3 17-02-2005 17:12
Voice Activated commands Amber H. Technical Discussion 40 03-11-2002 12:40


All times are GMT -5. The time now is 04:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi