Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/25/09 12:47
Modified:
  04/25/09 13:10

Read: times


 
#164830 - Simple scheme...
Responding to: ???'s previous message
The idea already discussed by others here is very simple. Let's have an example:

Start byte is "39", end byte is "130" and numbers of steps is "11". Then the correct steps' witdh would be (130 - 39)/11 = 91/11 = 8.27272727...

Unfortunately, it would consume much time to accurately calculate this quotient and to add this quotient 11 times to "39" later.

Nevertheless, the DIV AB routine of 8052 can be used to do the trick. When A=91 and B=11 the DIV AB instruction yields A=8 and B=3, corresponding to 91/11 = 8 + 3/11, where "3" is the remainder.

The idea is now to make the steps' width just "8" and to neglect the decimal places. By this an error is produced which is just 3/11!

If two times "8" is added instead of "8.27272727...", then the error accumulates to (3+3)/11 = 6/11. If three times "8" is added, then the error acccumulates to (6+3)/11 = 9/11.

This error term, in the following called "ET", helps to correct the simplified steps' width of "8", because if the error term after an adding of "8" is ET >= 6/11, then not "8" should have been added but "9". After doing so the error term must be corrected by substracting 11/11, of course.
If the error after the adding of "8", on the other hand, is ET <= 5/11 then the adding of "8" was correct.


Let's proceed with the example:

39+8=47, ET=3/11, nothing to correct
47+8=55, ET=(3+3)/11=6/11, correction: 55+1=56, ET=(6-11)/11=-5/11.
56+8=64, ET=(-5+3)/11=-2/11, nothing to correct
64+8=72, ET=(-2+3)/11=1/11, nothing to correct
72+8=80, ET=(1+3)/11=4/11, nothing to correct
80+8=88, ET=(4+3)/11=7/11, correction: 88+1=89, ET=(7-11)/11=-4/11

And so on...


With each step you add "3" to the numerator. And if a correction is needed, then you subtract "11" from the numerator.

In the actual code you don't need to calculate "ET" explicitely by dividing the numerator by "11", of course. The only you have to do is to check whether the numerator is bigger than half the denominator.


Kai

List of 19 messages in thread
TopicAuthorDate
Values interpolation            01/01/70 00:00      
   A possible start            01/01/70 00:00      
      The Brezingham Line Drawing algorithm            01/01/70 00:00      
         http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm ?            01/01/70 00:00      
            Good method            01/01/70 00:00      
               Integer Digital Differential Analyzer            01/01/70 00:00      
   Simple scheme...            01/01/70 00:00      
      Further optimization            01/01/70 00:00      
         You are absolutely right, of course,...            01/01/70 00:00      
   Having a hard time trying to understand :(            01/01/70 00:00      
      Clarification Needed            01/01/70 00:00      
         Even more confused now            01/01/70 00:00      
            Another Shot            01/01/70 00:00      
               code            01/01/70 00:00      
                  Provided Code            01/01/70 00:00      
                     Maybe this            01/01/70 00:00      
                        Give this a try...            01/01/70 00:00      
            Look it up            01/01/70 00:00      
      Now, we have a hard time to understand...            01/01/70 00:00      

Back to Subject List