Need help with scaling


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    I guess what I'm asking is how to take the 0 and 1 bit from one number and put them into a seperate number so that I can further scale just those two bits. Thanks!!!

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by champion
    I guess what I'm asking is how to take the 0 and 1 bit from one number and put them into a seperate number so that I can further scale just those two bits. Thanks!!!
    This will give you a value with just the first two bits of the original byte:

    TwoBits = OrigByte & %00000011

    HTH,
    Steve

  3. #3
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Possibly a more complete answer.

    Here may be a more complete answer to your question:

    Code:
    PotValue  VAR BYTE
    Degrees   VAR WORD
    Minutes   VAR WORD
    
    
    Degrees = Potvalue * 14118    ' Convert to degrees and fractional Degrees
    			      ' scaled by 10000.
    	' It does not matter that we assign Degrees a value before DIV32,
    	' since DIV32 uses only internal PBP variable in the calculation
    	' It is important that DIV32 follows right after the Multiply
    			      ' 
    Degrees = DIV32 10000         ' Returns degrees
    Minutes = R2                  ' Returns the remainder of the division,
    			      ' which is fractional degress scaled by 10000
    Minutes = (Minutes * 6)/1000  ' returns minutes
    Here are a couple of nice threads by Darrel Taylor dealing with exploiting PBP's integer math:

    Retrieving 32bit Multiply Result
    Retrieving Div32 Remainder (This one explains "Minutes = R2". See the last post in the thread)
    32-bit Variables and DIV32, Hourmeter 99999.9

    Steve

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default One last thing...

    It seems a little over-kill to be getting minutes when the accuracy of your measurements is not even 1 degree. That, and a pot is also not likely to give you very consistant accuracy as well. Even if you used 10 bits, you are still looking at a LSB of .35 degrees (21 minutes).

    Just my 2 cents,
    Steve

  5. #5
    Join Date
    Nov 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Thanks again for all of your help. I have tried this, and I get a two bit result, however they are not the last two digits of the potvalue * conversion. I will do more research inside the threads you listed to figure out exactly what these two bits are representing. Thank you very much for your help, and I will be sure not to forget it when/if you ever have a question in the future.

  6. #6
    Join Date
    Nov 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Steve, actually I am trying to have accuracy down to 1 minute. I have come to the conclusion however, like you say, that a pot will not have the repeatability that I will need to take on this task. I have moved on to an optical encoder with 8192 pulses per revolution and a gear ratio of 3:1. Thanks for all of your help.

Similar Threads

  1. Scaling ADC values
    By purkolator in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th November 2007, 05:14
  2. Help scaling voltage...
    By sirvo in forum Schematics
    Replies: 6
    Last Post: - 30th July 2007, 19:35
  3. 16F876 ADC problem
    By Douwe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th June 2006, 19:38
  4. 2 Decimal Numbers
    By fowardbias in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th May 2006, 06:51

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