Operator problem


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    DIV32 requires that PBP's system variables be loaded with a 32-bit value from a prior 16x16 bit multiplication.
    The multiplication has to use at least 1 WORD variable.

    But when you specify a multiplication of 2 constants ... the multiplication is done a compile-time as part of the optimization (constant folding).
    The system variables never get loaded, because the multiplication was not done at run-time.

    The mid-word multiplier is never done at compile-time, even if it has two constants.
    It's always done at run-time, and the system variables do get loaded.

    And ... TMR1 is declared as a WORD variable in the .pbpinc files.
    It's OK to read the entire Timer1 value as long as two conditions are met ... the Timer must be stopped, and RD16 must NOT be set.
    DT

  2. #2
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Quote Originally Posted by Darrel Taylor View Post
    DIV32 requires that PBP's system variables be loaded with a 32-bit value from a prior 16x16 bit multiplication.
    The multiplication has to use at least 1 WORD variable.

    But when you specify a multiplication of 2 constants ... the multiplication is done a compile-time as part of the optimization (constant folding).
    The system variables never get loaded, because the multiplication was not done at run-time.

    The mid-word multiplier is never done at compile-time, even if it has two constants.
    It's always done at run-time, and the system variables do get loaded.

    And ... TMR1 is declared as a WORD variable in the .pbpinc files.
    It's OK to read the entire Timer1 value as long as two conditions are met ... the Timer must be stopped, and RD16 must NOT be set.
    You're amazing Darrel ! .. That's such a nice explanation and mind-flashing answer .. Just outta curiosity .. Where do you get such knowledges from ? I mean we can't even get these infos from the compilers reference manual ...

    Thank you guys for your prompt answers !

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Thanks gunayburak,

    Everything about PBP is completely transparent.
    The libraries (*.lib), macro files (*.mac), the generated assembly language (*.asm) and resulting Listing files (*.LST) are all plain text files that can be viewed with NotePad or similar text editors.

    With only 15-years or so of studying those files ... and attempting to solve hundreds of other peoples problems (cause I can't make my own), and you too will know everything there is to know about PicBasic Pro.

    Except for about a million things.
    DT

  4. #4
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Yet there is one more problem digging my mind ..
    Was I not supposed to get 11 according to the calculation I did at my first post ?
    How come I get 3026 ( which is the correct mathematical result and the result I expect to get with only * operand ??

    Thanks once again ..

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Assuming the operations are being done at run-time ...
    Internally, both * and */ do the same 16x16 bit multiplication, and the system variables contain the same 32-bit "product".

    For the mid-word multiplier, the middle two bytes are then copied to the result variable, in this case rpm.
    That result is then discarded and rpm is assigned the value from the DIV32, which used the 32-bit value in the system variables, not the mid-word value.
    Code:
    rpm=6000*/10000  ; <-- This result in rpm is discarded
    rpm=div32 time
    The same thing applies to the High-Word multiplier **.
    DT

  6. #6
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Thanks to both of you darrel and henrik ...

    By the night I will be done with my pid rpm controller unit ...
    Thanks to henrik's code which helped me so much with my projects ..
    I modified his code to suit my rpm controller

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Operator problem

    Hi,
    Excellent!
    All credits goes to Darrel though, I pretty much missed the ball alltogether on this one. Which is OK because I learned a thing or two from it, th e
    I'm glad to hear the PID routine gets used and that it works. Out of curiosity, modifications were needed?

    /Henrik.

Similar Threads

  1. Can someone please explain the operator */
    By triton99 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th November 2011, 14:16
  2. // Division Operator
    By Dick Ivers in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th September 2011, 14:27
  3. Exponential Operator
    By andrewroz in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 31st October 2007, 08:00
  4. '*/' operator
    By jblackann in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th January 2007, 20:00
  5. math operator LOG
    By Eyal in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd July 2004, 23:45

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