some help with math


Closed Thread
Results 1 to 40 of 65

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    If it’s bigger now, it won’t be if you put all of them in the same big array and skip to each group
    with an outer loop around that.

    Code:
    Event_OT var byte[8] ‘ or however many there are
    
    Event_OT_Day var Event_OT[0] ‘create alias to keep those names used elsewhere
    Event_OT_AllThoseOtherThings var Event_OT[1] ‘create alias
    …
    …
    
    index var byte ‘ this is re-useable for all of them
    
    if Event1_OT[0] >7 then 
    for index = 0 to 4
    Event_OT[index] = 0
    next index
    ENDIF

    You could check it isn’t cheaper to check for 0.
    It might not be now, but an earlier PBP, it would be cheaper.
    Code:
    'if Event_Penalty_Sec <1
    if Event_Penalty_Sec =0
    if your program uses the watchdog timer, there will be some buried in all of that.
    Code:
    DEFINE NO_CLRWDT
    You should get away with only one for that entire slab,
    and sprinkle any others only where needed
    Code:
    @ clrwdt
    definitely if there are any nops in code they can be replaced with them.
    Last edited by Art; - 11th September 2015 at 20:42.

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    this:
    Code:
       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 
             
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
                lookup val-6,[1,2,4,8,16,32],val 
                gosub Show_current_sel_2 
             endif
             if val =>12 and Menu_Select = 2113 then
                lookup val-12,[1,2,4,8,16,32],val 
                gosub Show_current_sel_2
            endif
    this should work instead (directly replaced) :


    Code:
    thingyousubtract var byte ‘ new variable
    
    
       if val < 6 AND Menu_Select = 211 then 
                thingyousubtract = 0 : gosub memorysavelookup      '  reasign  val to 
                gosub Show_current_sel_2   ' place "*    *" on the selected channel
             endif 
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
                thingyousubtract = 6 : gosub memorysavelookup 
                gosub Show_current_sel_2 
             endif
             if val =>12 and Menu_Select = 2113 then
                thingyousubtract = 12 : gosub memorysavelookup 
                gosub Show_current_sel_2
            endif
    
    
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    return
    and if that still works, you might as well:

    Code:
    thingyousubtract var byte ‘ new variable
    
       if val < 6 AND Menu_Select = 211 then 
                thingyousubtract = 0 : gosub memorysavelookup      '  reasign  val to 
             endif 
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
                thingyousubtract = 6 : gosub memorysavelookup 
             endif
             if val =>12 and Menu_Select = 2113 then
                thingyousubtract = 12 : gosub memorysavelookup 
            endif
    
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    gosub Show_current_sel_2
    return
    then if it still works, you should be able to:

    Code:
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    goto Show_current_sel_2
    Now this is still assuming I haven’t broken it yet, you can:

    Code:
    thingyousubtract var byte ‘ new variable
    thingyousubtract = 0
    
       if val < 6 AND Menu_Select = 211 then 
             gosub memorysavelookup
             endif 
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
             gosub memorysavelookup 
             endif
             if val =>12 and Menu_Select = 2113 then
             gosub memorysavelookup 
            endif
    
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    thingyousubtract = thingyousubtract + 6
    goto Show_current_sel_2
    Last edited by Art; - 11th September 2015 at 20:56.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    But wait there’s more!
    If you call within the next 20 minutes I’ll also throw in this rotating bit
    (but also found I broke it and got to steal some memory back)

    Code:
    thingyousubtract var byte ‘ new variable
    thingyousubtract = 0
    
       if val < 6 AND Menu_Select = 211 then 
       thingyousubtract = 0 : gosub memorysaverotate
       endif 
       if val =>6  and val <= 11 and Menu_Select = 2112 then 
       thingyousubtract = 6 : gosub memorysaverotate 
       endif
       if val =>12 and Menu_Select = 2113 then
       thingyousubtract = 12 : gosub memorysaverotate 
       endif
    
    memorysaverotate:
    val = 1<<(val-thingyousubtract)
    goto Show_current_sel_2
    Last edited by Art; - 11th September 2015 at 21:29.

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