Conversion to degrees help


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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
    All this math makes my head hurt , couldn't you do the math twice with different multipliers, throw out the top numbers from one, and the bottom numbers from the other and display the results together separated by the decimal point ? Or is that what you just said?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    All this math makes my head hurt , couldn't you do the math twice with different multipliers, throw out the top numbers from one, and the bottom numbers from the other and display the results together separated by the decimal point ? Or is that what you just said?
    You could do what you suggested, but I split it up to display the math involved a bit more clearly...
    If I was me as I usually am, I would've put something like this instead:
    Code:
    dummy=(position<<8)*90:result_high=div32 1024:degrees_whole = result_high >> 6
    dummy=(position<<8)*9000:result_low=div32 1024:degrees_fraction=(result_low>>6)//100
    lcdout $fe,1,"Degrees:",DEC3 degrees_whole,":",DEC2 degrees_fraction

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