J
Jay
Hey Guys,
I need an algorithm/formula to do the following:
I have two 32-bit timers cascaded to form a 64-bit timer, max value
per timer(50sec). This is the way they work:
value | timer1 | timer2
5 50 3
when timer1 counts down to zero, timer2 would count down to two.
Timer1 would reload the value 50 and start counting down, this goes on
till timer2 reaches zero.
I need to be able to load them most efficiently. So, pseudo-code looks
like this??
if (value < max_value)
load timer1 = value;
load timer2 = 1;
if (value == even number) && (value < max_value*2)
load timer1 = value/2;
load timer2 = 2;
For a list of different values:
value | timer1 | timer2
10 | 10 | 1
50 | 50 | 1 (max_value)
60 | 30 | 2
80 | 40 | 2
100 | 50 | 2 (max_value*2)
110 | 11 |10
Now the fun starts, since I cannot load timer1 with a value more than
50, I have to split the value 110 so that timer1 would have the
maximum value possible. Some more scenarios,
120 | 30 | 4
150 | 50 | 3
160 | 40 | 4
I just can't see a pattern to implement an algorithm. Any help will be
greatly appreciated.
I need an algorithm/formula to do the following:
I have two 32-bit timers cascaded to form a 64-bit timer, max value
per timer(50sec). This is the way they work:
value | timer1 | timer2
5 50 3
when timer1 counts down to zero, timer2 would count down to two.
Timer1 would reload the value 50 and start counting down, this goes on
till timer2 reaches zero.
I need to be able to load them most efficiently. So, pseudo-code looks
like this??
if (value < max_value)
load timer1 = value;
load timer2 = 1;
if (value == even number) && (value < max_value*2)
load timer1 = value/2;
load timer2 = 2;
For a list of different values:
value | timer1 | timer2
10 | 10 | 1
50 | 50 | 1 (max_value)
60 | 30 | 2
80 | 40 | 2
100 | 50 | 2 (max_value*2)
110 | 11 |10
Now the fun starts, since I cannot load timer1 with a value more than
50, I have to split the value 110 so that timer1 would have the
maximum value possible. Some more scenarios,
120 | 30 | 4
150 | 50 | 3
160 | 40 | 4
I just can't see a pattern to implement an algorithm. Any help will be
greatly appreciated.