Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   sleep() (http://www.chiefdelphi.com/forums/showthread.php?t=25704)

jacob_dilles 22-02-2004 20:53

Re: sleep()
 
im sorry that i have to reiterate this, but you CAN NOT stop the program code from looping! no matter if it is with a non exastant "wait()" command or a for loop that devides PI by 100 million 50 thousand times, dont do it! it is much better, and perhaps the only viable solutuion, if you count the loops rather then trying to stop in the middle of one. each loop is ~26 ms. its not that hard to make 1 variable. comon guys.

Astronouth7303 22-02-2004 21:12

Re: sleep()
 
It's not that, it's that the main loop has different iteration times depending on what is executed. Besides, It'd be so much cooller if we got it to work.

And like I said, just put calls to putdata and getdata in the loop.

KevinB 22-02-2004 21:21

Re: sleep()
 
Quote:

Originally Posted by Texan
Note that if you were using this as a timer, it would be different at different battery charges as the controller would run slower.

Ken was right when he said that the timer will always run at the same speed. Texan probably meant that the motors being controlled by the timer would run slower ... which is true.

Getting back to the original focus of this post ... why do you want a sleep function? If you post the reason for your request for a sleep function, you'll probably get much better help.

jacob_dilles 22-02-2004 21:22

Re: sleep()
 
if your going to the point where the diffrence between 23 and 26 ms matters, then use a timer inturupt. this is not a basic stamp lol

Astronouth7303 22-02-2004 21:33

Re: sleep()
 
Any wait/pause code is the basis of a DriveForTime() Routine

jacob_dilles 22-02-2004 21:35

Re: sleep()
 
Quote:

Originally Posted by Astronouth7303
Any wait/pause code is the basis of a DriveForTime() Routine

yesm. i think were arguing the same thing here.

mtrawls 22-02-2004 21:56

Re: sleep()
 
Quote:

Originally Posted by Astronouth7303
Any wait/pause code is the basis of a DriveForTime() Routine

What? DriveForTime should do some driving for a given time ... but I don't see how any waiting is implicit in the function. Am I grossly mistaken? You can use a timer interrupt to drive for the specified amount of time, all you do is say:
Code:

if (time_from_start < time_to_drive) { put code to drive here }
else { as you are done driving, move on to the next thing }

Where's the need to wait? If you are 'pausing' (stuck in the loop for some reason), you sure aren't driving. Care to elaborate your thinking on the matter?

KevinB 23-02-2004 00:00

Re: sleep()
 
Although there are easy ways to make the processor "pause" or "wait" as described above, they are probably not the best way to implement this function on the IFI Controller. The Master processor expects to receive a data packet from the user processor every 26.2ms.

This means you cannot pause the controller for longer than 26.2ms at a time and still have the control system function.

The best bet is to increment a counter every time a new data packet is received from the master processor. If you need finer control than that, use a timer interrupt.

gnormhurst 23-02-2004 17:06

Re: sleep()
 
Quote:

Originally Posted by Astronouth7303
It's not that, it's that the main loop has different iteration times depending on what is executed.

Do you mean "execution times"? I take "iteration time" to be the time between iterations of the 26.2 ms loop area. I actually measured this with a scope on Saturday, it was very interesting:

Code:

  while (1)  /* This loop will repeat indefinitely. */
  {

    if (statusflag.NEW_SPI_DATA)      /* 26.2ms loop area */
    {                                /* I'm slow!  I only execute every 26.2ms because */
                                      /* that's how fast the Master uP gives me data. */
      rc_dig_out17 = 1;  // take pin 17 high     
      Process_Data_From_Master_uP();  /* You edit this in user_routines.c */

      if (autonomous_mode)            /* DO NOT CHANGE! */
      {
        User_Autonomous_Code();        /* You edit this in user_routines_fast.c */
      }
    }
    Process_Data_From_Local_IO();    /* You edit this in user_routines_fast.c */
    rc_dig_out17 = 0;  // clear pin 17                                      /* I'm fast!  I execute during every loop.*/
  } /* while (1) */

This made a pulse of about 4 ms in duration (the "exectution time" of my code), with a (measured) cycle time ("iteration time") of about 26 ms. Hitting certain buttons would change the 4 ms to something else like 3 ms as my code changed modes, but the period remained 26 ms. It seemed pretty rock-solid. Except when very strange things were happening; see my earlier post on that. But that was something broken.

One reason a delay might be useful is to reduce the frequency of calls to Generate_Pwms(). See the reply from Kevin Watson to the post mentioned above.

-Norm

KenWittlief 23-02-2004 17:12

Re: sleep()
 
Ive been wanting to scope the loop myself, but havent got to it yet- thanks for instrumenting your RC.

One thing I have not been able to figure out. The main loop looks for new input from the OI, and if it doesnt see it, it call the user_fast code

I dont see anything in the fast code to throttle it back - can you put your toggles at the beginning and end of the fast section and see how fast it runs with your scope for us?

I thought they said it runs every 4mS or so, and you have to be carefull not to overwhelm the pwms by changing them too fast - I also think you cannot do a get_analog_value... too quickly either?

but does anyone know - is the fast code loop timed by some event (the get or put data maybe?)

and is its period consistant?

BTW - if you are looking at timing be sure to comment out all your printf statements - there seems to be a whole library of code behind them, I think they will make a drastic reduction in your loop speed.

mtrawls 23-02-2004 22:22

Re: sleep()
 
Quote:

Originally Posted by KenWittlief
BTW - if you are looking at timing be sure to comment out all your printf statements - there seems to be a whole library of code behind them, I think they will make a drastic reduction in your loop speed.

I can say from experience that the printf libraries do make a difference. All the "horror" stories my SICP instructor told me a couple of years ago about debug statements causing or removing bugs (the act of observing disturbs the observed?) have come true. Using the timing interrupts and for our auton code (on the EduBot at least), I've come across situations where putting a printf statement causes problems .. and then where it removes them. Needless to say, it was a pain figuring out that the printf statement caused it -- luckily my old teacher had warned me, or I wouldn't have even thunk it.

velocipenguin 23-02-2004 22:30

Re: sleep()
 
Quote:

Originally Posted by mtrawls
All the "horror" stories my SICP instructor told me a couple of years ago about debug statements causing or removing bugs (the act of observing disturbs the observed?) have come true.

Bugs like those are colloquially known as "Heisenbugs", after Heisenberg's Uncertainty Principle, which states that observing something will alter that which you are trying to observe. They're ever-so-fun to track down.

KenWittlief 24-02-2004 07:42

Re: sleep()
 
putting debug statements in code is a significant change to its content.

HW guys have it even worse - Every HW engineer I know can tell you about some circuit they worked on that they were testing with a scope, and as long as the scope was connected, the circuit worked, but when you remove the probe it stopped working

all due to the slight capacitance of the probe altering the circuit they were trying to see.

gnormhurst 24-02-2004 10:05

Re: sleep()
 
Quote:

Originally Posted by KenWittlief
I've been wanting to scope the loop myself, but havent got to it yet- thanks for instrumenting your RC.

Thanks, but I got the idea from someone on this forum.

Quote:

One thing I have not been able to figure out. The main loop looks for new input from the OI, and if it doesnt see it, it call the user_fast code.

That took me a little time to figure out. The fast code (Process_Data_From_Local_IO()) is called every loop of the while(1) loop. The "slow" user code is called in addition very occasionally in the while(1) loop when new data is ready (if (statusflag.NEW_SPI_DATA) ).

Quote:

Don't see anything in the fast code to throttle it back - can you put your toggles at the beginning and end of the fast section and see how fast it runs with your scope for us?
I did that, too, at the time, just to see. I didn't measure the rate, but it looked like hundreds of times for each call of Process_Data_From_Local_IO(). An easier, non-scope way would be to run a counter in the main while( 1 ) loop, then print it and reset it just before calling Process_Data_From_Local_IO().

...I was doing integer division in a few places in my joystick calculations and I was worried that my code was too slow, but was relieved to see that it runs in only 4 ms. Whew!

deltacoder1020 24-02-2004 11:10

Re: sleep()
 
Don't worry - for the most part, integer division is just fine. It's only when you get into floating-point numbers that math operations start to kill you.


All times are GMT -5. The time now is 15:17.

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