Decimal to Degrees mathematics help


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ingvar
    Keep in mind that "normal" potentiometers are NOT very linear. There are special types for positioning purposes.

    Multi turn pots could be a good choice for positioning.
    In 360 degree, with the help of some gears, the pot can turn 10 times.

    Thus, Alain's math can have a better accuracy.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  2. #2
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    Some things to keep in mind here (and elsewhere too):

    1) The max number from the analog conversion is 1023, which is the maximum number expressible with the 10 bits from the converter. SO, the maximum resolution you can get is 360/1023= .3519 degrees per bit

    2) Converting from raw A2D number to degrees is simple, just (assuming max reading is 1023, and min is zero) A2Dreading x 360 / 1023. However, it is important to perform the calculation by doing the multiplication first, then the division. If you divide first you’ll loose a lot of precision (do you see why?) You’re working with integer numbers here, so the decimal parts get lost quickly. Alain has a good point when he scale up the reading, just be careful you do not overflow the variable; his use of 64 is the most you can scale this number up

    Max scale factor = biggest word / biggest expected number = 65535 / 1023 = 64.0165… so use 64. PBP does have some facilities for handling double precision multiplicands (32 bit products), but that’s trouble to deal with.

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Lets make it simple.

    Try my way first.

    You will be surprised with the result.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hey Guys

    very suprised about the fast reply's , thanks to all !!!

    I will give it a try this evening.

    I agree that potmeters are not that linair, and I dont need the 0.3 deg
    precision, but 8bit is not enough

    Will try sayzers solution this evening, if it is not working i will post the code
    for the specialists

    Thanks agn

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RFsolution
    ....
    if it is not working i will post the code for the specialists

    You broke my heart !


    --------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Hi

    This is what I have but dont see any light in "my" tunnel

    OSCCON = $60
    DEFINE OSC 4
    DEFINE adc_bits 10
    DEFINE adc_clock 3
    DEFINE adc_sampleus 50

    adcresult VAR WORD
    dummy var word
    adcon1=%100000010
    maxvalue var word
    minvalue var word
    scale var word
    result_64 var word

    init:
    maxvalue = 64000 'this is 359,8 degrees
    minvalue = 2200 ' this is equal to 0 degrees

    loop:
    gosub readadc
    Scale = MaxValue - MinValue
    dummy = (AdcResult - MinValue) * 64
    dummy = dummy * 360
    Result_64 = DIV32 Scale
    SerOut 6,6,["adc=",#adcresult," scale=",#scale," dummy=",#dummy," res64=",result_64,10,13]
    goto loop


    readADC:
    ADCIN 0, adcresult
    return

  7. #7
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    OK, a lot of code, but no hint as to what is going wrong!

    When getting up a new project, try to cut it into as many small slices as possible, get first to work, then move on to the next slice.



    Slice 1: getting out debug info. Method: just post dummy data.

    Slice 2: Read A2D. Method: read it, then output as debug info

    Slice 3: Convert to degrees. Method: as discussed

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RFsolution
    Hi

    This is what I have but dont see any light in "my" tunnel

    OSCCON = $60
    DEFINE OSC 4
    DEFINE adc_bits 10
    DEFINE adc_clock 3
    DEFINE adc_sampleus 50

    adcresult VAR WORD
    dummy var word
    adcon1=%100000010
    maxvalue var word
    minvalue var word
    scale var word
    result_64 var word

    init:
    maxvalue = 64000 'this is 359,8 degrees
    minvalue = 2200 ' this is equal to 0 degrees

    .....

    You have 10bits of res. Thus you need the result as right justified. But you have adcon1=%100000010 one extra 0 is typed here. So the result becomes as left justified. Thus you get your results as 64000 and 2200.

    Change it to adcon1=%10000010. So you now have correct right justified setting.

    Then check the readings again.



    -------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. variable + decimal
    By savnik in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th August 2009, 14:21
  2. Offset to variable howto ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 3rd October 2008, 09:36
  3. Conversion to degrees help
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 5th September 2008, 18:03
  4. Help for decimal conversion
    By eva in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th March 2007, 18:20
  5. Convert a word variable to decimal
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th December 2004, 20:02

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