View Full Version : 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
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
a better way to set up a timer, if you are comfortable with it, is to use the processor interrupts. www.kevin.org/frc (http://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
a better way to set up a timer, if you are comfortable with it, is to use the processor interrupts. www.kevin.org/frc (http://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.
i want to know what 1 second equals to in this part
1000?
400?
what is it!?!?!?
gnormhurst
23-02-2004, 16:16
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.
static unsigned int cycleCounter = 0;
You might have some code that looks like this:
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
oooo ok thx for clearing that up ;)
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.