speed Calculations


Closed Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default speed Calculations

    Hi guys ,

    i need to do some simple speed calculations in PBP 3 on 18f67k22 pic , that is very very full PIC already.

    i have not had to do floating point calculations before and not sure if i need to now for this but i suspect i do, hope i dont cos i believe the overheads can be high .

    i have options / variables that select the following for the displayed / recorded results

    Display Distance base measurement
    00 = Feet
    01 = meters
    02 = miles
    03 = KM

    Display Time base measurement
    00 = time in sec
    01 = time in minutes
    02 = Time in Hours
    03 = LAP SPEED

    Distance input values
    0 - 4000

    Time input values

    days, hours , min, sec , 1/100th


    i would like to display the speed for the selected option , with a result to 2 decimal places

    can you advise the best way to get this started for the least likely overhead in code space


    Cheers

    Sheldon

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    You didn't give range of variables...
    One way is just multiply distance with 100, and put decimal separator fixed on display in result, if long variable have range to do that...

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    i cant see multiy by 100 is going to help
    speed = distance / time

    also cant see how i can avoid floating points and longs again ;(


    distance = distance base measurement ( feet or meters or km or miles ) x distance input value
    time = time base measurement ( sec or mins or hours or lap count ) x time measured value

    for the caclulation of distance i though convert all values to meters as common base value


    if meters option then Distbase_value = 1 ' = 1 meter
    if feet option then Distbase_value = 3.28 ' = feet to meters
    if Km option then Distbase_value = 1000 ' = 1 km in meters
    if Miles option then Distbase_value = 1609.34 ' = 1 mile in meters

    Dist_input = 0 - 4000
    Distbase_value x Dist_input = Distance ' 24 bit number max ???



    Calculation for Time base - make a sec the common base to work to

    if sec option then Timebase_value = 1 ' = 1 sec base
    if min option then Timebase_value = 60 ' = 60 sec in min
    if hour option then Timebase_value = 3600 ' = 3600 sec in hour

    TimeValue = days/hours/min/sec /1_100th - convert time to secs base

    timevalue = days x 24 x 60 x 60 ' days
    timevalue = timevalue + (hours x 60 x 60) ' hours
    timevalue = timevalue + ( mins x 60) ' mins
    timevalue = timevalue + sec ' sec
    timevalue = timevalue + (100th / 100) ' 1_100th

    timevalue eg 12456.78

    timebase x timevalue = Time


    speed = distance / time ' speed is a max 32bit positive number

    is this seem right or am i doing the long and hard way , with larger number than need to

    i am just starting to read up on Floating point , with the include of "FP1832.bas" and what i think is required as well , but not sure where to put them yet in the program of Fp32.A18 and math18.inc files

    sheldon

  4. #4
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    By multiply your number with 100 you shift result for 2 decimal places.
    Eg:
    10/3=3.333
    If you are using integer, result is 3.
    If you multiply 10 with 100, (10*100)/3=333.333, using integer's result is 333. Put dot on in front of second digit, and displayed result is 3.33. And you get your result with 2 decimal places.
    This is explained too many times when using ADC to display voltage on input...

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    would it not be easier to decide on a basic speed unit first ie miles/hour , kph or meters/sec.
    even yards per month or whatever then just convert it to the desired display format

    for my money i'd pick meters/second

  6. #6
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    id like to use sec/meters as the only option but i dont know what option is to be used on the day , and must allow for each possible one described

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    and

    1 m/s = 2.236936292054402 mph =3.3 kph =1.943844492440605 knots=3.280839895013123 ft/s =0.0029386414601757 mach ................................

    id like to use sec/meters as the only option
    as I said
    or whatever then just convert it to the desired display format
    to have any chance of doing this efficiently we need to know
    min and maximum for each of these quantities
    1 velocity
    2 distance
    3 time
    otherwise its just pissing in the wind

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


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    as a surprise ...

    1 foot = 78/256 meter

    1 mile = 412/256 kilometer

    Which are more than easy to calculate in PBP ...

    others are obvious ...

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  9. #9
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    have any chance of doing this efficiently we need to know
    min and maximum for each of these quantities
    1 velocity
    2 distance
    3 time
    otherwise its just pissing in the wind
    velocity - max = 300km /hour
    distance input max = 4000 ,
    options of distance base is miles/km/meters/feets
    timer allows for 7days 23hours ,59mins, 59,sec,. 99 1/100th - before rolling to 0.00
    timer base for speed measurments is sec, min, hour,

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    1. so worst case

    max distance 4000 miles = 6437376 m
    max time = 8 days = 69120000 1/ 100's of a second

    v=(d/time)/100 (d in meters ,time in 1/100's of a second) = v in m/s
    velocity= (6437376/69120000) /100 (to two decimals) as m/s
    velocity= (6437376/69120000)*36 /1000 (to two decimals) as kph

    and using Alain's figures
    velocity= (6437376/69120000)*256 /(100*78) (to two decimals) as ft/s

    etc.....................
    just keep within the range of unsigned longs


    a better strategy would be to examine the magnitude of the time and switch to hours at a suitable size and ditto for distance switch to kilometres for larger distances. you may be able to avoid longs
    that way
    Last edited by richard; - 4th November 2014 at 03:27.

  11. #11
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    yes like to avoid longs if i can for code space

  12. #12
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    btw u pic a good horse today richard

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    could not even get last in the sweep

  14. #14
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    in a starting point i am trying to "include FP1832.bas" , into the program with fp32.a18 , math18.inc in the programs working directory , but getting lots of asm errors symbol not prev defined 113 as a result , what am i forgetting ?

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


    Did you find this post helpful? Yes | No

    Thumbs up Re: speed Calculations

    Quote Originally Posted by richard View Post
    a better strategy would be to examine the magnitude of the time and switch to hours at a suitable size and ditto for distance switch to kilometres for larger distances. you may be able to avoid longs
    that way
    +1000

    and moreover if only two decimals are needed for the result ...

    might be the " Arduino syndrom " ( extensive use of floats ) ???

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  16. #16
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    i would love to avoid floats or long at all , which means a lot more if/then for ranging of the inputs for the distance and time options for a given time / distance input

    the result display would be returned to 1 byte for decimal display use , and a word value for the above decimal use ,
    i am bit lost on this one on how to get it going atm would not be too bad normally but i have only small amount of code space left , i am still trying to claw back some code space elsewhere

    varables i have so far

    Display Distance base measurement selection option

    00 = Feet
    01 = meters
    02 = miles
    03 = KM

    Display Time base measurement selection option
    00 = time in sec
    01 = time in minutes
    02 = Time in Hours
    03 = LAP SPEED

    Distance input values
    0 - 4000 - 2 bytes

    Time input values

    days, hours , min, sec , 1/100th - all 1 bytes

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    one of the first rules in mathematical calculations is that 2000/2.xx is accurate to 0 decimal points
    2000.0 / 2.xx is accurate to 1 decimal point. to be accurate to 2 decimals all!! input figures must be measured to two decimals , otherwise its fantasy

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    actually its worse than I made out
    see this
    http://courses.chem.indiana.edu/s117...on-SigFigs.pdf

  19. #19
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: speed Calculations

    that was interesting read and a worry in how calculations can go astray , i guess i am looking for no better than if i put distance / time into online calc i get it to 2.dec places , as best as possible

Similar Threads

  1. CRC Calculations
    By timmers in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th June 2009, 17:10
  2. clock/timer calculations
    By virolay in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th January 2008, 20:20
  3. Incorrect calculations... please help.
    By bearpawz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th January 2007, 22:03
  4. Calculations for using faster Clocks.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th April 2005, 14:24
  5. timing calculations
    By scorpion in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2004, 22:58

Members who have read this thread : 1

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