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