Decimal to Degrees mathematics help


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1

    Default Decimal to Degrees mathematics help

    Hi All,

    I'm working on some code to read a AC or DC motors position
    using a potmeter as indicator having max 5V at the whiper

    I'm using the 16F819 with 10bit AD

    I was wondering how I can convert the AD word value to 360 deg, as PBP has
    limited math possibilitys

    In the final code I want to implement a setup routine so that I can determine
    which Digtal value (word) corresponds to 360deg or max azimuth to do the final divide

    Can someone help me with the mathematics part as I dont see how to do that

    Lets say that we have the following variables:

    AZdeg position 0 to 360 deg
    AZdig position from AD convertion
    AZdigmax value which corresponds to 360deg (during setup) so here we have to determine the divide ratio

    Thanks all for your time reading my request

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


    Did you find this post helpful? Yes | No

    Default

    If what I understood is correct, then a simple experiment could be as follows.

    At 0 degree, record ADC value. Say it shows 150 (this would be your base value).

    At 360 degree, record ADC value. Say it shows 900.

    Then each degree would become as;
    (900-150) / 360 = 2.

    That means, when your ADC reading is 152, you will know that you are at 1st degree, 154 is 2nd, 156 is 3rd. etc...

    With an additional math, which I am sure you can figure out, you can get the exact degree.


    Was this what you needed, or I am in a different page?



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

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer

    At 0 degree, record ADC value. Say it shows 150 (this would be your base value).

    At 360 degree, record ADC value. Say it shows 900.

    Then each degree would become as;
    (900-150) / 360 = 2.

    That means, when your ADC reading is 152, you will know that you are at 1st degree, 154 is 2nd, 156 is 3rd. etc...

    With an additional math, which I am sure you can figure out, you can get the exact degree.


    Was this what you needed, or I am in a different page?



    ----------------
    Hi, Sayzer

    ... life is easy with you !!!

    RF:

    at first, be sure to use the posssible max of the ADC range for your measure ...

    As said by sayzer, read the min ( 0°) and Max ( 359.9 °)

    then you get a result between 0 and 1023 ... no use to look at a better than .1% precision ( humour )

    But, to keep decimals, just multiply the result by ... 64 , to use the max counting possibilities of the Pic.

    so, let's make it clear:

    Scale = MaxValue - MinValue

    dummy = ( AdcResult - MinValue ) x 64

    ' disable interrupts ... if necessary

    dummy = dummy x 360

    Result_64 = DIV32 Scale

    ' re enable

    Now, dividing Result_64 by ... 64 ( 6 right shifts ...) give the INT part.

    ... and , if needed, the 6 right digits will give 64 x the decimal part.... a little bits shifting ( or multiplying i.e. by 100 )and you can show it !!!


    life is sooooooooo simple ....

    Alain
    Last edited by Acetronics2; - 2nd October 2006 at 09:43.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Be My teacher Alain!


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

  5. #5
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Keep in mind that "normal" potentiometers are NOT very linear. There are special types for positioning purposes.

  6. #6
    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

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