HELP WITH SOME Nbit MATH


Closed Thread
Results 1 to 11 of 11

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: HELP WITH SOME Nbit MATH

    ok ill give that a go , the array that have been defined were existing sdc_buffer of 255bytes that i use for data transfer to spi chips so all this is about building the buffers ready to write the records for this section


    i have the time in sec / laps count = lap time avg (result + remander) in sec
    this then needs to be placed in to the record as days/hour/mins/sec/100th
    here is the fisrt attempt in nbit math for this

    Code:
     '------- NbIT Math 32bit length  get lap average time value -------------
        glc_s = SDC_buffer[24]                             ' get the current lap count into tmp var ( Nmath wont allow indexed var) 
       
        @ MOVE?BP _glc_s,_Tmp32bit_1                        ' copy lap value into tmp1 
        @ MATH_DIV _Tmp32bit_3,_Tmp32bit_1,_Result_32bit    ' Tmp32bit_3 hold last lap time  div total laps  = lap time in secs , REg_Z holds remainder sec 
        @ MOVE?PB  REG_Z, _glc_s                            ' copy sec remainder to tmp pbp var ( non indexed)
          SDC_buffer[44] = glc_s                            ' copy remainder to AVG lap time 1/100th buffer 
        
        @ MOVE?CP 60,_Tmp32bit_1                            ' copy 60 value into tmp1 for minutes div 
        @ MATH_DIV _Result_32bit,_Tmp32bit_1,_Tmp32bit_3    ' Result_32bit ( laps in sec div 60 = minutes  Reg_Z holds remainder sec           
        @ MOVE?PB  REG_Z, _glc_s                            ' copy min remainder to tmp pbp var ( non indexed)
          SDC_buffer[45] = glc_s                            ' copy min remainder to AVG lap time secs buffer 
       
        @ MATH_DIV _Tmp32bit_3,_Tmp32bit_1,_Result_32bit    ' _Tmp32bit_3 (laps in mins div 60 = hours ,Reg_Z holds remainder mins 
        @ MOVE?PB  REG_Z, _glc_s                            ' copy hour remainder to tmp pbp var ( non indexed)
          SDC_buffer[46] = glc_s                            ' copy hour remainder to AVG lap time mins buffer 
     
        @ MOVE?CP 24,_Tmp32bit_1                            ' copy 24 value into tmp1 for days div 
        @ MATH_DIV _Result_32bit,_Tmp32bit_1,_Tmp32bit_3    ' Result_32bit ( laps in hours  div 24 = days  Reg_Z holds remainder hours     
        @ MOVE?PB  REG_Z, _glc_s                            ' copy days remainder to tmp pbp var ( non indexed)
          SDC_buffer[47] = glc_s                            ' copy days remainder to AVG lap time hours buffer 
        
        @ MOVE?PW _Tmp32bit_3,_glc_s                        ' copy days result to tmp pbp var ( byte size max value = 7)  
          glc_s = glc_s << 5                                ' move day value to bit7-5 from bit2-0 
          SDC_buffer[47] = glc_s + SDC_buffer[47]           ' assemble days + hours to  AVG lap time day/hours buffer

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: HELP WITH SOME Nbit MATH

    I'm not sure, but something might be wrong here...
    Looking at this 2 lines
    glc_s = SDC_buffer[24] ' get the current lap count into tmp var ( Nmath wont allow indexed var)
    @ MOVE?BP _glc_s,_Tmp32bit_1 ' copy lap value into tmp1
    And you sad that you have array of bytes.
    So glc_s is byte, and max time that can hold is 255 sec.
    And then I lost it...
    Why you bother with N bit math if your max result is only byte wide? There is more than 255sec in day, so day will be 0 always, even hour...
    You are doing something fundamentally wrong here.

Similar Threads

  1. some help with math
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 64
    Last Post: - 16th October 2015, 02:03
  2. Help with the math
    By Ramius in forum FAQ - Frequently Asked Questions
    Replies: 3
    Last Post: - 5th September 2014, 07:15
  3. Math help please...
    By Ioannis in forum General
    Replies: 2
    Last Post: - 20th June 2008, 10:18
  4. 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
  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