Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   question about autonomous timing (http://www.chiefdelphi.com/forums/showthread.php?t=25621)

zainali 19-02-2004 15:42

question about autonomous timing
 
im bit confused about 26.2 ms loop area part

does that mean 1 = 26.2 ms when i set up a counter or something? :confused:

steven114 19-02-2004 16:31

Re: question about autonomous timing
 
Quote:

Originally Posted by zainali
im bit confused about 26.2 ms loop area part

does that mean 1 = 26.2 ms when i set up a counter or something? :confused:

It means that the code within that area is executed approx. every 26.2ms, so if you increment a variable it should indicate time in approx. 26.2ms steps.

mightywombat 19-02-2004 19:54

Re: question about autonomous timing
 
a better way to set up a timer, if you are comfortable with it, is to use the processor interrupts. www.kevin.org/frc has some sample code that can be cut and pasted into your code. I knew nothing about interrupts and timers and such and after a few hours staring blindly at the screen everything clicked. its really sweet how everything works. search chiefdelphi for other threads related to interrupt driven timers

Jeff McCune 21-02-2004 11:08

Re: question about autonomous timing
 
Quote:

Originally Posted by mightywombat
a better way to set up a timer, if you are comfortable with it, is to use the processor interrupts. www.kevin.org/frc has some sample code that can be cut and pasted into your code. I knew nothing about interrupts and timers and such and after a few hours staring blindly at the screen everything clicked. its really sweet how everything works. search chiefdelphi for other threads related to interrupt driven timers

Interrupts can be very dangerous and difficult to debug. I wouldn't recommend their use for rookie teams, espically at this late date.

tml240 23-02-2004 15:12

Re: question about autonomous timing
 
i want to know what 1 second equals to in this part
1000?
400?

what is it!?!?!?

gnormhurst 23-02-2004 16:16

Re: question about autonomous timing
 
Quote:

Originally Posted by tml240
i want to know what 1 second equals to in this part
1000?
400?

what is it!?!?!?

The processor runs at 10 MHz, 10,000,000 clock cycles per second. The joystick info (etc) is only updated every 10 MHz / (2^18). That's 10,000,000 divided by 2 raised to the 18th power. 2^18 is 262144. So 10,000,000 divided by 262144 is 38.1469... cycles per second. One cycle has a duration of 1 / 38.14... = 0.0262144 second, or 26.2 milliseconds (ms).

So in one second, there are 38 or 39 cycles of the "main loop".

You can pre-calculate certain fixed periods of time (using pocket calculator or the Windows calculator accessory, not the robot controller), converting from seconds to cycles of 38 Hz:

To know when a certain pre-determined amount of time has passed, say, 11.7 seconds, figure out how many counts that would be:

11.7 / .0262144 = 446.3195801

and round to the nearest integer, because the controller works fastest with integers: 446.

A quicker way? Mutliply seconds by 38:

11.7 * 38 = 444.60000

which is 445 when rounded. A little different than 446. An even faster way that you could do in your head:

11.7 * 38 is about: 12 * 40 = 480

Close enough? Think like an engineer and make that decision yourself!

Remember, to count these cycles, declare a "static" variable. "static" means that the variable isn't lost every 26.2 ms cycle, which could happen otherwise.

Code:

static unsigned int cycleCounter = 0;
You might have some code that looks like this:

Code:

  if ( cycleCounter < 446 )
  {
    // this part gets used for the first 11.7 seconds
  }
  else
  {
    // this part gets used after the first 11.7 seconds has passed.
  }

  cycleCounter++;  // increase the cycle counter by 1.

-Norm

tml240 23-02-2004 22:58

Re: question about autonomous timing
 
oooo ok thx for clearing that up ;)


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

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