Math operations & Syntax?


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kevj View Post
    I'm asking if I create a 16 bit variable, and populate it by saying "myVar = TRM1", will it automatically plug the TMR1H and TMR1L values together and stick them into myVar?
    And if I add 100 to that value, then populate the timer registers again by plugging this variable back in like this "TMR1 = myVar", will the binary values of the 2 8-bit registers get split correctly and put back into TMR1H and TMR1L as appropriate?
    Ok, I got you...
    It may depend on the PIC, not sure, the datasheets will tell.
    But...
    I'm looking at the 18F4620 datasheet, there's a section in there under Timer 1 that talks about 8 bit vs 16 bit Timer 1 writes.
    Basically, you can't go TMR1 = var, you do actually have to use 2 8bit writes. You can't directly access TMR1H, it gets buffered in the 16 bit R/W mode. (section 12.2 of the 18F4620 datasheet)

  2. #2
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Ok, I got you...
    It may depend on the PIC, not sure, the datasheets will tell.
    But...
    I'm looking at the 18F4620 datasheet, there's a section in there under Timer 1 that talks about 8 bit vs 16 bit Timer 1 writes.
    Basically, you can't go TMR1 = var, you do actually have to use 2 8bit writes. You can't directly access TMR1H, it gets buffered in the 16 bit R/W mode. (section 12.2 of the 18F4620 datasheet)
    Okay perfect - that is exactly what I'm asking, and now the follow up...

    What is the exact syntax to split off the high and low bits? That really is my confusion at this point. I want to do something like this, but I'm not sure the syntax...

    Code:
    myHolder VAR WORD
    
    ''' stop timer, which is now holding the result I want to measure
    
    myHolder (the low byte) = TMR1L
    myHolder (the high byte) = TMR1H
    
    myHolder = myHolder - 200
    
    ''' now I'll goto another sub where I'm using the timeout as a trial
    
    TMR1L = (the low byte of myHolder)
    TMR1H = (the high byte of myHolder)
    
    '

    So I guess I'm just asking for the syntax of how to reference a high bit or a low bit in or out of a 16-bit variable, and also to clairify that once I have the value in "myHolder", I can do all the simple add/subtract math I want to it just like any normal variable as long as the values remain between 0 and 64,000andwhatever.

    Right? :-)

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kevj View Post
    What is the exact syntax to split off the high and low bits? That really is my confusion at this point. I want to do something like this, but I'm not sure the syntax...

    Code:
    myHolder VAR WORD
    ''' stop timer, which is now holding the result I want to measure
    myHolder (the low byte) = TMR1L
    myHolder (the high byte) = TMR1H
    myHolder = myHolder - 200
    ''' now I'll goto another sub where I'm using the timeout as a trial
    TMR1L = (the low byte of myHolder)
    TMR1H = (the high byte of myHolder)
    So I guess I'm just asking for the syntax of how to reference a high bit or a low bit in or out of a 16-bit variable, and also to clairify that once I have the value in "myHolder", I can do all the simple add/subtract math I want to it just like any normal variable as long as the values remain between 0 and 64,000andwhatever.
    Right? :-)
    It's all in the manual under the "Variables" section, highbyte, lowbyte, bitxxx, aliasing, whatever...

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    These two threads should answer your question & then some. The 2nd using the EXT
    modifier is really nifty.

    http://www.picbasic.co.uk/forum/showthread.php?t=544

    http://www.picbasic.co.uk/forum/showthread.php?t=3891
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Thanks guys! Much appreciated!

Similar Threads

  1. Resolution integer math assistance?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th January 2010, 04:01
  2. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 11:22
  3. instruction cycles for math operations
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th July 2007, 12:03
  4. Math Operations on pbp
    By Jannia04 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th May 2007, 16:33
  5. PIC18Fxx math 24 & 32 bit
    By ronsimpson in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd December 2006, 13:52

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