Troubles with I2C_Write


Results 1 to 11 of 11

Threaded View

  1. #10
    Join Date
    Aug 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    While I have your attention, I'm puzzling over how to efficiently do a 10-bit by 10-bit division (which will yield a value 0<x<1) then multiply it again by 1023 to get a number (0<=x<=1023). I'd prefer not to use LONG values as they eat up precious RAM, but I also want to keep it reasonably quick. I have plenty of words set up, but no LONGs.
    Here's the math:
    a, b, and x are WORDs
    x=1023*(a-b)/(a+b)
    Any thoughts?
    EDIT: Oh. Ha ha. I don't even have LONGs to work with. Yeah... that makes a difference now, doesn't it?
    The only thing I can conceive of is using a two-fold mechanism that combines this:
    Code:
    'Shift RESULT left 10 times
    FOR Iter=1 to 10
    	RESULT=RESULT<<1
    NEXT
    with this:
    Code:
    'RESULT= B / A
    RESULT=0
    WHILE B>A
    	B=B-A
    	RESULT=RESULT+1
    WEND
    The trick is to keep the working value inside 16-bits, but inside 10 bits at the very end.
    Last edited by The Altruist; - 23rd March 2010 at 02:23.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts