Conversion to degrees help


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Thank you skymath
    I will give it a try this evening
    I have PBP 2.50 need to patch to 2.50b, what is special in 2.50 regarding to
    my conversion problem, dont find anything in the changes log that points to that



    Quote Originally Posted by skimask View Post
    This might get you 2 behind the point...
    Code:
    scale = 1024
    dummy = position << 6'wont overflow 16 bits, same as *64 but quicker
    dummy = dummy * 360 'will overflow 16 bits
    result_high = div32 scale 'but doesnt matter here
    degrees_whole = result_high >> 6 'same as divide by 64 but quicker
    
    scale = 1024
    dummy = position << 6 'wont overflow 16 bits, same as *64 but quicker
    dummy = dummy * 36000 'will overflow 16 bits
    result_low = div32 scale 'again, doesnt matter here
    degrees_fraction = result_low >> 6 'same as divide by 64 but quicker
    degrees_fraction = degrees_fraction // 100 'take out the -whole- degrees and leave the fraction
    
    lcdout $fe , 1 , "Degrees:" , DEC3 degrees_whole , ":" , DEC2 degrees_fraction
    This should work for a 10 bit ADC, but for a 12 bit ADC, the 2nd chunk will overflow. Changing the 36000 to 3600 and 100 to 10 should let the 2nd chunk work with one digit behind the decimal point, or change 36000 to 9000 and 100 to 25 and you'll get 2 digits behind the decimal point but in steps of .04

    And upgrade to PBP 2.50b

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    LONGS!!!!
    Look in your manual on the different variable types. 2.5 can do 32 bit +numbers
    or 31 bit - numbers. Something like that. The negative takes up a bit.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Lightbulb Don't forget the "*/" and "**" operators.

    OK, You want to scale a number by a constant factor. This is pretty easy using the "*/" and "**" operators. This way you can save some time since the calculations are pretty easy to do for the processor, no divisions only one multiplication. You can learn more about them here http://www.emesystems.com/BS2math1.htm . A short way of describing them is that "*/" makes an invisible division by 256 and "**" divides by 65536.

    Older versions(pre 2.50) can only use WORD sized(16 bits) variables, meaning your result must be 65535 or less.
    1024 to 360. Degrees = position */ 90 or Degrees = position ** 23040
    1024 to 3600. Degrees = position */ 900
    1024 to 36000. Degrees = position */ 9000

    4096 to 360. Degrees = position ** 5760
    4096 to 3600. Degrees = position */ 225 or Degrees = position ** 57600
    4096 to 36000. Degrees = position */ 2250

    If you have PBP2.50 you can have your result bigger than 16 bits. 360000 is then possible.
    1024 to 360000. Degrees = position */ 90000
    4096 to 360000. Degrees = position */ 22500

    /Ingvar

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Thanks Ingvar or should I say "professor Math" !

    give it a try this evening

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. Conversion problem
    By eva in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th March 2007, 18:21
  4. Help for decimal conversion
    By eva in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th March 2007, 18:20
  5. 16bit variable and degrees conversion
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd May 2005, 17:27

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