Calculation Problem - value goes to zero after 65


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Ingvar,

    OK, now we're getting silly, but I just can't resist.

    Same thing as before, With Rounding, less code.
    Code:
    Dummy = Dec_speed * 9881
    Dec_speed = R0 + R2.15 + Dec_speed
    Saved 30 Words in the process.

    OK, I'll quit now,
       Darrel

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


    Did you find this post helpful? Yes | No

    Talking Reducing even further .....

    While were on the task of reducing and optimizing Toms code, i feel a strong urge to reduce .......
    SSD4= (ssmax[18]>>4)
    SSD3= (ssmax[18] & $f)
    SSD2= (ssmax[17]>>4)
    SSD1= (ssmax[17] & $f)

    Then convert to Decimal:
    Dec_speed=(ssd4*4096)+(ssd3*256)+(ssd2*16)+ssd1 ' convert to dec
    ..... into .....
    Code:
    Dec_speed.HighByte = ssmax[18]
    Dec_speed.LowByte = ssmax[17]
    ...... thus saving time, codespace and ram ... you name it.

    How about it Darrel, want a shot at it ;-)

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Good eye Ingvar,

    I didn't even notice that he was Ripping them apart, just to re-assemble them back exactly like they were. That's a pretty big code savings.

    And, here's my "Shot at it"
    Code:
    @Dec_Speed = _ssmax + 17
    Dec_Speed   VAR  WORD  EXT
    Zero Code.

    Think we can reduce it even farther??

    Darrel

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Darrell,,


    Darrell>>Zero Code.

    Think we can reduce it even farther?? <<


    There goes the bankruptsy of Pkzip....

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

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


    Did you find this post helpful? Yes | No

    Thumbs up

    Ouch, i believe your "Shot at it" found it's target ..... sinking .... mayday. It's difficult to beat zero code, really difficult ...... sort of impossible.

    However, i want to point out that if you change the value of "Dec_Speed" you infact change the values in the array(ssmax17&18). This makes it impossible to use for other tasks, not a problem in this application(i hope). I bet you know that but some people find it difficult to get their head around this.

    Good job!

    /Ingvar

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    All true, I guess it's Bad Form to re-use variables like that.

    So here it is. The End all, Be all solution to Tom's Knot to MPH conversion.
    Code:
    @Knots = _ssmax + 17
    Knots    VAR  WORD  ext
    
    Dec_speed = Knots * 9881
    Dec_speed = R0 + R2.15 + Knots
    That way it preserves the original Knots value and calculates Dec_speed from it.

    Ok, now I really quit.

    Darrel

  7. #7
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default

    Darrel, Ingvar,

    I hope you do not mind dusting off this OLD thread.

    Quote by Ingvar... "I bet you know that but some people find it difficult to get their head around this."

    Boy was he right... Very interesting but difficult to follow for a newbie.


    I am also trying to convert knots and fractional knots to mph.h

    Darrel could you please explain/elaborate on the code from your last post...

    @Knots = _ssmax + 17
    Knots VAR WORD ext

    Dec_speed = Knots * 9881
    Dec_speed = R0 + R2.15 + Knots


    I thought that "@" usually proceeds "one line of assembly code"

    As I read through this thread, I was not able to follow with much clarity.

    In my gps program I end up with two variables containing integer knots and decimal knots.

    If we assume the variables used are knots (whole knots) and knotsten (fractional knots) how would I apply your final code to provide mph.h?

    Thanks much
    Dwight

Similar Threads

  1. Problem to compile my program
    By wagner in forum Off Topic
    Replies: 5
    Last Post: - 7th July 2008, 20:17
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. Microcode Studio 18f2455 problem?????
    By volkan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st May 2007, 21:04
  4. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

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