some help with math


Closed Thread
Results 1 to 40 of 65

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    looking at a hex dump noticed that pokecode stores a byte as a word value in the flash , this is real waist of space , can i store the data as a word and then get it back as a byte or if needed a word if so how , this must have been done a lot before

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hey Longpole001, you asked this:

    and this i cant find a better way to do to reduce its compile size

    if val < 6 AND Menu_Select = 211 then
    lookup val,[1,2,4,8,16,32],val ' reasign val to
    gosub Show_current_sel_2 ' place "* *" on the selected channel in menu using bit pattern sleection
    endif

    Why not use the PBP command "DCD for the lookup table problem like this:

    Value = DCD Value

    When you come into the statement value will be a number between 0 and something less than 31, DCD will give it a value based on the bit position which is what you are doing with the lookup command. a value of 0 = 1, a value of 1 = 2, a value of 2 = 4 and so on. At lease that's how I would do it...
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    You might also explore the use of MAX and MIN for setting bounds in situations like:

    if Event1_OT_Hour >23 then Event1_OT_Hour = 23
    or
    if Event1_OT_Hour <1 then Event1_OT_Hour = 0
    Last edited by Amoque; - 10th September 2015 at 13:27. Reason: Sorry, missed Richard's post above.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    hi thanks for the input guys

    to get it to do what i want i used longs ;(
    which i would like to change to 2 x word variables for this one long variable "Event_Dist_Speed "

    i thinking perhaps the nbit math may work but not sure how it may be done with the calculations i have now


    Code:
    ' routine to calc speed based on sec under 18 hours 
    Distance_Calc_Speed0:            
                  
      if Event_Dist_Timebase = 0 then Event_Dist_Speed = Event_Dist_Value                      ' calculate speed with base in secs 
      if Event_Dist_Timebase = 1 then Event_Dist_Speed = Event_Dist_Value*60                   ' calculate speed with base in mins
      Event_Dist_Speed = Event_Dist_Speed*100/(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)  
      if Event_Dist_Timebase = 2 then gosub Distance_Speed_Calc2                               ' calculate speed with base in hours - gosub becuase it is called as a seprate display 
     ' HSEROUT [" Event_Dist_Speed = ",dec Event_Dist_Speed, 10,13] ' debug 
                 
     return   
    ' ----------------------------------------------------------------
     ' routine to calc speed based on sec 's 
    ' used when time is >18 hours so that value is < word max size            
    Distance_Calc_Speed1:            
           
    
     return   
    
    ' ------------------------------------------------------------------
    ' show KPH or MPH on every base reading formular 
    ' calculate speed with hours base 
    ' called as 2nd speed display details 
    Distance_Speed_Calc2:
        
        Event_Dist_Speed = Event_Dist_Value*360 
        if Event_Dist_Measure  = 0 then  Event_Dist_Speed = (Event_Dist_Speed*1000/5280)/(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)       ' if feet distance base 
        if Event_Dist_Measure  = 1 then  Event_Dist_Speed =  Event_Dist_Speed*100       /(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)/100   ' if meters distance base 
        if Event_Dist_Measure  > 1 then  Event_Dist_Speed =  Event_Dist_Speed*1000      /(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)       ' if Miles or KM  distance base 
       
      '  HSEROUT [" hour reading Event_Dist_Speed = ",dec Event_Dist_Speed ,10,13] ' debug 
    return                     
    
    '------------------------------------------------------------------
    
    Show_Speed_Value:
       gl_x = 0
       gl_y = 48  
       gl_k = 0 
       for gl_k = 0 to 7
            lookup gl_k,["    x.xx"],Sml_font               ' 8 chrs 
            gosub Get_Sml_font                                    ' Get Font in K9_Fonts_banners.bas    
            gl_x = gl_x+8
       next gl_k      
      
       gl_x = 0                 ' puts 5 digits of speed 00000.xx 
       g_num = Event_Dist_Speed /100  ' get the base value 00000.xx 
       gosub Sml_put_5dig
                 
       
       gl_x = 48                ' put first 2 digits of speed xxxxx.00 
       g_num = Event_Dist_Speed 
       gosub Sml_put_2dig
       
      
       
              
      
     return

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    varable ranges information

    Event_Dist_Speed input = 1 - 4096
    time = combined values of EL1 varables - time range = 1sec - 8 days ' note days varable not used as yet , base time calculations based on secs
    expect that if hours >18 then the secs will be droped and time caclulation base of mins - not tested yet

Similar Threads

  1. Help with A/D math!
    By dbodenheimer in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th March 2011, 00:51
  2. Math help please...
    By Ioannis in forum General
    Replies: 2
    Last Post: - 20th June 2008, 10:18
  3. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 10:22
  4. Math help please!!!
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th August 2007, 14:45
  5. math help
    By houa in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th January 2006, 16:58

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